Skip to content

Commit

Permalink
Merge pull request #39895 from Expensify/hayata-prevent-toggle-when-a…
Browse files Browse the repository at this point in the history
…ccounting-is-connected

[NO QA] Disable the switch when there is accounting connection
  • Loading branch information
mountiny authored Apr 15, 2024
2 parents ae93028 + 7fc0015 commit 368969b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Item = {
titleTranslationKey: TranslationPaths;
subtitleTranslationKey: TranslationPaths;
isActive: boolean;
disabled?: boolean;
action: (isEnabled: boolean) => void;
pendingAction: PendingAction | undefined;
};
Expand All @@ -46,6 +47,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();
const {canUseAccountingIntegrations} = usePermissions();
const hasAccountingConnection = !!policy?.areConnectionsEnabled && !!policy?.connections;
const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline.config.syncTax;

const spendItems: Item[] = [
{
Expand Down Expand Up @@ -76,6 +79,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
titleTranslationKey: 'workspace.moreFeatures.categories.title',
subtitleTranslationKey: 'workspace.moreFeatures.categories.subtitle',
isActive: policy?.areCategoriesEnabled ?? false,
disabled: hasAccountingConnection,
pendingAction: policy?.pendingFields?.areCategoriesEnabled,
action: (isEnabled: boolean) => {
Policy.enablePolicyCategories(policy?.id ?? '', isEnabled);
Expand All @@ -86,6 +90,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
titleTranslationKey: 'workspace.moreFeatures.tags.title',
subtitleTranslationKey: 'workspace.moreFeatures.tags.subtitle',
isActive: policy?.areTagsEnabled ?? false,
disabled: hasAccountingConnection,
pendingAction: policy?.pendingFields?.areTagsEnabled,
action: (isEnabled: boolean) => {
Policy.enablePolicyTags(policy?.id ?? '', isEnabled);
Expand All @@ -95,7 +100,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
icon: Illustrations.Coins,
titleTranslationKey: 'workspace.moreFeatures.taxes.title',
subtitleTranslationKey: 'workspace.moreFeatures.taxes.subtitle',
isActive: policy?.tax?.trackingEnabled ?? false,
isActive: (policy?.tax?.trackingEnabled ?? false) || isSyncTaxEnabled,
disabled: isSyncTaxEnabled,
pendingAction: policy?.pendingFields?.tax,
action: (isEnabled: boolean) => {
Policy.enablePolicyTaxes(policy?.id ?? '', isEnabled);
Expand Down Expand Up @@ -150,6 +156,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
isActive={item.isActive}
pendingAction={item.pendingAction}
onToggle={item.action}
disabled={item.disabled}
/>
</View>
),
Expand Down

0 comments on commit 368969b

Please sign in to comment.