@@ -8,11 +8,11 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
8
8
import * as Expensicons from '@components/Icon/Expensicons' ;
9
9
import * as Illustrations from '@components/Icon/Illustrations' ;
10
10
import ScreenWrapper from '@components/ScreenWrapper' ;
11
+ import ListItemRightCaretWithLabel from '@components/SelectionList/ListItemRightCaretWithLabel' ;
11
12
import TableListItem from '@components/SelectionList/TableListItem' ;
12
13
import type { ListItem } from '@components/SelectionList/types' ;
13
14
import SelectionListWithModal from '@components/SelectionListWithModal' ;
14
15
import CustomListHeader from '@components/SelectionListWithModal/CustomListHeader' ;
15
- import Switch from '@components/Switch' ;
16
16
import Text from '@components/Text' ;
17
17
import useLocalize from '@hooks/useLocalize' ;
18
18
import useMobileSelectionMode from '@hooks/useMobileSelectionMode' ;
@@ -74,11 +74,11 @@ function PolicyDistanceRatesPage({
74
74
const dismissError = useCallback (
75
75
( item : RateForList ) => {
76
76
if ( customUnitRates [ item . value ] . errors ) {
77
- DistanceRate . clearDeleteDistanceRateError ( policyID , customUnit ?. customUnitID ?? CONST . EMPTY_STRING , item . value ) ;
77
+ DistanceRate . clearDeleteDistanceRateError ( policyID , customUnit ?. customUnitID ?? '' , item . value ) ;
78
78
return ;
79
79
}
80
80
81
- DistanceRate . clearCreateDistanceRateItemAndError ( policyID , customUnit ?. customUnitID ?? CONST . EMPTY_STRING , item . value ) ;
81
+ DistanceRate . clearCreateDistanceRateItemAndError ( policyID , customUnit ?. customUnitID ?? '' , item . value ) ;
82
82
} ,
83
83
[ customUnit ?. customUnitID , customUnitRates , policyID ] ,
84
84
) ;
@@ -98,36 +98,16 @@ function PolicyDistanceRatesPage({
98
98
setSelectedDistanceRates ( [ ] ) ;
99
99
} , [ isFocused ] ) ;
100
100
101
- const updateDistanceRateEnabled = useCallback (
102
- ( value : boolean , rateID : string ) => {
103
- if ( ! customUnit ) {
104
- return ;
105
- }
106
- const rate = customUnit ?. rates ?. [ rateID ] ;
107
- // Rates can be disabled or deleted as long as in the remaining rates there is always at least one enabled rate and there are no pending delete action
108
- const canDisableOrDeleteRate = Object . values ( customUnit ?. rates ?? { } ) . some (
109
- ( distanceRate : Rate ) => distanceRate ?. enabled && rateID !== distanceRate ?. customUnitRateID && distanceRate ?. pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ,
110
- ) ;
111
-
112
- if ( ! rate ?. enabled || canDisableOrDeleteRate ) {
113
- DistanceRate . setPolicyDistanceRatesEnabled ( policyID , customUnit , [ { ...rate , enabled : value } ] ) ;
114
- } else {
115
- setIsWarningModalVisible ( true ) ;
116
- }
117
- } ,
118
- [ customUnit , policyID ] ,
119
- ) ;
120
-
121
101
const distanceRatesList = useMemo < RateForList [ ] > (
122
102
( ) =>
123
103
Object . values ( customUnitRates )
124
104
. sort ( ( rateA , rateB ) => ( rateA ?. rate ?? 0 ) - ( rateB ?. rate ?? 0 ) )
125
105
. map ( ( value ) => ( {
126
- value : value . customUnitRateID ?? CONST . EMPTY_STRING ,
106
+ value : value . customUnitRateID ?? '' ,
127
107
text : `${ CurrencyUtils . convertAmountToDisplayString ( value . rate , value . currency ?? CONST . CURRENCY . USD ) } / ${ translate (
128
108
`common.${ customUnit ?. attributes ?. unit ?? CONST . CUSTOM_UNITS . DISTANCE_UNIT_MILES } ` ,
129
109
) } `,
130
- keyForList : value . customUnitRateID ?? CONST . EMPTY_STRING ,
110
+ keyForList : value . customUnitRateID ?? '' ,
131
111
isSelected : selectedDistanceRates . find ( ( rate ) => rate . customUnitRateID === value . customUnitRateID ) !== undefined && canSelectMultiple ,
132
112
isDisabled : value . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ,
133
113
pendingAction :
@@ -139,16 +119,9 @@ function PolicyDistanceRatesPage({
139
119
value . pendingFields ?. taxClaimablePercentage ??
140
120
( policy ?. pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . ADD ? policy ?. pendingAction : undefined ) ,
141
121
errors : value . errors ?? undefined ,
142
- rightElement : (
143
- < Switch
144
- isOn = { ! ! value ?. enabled }
145
- accessibilityLabel = { translate ( 'workspace.distanceRates.trackTax' ) }
146
- onToggle = { ( newValue : boolean ) => updateDistanceRateEnabled ( newValue , value . customUnitRateID ) }
147
- disabled = { value . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE }
148
- />
149
- ) ,
122
+ rightElement : < ListItemRightCaretWithLabel labelText = { value . enabled ? translate ( 'workspace.common.enabled' ) : translate ( 'workspace.common.disabled' ) } /> ,
150
123
} ) ) ,
151
- [ customUnitRates , translate , customUnit , selectedDistanceRates , canSelectMultiple , policy ?. pendingAction , updateDistanceRateEnabled ] ,
124
+ [ customUnit ?. attributes ?. unit , customUnitRates , selectedDistanceRates , translate , policy ?. pendingAction , canSelectMultiple ] ,
152
125
) ;
153
126
154
127
const addRate = ( ) => {
@@ -197,7 +170,7 @@ function PolicyDistanceRatesPage({
197
170
DistanceRate . deletePolicyDistanceRates (
198
171
policyID ,
199
172
customUnit ,
200
- selectedDistanceRates . map ( ( rate ) => rate . customUnitRateID ?? CONST . EMPTY_STRING ) ,
173
+ selectedDistanceRates . map ( ( rate ) => rate . customUnitRateID ?? '' ) ,
201
174
) ;
202
175
setSelectedDistanceRates ( [ ] ) ;
203
176
setIsDeleteModalVisible ( false ) ;
0 commit comments