Skip to content

Commit

Permalink
Merge pull request #47533 from hungvu193/fix-toogle-disabled-onClick
Browse files Browse the repository at this point in the history
Add disableAction to the rest of item in MoreFeaturePage
  • Loading branch information
marcaaron authored Aug 26, 2024
2 parents 31758f1 + 988bda3 commit 8c1b8e0
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
const [isDisableExpensifyCardWarningModalOpen, setIsDisableExpensifyCardWarningModalOpen] = useState(false);
const [isDisableCompanyCardsWarningModalOpen, setIsDisableCompanyCardsWarningModalOpen] = useState(false);

const onDisabledOrganizeSwitchPress = useCallback(() => {
if (!hasAccountingConnection) {
return;
}
setIsOrganizeWarningModalOpen(true);
}, [hasAccountingConnection]);

const spendItems: Item[] = [
{
icon: Illustrations.Car,
Expand Down Expand Up @@ -199,15 +206,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
subtitleTranslationKey: 'workspace.moreFeatures.categories.subtitle',
isActive: policy?.areCategoriesEnabled ?? false,
disabled: hasAccountingConnection,
disabledAction: onDisabledOrganizeSwitchPress,
pendingAction: policy?.pendingFields?.areCategoriesEnabled,
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
if (hasAccountingConnection) {
setIsOrganizeWarningModalOpen(true);
return;
}
Category.enablePolicyCategories(policyID, isEnabled);
},
},
Expand All @@ -218,14 +222,11 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
isActive: policy?.areTagsEnabled ?? false,
disabled: hasAccountingConnection,
pendingAction: policy?.pendingFields?.areTagsEnabled,
disabledAction: onDisabledOrganizeSwitchPress,
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
if (hasAccountingConnection) {
setIsOrganizeWarningModalOpen(true);
return;
}
Tag.enablePolicyTags(policyID, isEnabled);
},
},
Expand All @@ -236,14 +237,11 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
isActive: (policy?.tax?.trackingEnabled ?? false) || isSyncTaxEnabled,
disabled: hasAccountingConnection,
pendingAction: policy?.pendingFields?.tax,
disabledAction: onDisabledOrganizeSwitchPress,
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
if (hasAccountingConnection) {
setIsOrganizeWarningModalOpen(true);
return;
}
Policy.enablePolicyTaxes(policyID, isEnabled);
},
},
Expand All @@ -254,14 +252,11 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
isActive: policy?.areReportFieldsEnabled ?? false,
disabled: hasAccountingConnection,
pendingAction: policy?.pendingFields?.areReportFieldsEnabled,
disabledAction: onDisabledOrganizeSwitchPress,
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
if (hasAccountingConnection) {
setIsOrganizeWarningModalOpen(true);
return;
}
if (isEnabled) {
if (!isControlPolicy(policy)) {
Navigation.navigate(
Expand All @@ -285,12 +280,14 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
subtitleTranslationKey: 'workspace.moreFeatures.connections.subtitle',
isActive: isAccountingEnabled,
pendingAction: policy?.pendingFields?.areConnectionsEnabled,
action: (isEnabled: boolean) => {
if (!policyID) {
disabledAction: () => {
if (!hasAccountingConnection) {
return;
}
if (hasAccountingConnection) {
setIsIntegrateWarningModalOpen(true);
setIsIntegrateWarningModalOpen(true);
},
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
Policy.enablePolicyConnections(policyID, isEnabled);
Expand Down

0 comments on commit 8c1b8e0

Please sign in to comment.