diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 760155861f2a..de9a3e15dd56 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -57,29 +57,6 @@ type SectionObject = { items: Item[]; }; -// TODO: remove when Onyx data is available -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const mockedCardsList = { - test1: { - cardholder: {accountID: 1, lastName: 'Smith', firstName: 'Bob', displayName: 'Bob Smith', avatar: ''}, - name: 'Test 1', - limit: 1000, - lastFourPAN: '1234', - }, - test2: { - cardholder: {accountID: 2, lastName: 'Miller', firstName: 'Alex', displayName: 'Alex Miller', avatar: ''}, - name: 'Test 2', - limit: 2000, - lastFourPAN: '1234', - }, - test3: { - cardholder: {accountID: 3, lastName: 'Brown', firstName: 'Kevin', displayName: 'Kevin Brown', avatar: ''}, - name: 'Test 3', - limit: 3000, - lastFourPAN: '1234', - }, -}; - function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPageProps) { const styles = useThemeStyles(); const {shouldUseNarrowLayout} = useResponsiveLayout(); @@ -91,13 +68,10 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro !!policy?.connections?.quickbooksOnline?.config?.syncTax || !!policy?.connections?.xero?.config?.importTaxRates || !!policy?.connections?.netsuite?.options?.config?.syncOptions?.syncTax; - const policyID = policy?.id ?? ''; + const policyID = policy?.id; // @ts-expect-error a new props will be added during feed api implementation const workspaceAccountID = (policy?.workspaceAccountID as string) ?? ''; const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}${CONST.EXPENSIFY_CARD.BANK}`); - // Uncomment this line for testing disabled toggle feature - for c+ - // const [cardsList = mockedCardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); - const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState(false); const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState(false); const [isReportFieldsWarningModalOpen, setIsReportFieldsWarningModalOpen] = useState(false); @@ -111,7 +85,10 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro isActive: policy?.areDistanceRatesEnabled ?? false, pendingAction: policy?.pendingFields?.areDistanceRatesEnabled, action: (isEnabled: boolean) => { - DistanceRate.enablePolicyDistanceRates(policy?.id ?? '-1', isEnabled); + if (!policyID) { + return; + } + DistanceRate.enablePolicyDistanceRates(policyID, isEnabled); }, }, { @@ -121,7 +98,10 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro isActive: policy?.areWorkflowsEnabled ?? false, pendingAction: policy?.pendingFields?.areWorkflowsEnabled, action: (isEnabled: boolean) => { - Policy.enablePolicyWorkflows(policy?.id ?? '-1', isEnabled); + if (!policyID) { + return; + } + Policy.enablePolicyWorkflows(policyID, isEnabled); }, }, ]; @@ -136,7 +116,10 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro pendingAction: policy?.pendingFields?.areExpensifyCardsEnabled, disabled: !isEmptyObject(cardsList), action: (isEnabled: boolean) => { - Policy.enableExpensifyCard(policy?.id ?? '-1', isEnabled); + if (!policyID) { + return; + } + Policy.enableExpensifyCard(policyID, isEnabled); }, disabledAction: () => { setIsDisableExpensifyCardWarningModalOpen(true); @@ -152,7 +135,10 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro isActive: policy?.areInvoicesEnabled ?? false, pendingAction: policy?.pendingFields?.areInvoicesEnabled, action: (isEnabled: boolean) => { - Policy.enablePolicyInvoicing(policy?.id ?? '-1', isEnabled); + if (!policyID) { + return; + } + Policy.enablePolicyInvoicing(policyID, isEnabled); }, }, ]; @@ -166,11 +152,14 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro disabled: hasAccountingConnection, pendingAction: policy?.pendingFields?.areCategoriesEnabled, action: (isEnabled: boolean) => { + if (!policyID) { + return; + } if (hasAccountingConnection) { setIsOrganizeWarningModalOpen(true); return; } - Category.enablePolicyCategories(policy?.id ?? '-1', isEnabled); + Category.enablePolicyCategories(policyID, isEnabled); }, }, { @@ -181,11 +170,14 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro disabled: hasAccountingConnection, pendingAction: policy?.pendingFields?.areTagsEnabled, action: (isEnabled: boolean) => { + if (!policyID) { + return; + } if (hasAccountingConnection) { setIsOrganizeWarningModalOpen(true); return; } - Tag.enablePolicyTags(policy?.id ?? '-1', isEnabled); + Tag.enablePolicyTags(policyID, isEnabled); }, }, { @@ -196,11 +188,14 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro disabled: hasAccountingConnection, pendingAction: policy?.pendingFields?.tax, action: (isEnabled: boolean) => { + if (!policyID) { + return; + } if (hasAccountingConnection) { setIsOrganizeWarningModalOpen(true); return; } - Policy.enablePolicyTaxes(policy?.id ?? '-1', isEnabled); + Policy.enablePolicyTaxes(policyID, isEnabled); }, }, ]; @@ -214,6 +209,9 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro disabled: hasAccountingConnection, pendingAction: policy?.pendingFields?.areReportFieldsEnabled, action: (isEnabled: boolean) => { + if (!policyID) { + return; + } if (hasAccountingConnection) { setIsOrganizeWarningModalOpen(true); return; @@ -242,15 +240,23 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro isActive: isAccountingEnabled, pendingAction: policy?.pendingFields?.areConnectionsEnabled, action: (isEnabled: boolean) => { + if (!policyID) { + return; + } if (hasAccountingConnection) { setIsIntegrateWarningModalOpen(true); return; } - Policy.enablePolicyConnections(policy?.id ?? '-1', isEnabled); + Policy.enablePolicyConnections(policyID, isEnabled); }, disabled: hasAccountingConnection, errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED), - onCloseError: () => Policy.clearPolicyErrorField(policy?.id ?? '-1', CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED), + onCloseError: () => { + if (!policyID) { + return; + } + Policy.clearPolicyErrorField(policyID, CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED); + }, }, ]; @@ -357,6 +363,9 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro { + if (!policyID) { + return; + } setIsOrganizeWarningModalOpen(false); Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)); }} @@ -369,6 +378,9 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro { + if (!policyID) { + return; + } setIsIntegrateWarningModalOpen(false); Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)); }} @@ -382,6 +394,9 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro title={translate('workspace.reportFields.disableReportFields')} isVisible={isReportFieldsWarningModalOpen} onConfirm={() => { + if (!policyID) { + return; + } setIsReportFieldsWarningModalOpen(false); Policy.enablePolicyReportFields(policyID, false); }}