Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disableAction to the rest of item in MoreFeaturePage #47533

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading