11import { domainSecurityGroupSettingErrorsSelector , domainSecurityGroupSettingPendingActionSelector , selectGroupByID } from '@selectors/Domain' ;
2- import React , { useState } from 'react' ;
2+ import React from 'react' ;
33import { View } from 'react-native' ;
4- import ConfirmModal from '@components/ConfirmModal ' ;
4+ import useConfirmModal from '@hooks/useConfirmModal ' ;
55import useLocalize from '@hooks/useLocalize' ;
66import useOnyx from '@hooks/useOnyx' ;
77import useThemeStyles from '@hooks/useThemeStyles' ;
@@ -20,7 +20,7 @@ type ExpensifyCardPreferredWorkspaceToggleProps = {
2020function ExpensifyCardPreferredWorkspaceToggle ( { domainAccountID, groupID} : ExpensifyCardPreferredWorkspaceToggleProps ) {
2121 const styles = useThemeStyles ( ) ;
2222 const { translate} = useLocalize ( ) ;
23- const [ isDisabledModalVisible , setIsDisabledModalVisible ] = useState ( false ) ;
23+ const { showConfirmModal } = useConfirmModal ( ) ;
2424
2525 const [ group ] = useOnyx ( `${ ONYXKEYS . COLLECTION . DOMAIN } ${ domainAccountID } ` , {
2626 selector : selectGroupByID ( groupID ) ,
@@ -43,38 +43,34 @@ function ExpensifyCardPreferredWorkspaceToggle({domainAccountID, groupID}: Expen
4343 const isDisabled = ( ! isPreferredPolicyEnabled || ! isDomainUsingExpensifyCard ) && ! isActive ;
4444
4545 return (
46- < >
47- < View style = { styles . mv3 } >
48- < ToggleSettingOptionRow
49- title = { translate ( 'domain.groups.expensifyCardPreferredWorkspace' ) }
50- subtitle = { translate ( 'domain.groups.expensifyCardPreferredWorkspaceDescription' ) }
51- switchAccessibilityLabel = { translate ( 'domain.groups.expensifyCardPreferredWorkspace' ) }
52- shouldPlaceSubtitleBelowSwitch
53- disabled = { isDisabled }
54- disabledAction = { ( ) => setIsDisabledModalVisible ( true ) }
55- isActive = { isActive }
56- onToggle = { ( enabled ) => {
57- if ( ! group ) {
58- return ;
59- }
60- updateDomainSecurityGroup ( domainAccountID , groupID , group , { overridePreferredPolicyWithCardPolicy : enabled } , 'overridePreferredPolicyWithCardPolicy' ) ;
61- } }
62- wrapperStyle = { styles . ph5 }
63- pendingAction = { overridePreferredPolicyWithCardPolicyPendingAction }
64- errors = { overridePreferredPolicyWithCardPolicyErrors }
65- onCloseError = { ( ) => clearDomainSecurityGroupSettingError ( domainAccountID , groupID , 'overridePreferredPolicyWithCardPolicyErrors' ) }
66- />
67- </ View >
68- < ConfirmModal
69- onConfirm = { ( ) => setIsDisabledModalVisible ( false ) }
70- onCancel = { ( ) => setIsDisabledModalVisible ( false ) }
71- isVisible = { isDisabledModalVisible }
72- title = { translate ( 'workspace.distanceRates.oopsNotSoFast' ) }
73- prompt = { translate ( 'domain.groups.expensifyCardPreferredWorkspaceDisabledMessage' ) }
74- confirmText = { translate ( 'common.buttonConfirm' ) }
75- shouldShowCancelButton = { false }
46+ < View style = { styles . mv3 } >
47+ < ToggleSettingOptionRow
48+ title = { translate ( 'domain.groups.expensifyCardPreferredWorkspace' ) }
49+ subtitle = { translate ( 'domain.groups.expensifyCardPreferredWorkspaceDescription' ) }
50+ switchAccessibilityLabel = { translate ( 'domain.groups.expensifyCardPreferredWorkspace' ) }
51+ shouldPlaceSubtitleBelowSwitch
52+ disabled = { isDisabled }
53+ disabledAction = { ( ) => {
54+ showConfirmModal ( {
55+ title : translate ( 'workspace.distanceRates.oopsNotSoFast' ) ,
56+ prompt : translate ( 'domain.groups.expensifyCardPreferredWorkspaceDisabledMessage' ) ,
57+ confirmText : translate ( 'common.buttonConfirm' ) ,
58+ shouldShowCancelButton : false ,
59+ } ) ;
60+ } }
61+ isActive = { isActive }
62+ onToggle = { ( enabled ) => {
63+ if ( ! group ) {
64+ return ;
65+ }
66+ updateDomainSecurityGroup ( domainAccountID , groupID , group , { overridePreferredPolicyWithCardPolicy : enabled } , 'overridePreferredPolicyWithCardPolicy' ) ;
67+ } }
68+ wrapperStyle = { styles . ph5 }
69+ pendingAction = { overridePreferredPolicyWithCardPolicyPendingAction }
70+ errors = { overridePreferredPolicyWithCardPolicyErrors }
71+ onCloseError = { ( ) => clearDomainSecurityGroupSettingError ( domainAccountID , groupID , 'overridePreferredPolicyWithCardPolicyErrors' ) }
7672 />
77- </ >
73+ </ View >
7874 ) ;
7975}
8076
0 commit comments