Skip to content

Commit ba5c201

Browse files
authored
Merge pull request #42919 from mananjadhav/workspace-more-features-modal
[Wave Collect] [Xero] Remove text jitter for More Features modal
2 parents bc3009a + 32110d9 commit ba5c201

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

src/pages/workspace/WorkspaceMoreFeaturesPage.tsx

+22-46
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscree
3131
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';
3232
import ToggleSettingOptionRow from './workflows/ToggleSettingsOptionRow';
3333

34-
type ItemType = 'organize' | 'integrate';
35-
type ConnectionWarningModalState = {
36-
isOpen: boolean;
37-
itemType?: ItemType;
38-
};
39-
4034
type WorkspaceMoreFeaturesPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.MORE_FEATURES>;
4135

4236
type Item = {
@@ -66,7 +60,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
6660
const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config.syncTax || !!policy?.connections?.xero?.config.importTaxRates;
6761
const policyID = policy?.id ?? '';
6862

69-
const [connectionWarningModalState, setConnectionWarningModalState] = useState<ConnectionWarningModalState>({isOpen: false});
63+
const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState<boolean>(false);
64+
const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState<boolean>(false);
7065

7166
const spendItems: Item[] = [
7267
{
@@ -101,10 +96,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
10196
pendingAction: policy?.pendingFields?.areCategoriesEnabled,
10297
action: (isEnabled: boolean) => {
10398
if (hasAccountingConnection) {
104-
setConnectionWarningModalState({
105-
isOpen: true,
106-
itemType: 'organize',
107-
});
99+
setIsOrganizeWarningModalOpen(true);
108100
return;
109101
}
110102
Category.enablePolicyCategories(policy?.id ?? '', isEnabled);
@@ -119,10 +111,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
119111
pendingAction: policy?.pendingFields?.areTagsEnabled,
120112
action: (isEnabled: boolean) => {
121113
if (hasAccountingConnection) {
122-
setConnectionWarningModalState({
123-
isOpen: true,
124-
itemType: 'organize',
125-
});
114+
setIsOrganizeWarningModalOpen(true);
126115
return;
127116
}
128117
Tag.enablePolicyTags(policy?.id ?? '', isEnabled);
@@ -137,10 +126,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
137126
pendingAction: policy?.pendingFields?.tax,
138127
action: (isEnabled: boolean) => {
139128
if (hasAccountingConnection) {
140-
setConnectionWarningModalState({
141-
isOpen: true,
142-
itemType: 'organize',
143-
});
129+
setIsOrganizeWarningModalOpen(true);
144130
return;
145131
}
146132
Policy.enablePolicyTaxes(policy?.id ?? '', isEnabled);
@@ -157,10 +143,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
157143
pendingAction: policy?.pendingFields?.areConnectionsEnabled,
158144
action: (isEnabled: boolean) => {
159145
if (hasAccountingConnection) {
160-
setConnectionWarningModalState({
161-
isOpen: true,
162-
itemType: 'integrate',
163-
});
146+
setIsIntegrateWarningModalOpen(true);
164147
return;
165148
}
166149
Policy.enablePolicyConnections(policy?.id ?? '', isEnabled);
@@ -247,17 +230,6 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
247230
}, [fetchFeatures]),
248231
);
249232

250-
const getConnectionWarningPrompt = useCallback(() => {
251-
switch (connectionWarningModalState.itemType) {
252-
case 'organize':
253-
return translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledText');
254-
case 'integrate':
255-
return translate('workspace.moreFeatures.connectionsWarningModal.disconnectText');
256-
default:
257-
return undefined;
258-
}
259-
}, [connectionWarningModalState.itemType, translate]);
260-
261233
return (
262234
<AccessOrNotFoundWrapper
263235
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
@@ -280,20 +252,24 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
280252
<ConfirmModal
281253
title={translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledTitle')}
282254
onConfirm={() => {
283-
setConnectionWarningModalState({
284-
isOpen: false,
285-
itemType: undefined,
286-
});
255+
setIsOrganizeWarningModalOpen(false);
256+
Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID));
257+
}}
258+
onCancel={() => setIsOrganizeWarningModalOpen(false)}
259+
isVisible={isOrganizeWarningModalOpen}
260+
prompt={translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledText')}
261+
confirmText={translate('workspace.moreFeatures.connectionsWarningModal.manageSettings')}
262+
cancelText={translate('common.cancel')}
263+
/>
264+
<ConfirmModal
265+
title={translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledTitle')}
266+
onConfirm={() => {
267+
setIsIntegrateWarningModalOpen(false);
287268
Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID));
288269
}}
289-
onCancel={() =>
290-
setConnectionWarningModalState({
291-
isOpen: false,
292-
itemType: undefined,
293-
})
294-
}
295-
isVisible={connectionWarningModalState.isOpen}
296-
prompt={getConnectionWarningPrompt()}
270+
onCancel={() => setIsIntegrateWarningModalOpen(false)}
271+
isVisible={isIntegrateWarningModalOpen}
272+
prompt={translate('workspace.moreFeatures.connectionsWarningModal.disconnectText')}
297273
confirmText={translate('workspace.moreFeatures.connectionsWarningModal.manageSettings')}
298274
cancelText={translate('common.cancel')}
299275
/>

0 commit comments

Comments
 (0)