Skip to content

Commit

Permalink
add logic for check not available account options for company cards
Browse files Browse the repository at this point in the history
  • Loading branch information
narefyev91 committed Dec 31, 2024
1 parent d89e603 commit 38c538b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function SageIntacctExportPage({policy}: WithPolicyProps) {
const route = useRoute<PlatformStackRouteProp<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EXPORT>>();
const backTo = route?.params?.backTo;
const {export: exportConfig, pendingFields, errorFields} = policy?.connections?.intacct?.config ?? {};
const isConnectionShouldBeRemovedFromCompanyCard = exportConfig?.reimbursable === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT && backTo;

const sections = useMemo(
() => [
Expand Down Expand Up @@ -72,8 +73,7 @@ function SageIntacctExportPage({policy}: WithPolicyProps) {
title="workspace.sageIntacct.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
policyID={policyID}
// TODO here we should check - if export account is not supported by company card - we will navigate to card details page instead of go back
onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)}
onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
const {canUseNetSuiteUSATax} = usePermissions();

const config = policy?.connections?.netsuite?.options.config;
const isConnectionShouldBeRemovedFromCompanyCard =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(config?.reimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT ||
config?.nonreimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT) &&
backTo;

const {subsidiaryList, receivableList, taxAccountsList, items} = policy?.connections?.netsuite?.options?.data ?? {};
const selectedSubsidiary = useMemo(() => (subsidiaryList ?? []).find((subsidiary) => subsidiary.internalID === config?.subsidiaryID), [subsidiaryList, config?.subsidiaryID]);
Expand Down Expand Up @@ -200,7 +205,7 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
title="workspace.netsuite.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
policyID={policyID}
onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)}
onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function QuickbooksExportConfigurationPage({policy}: WithPolicyConnectionsProps)
() => qboConfig?.nonReimbursableExpensesExportDestination === CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.VENDOR_BILL,
[qboConfig?.nonReimbursableExpensesExportDestination],
);
const isConnectionShouldBeRemovedFromCompanyCard = shouldShowVendorMenuItems && backTo;

const menuItems = [
{
description: translate('workspace.accounting.preferredExporter'),
Expand Down Expand Up @@ -84,7 +86,7 @@ function QuickbooksExportConfigurationPage({policy}: WithPolicyConnectionsProps)
title="workspace.qbo.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
policyID={policyID}
onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)}
onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
const policyOwner = policy?.owner ?? '';

const {export: exportConfiguration, errorFields, pendingFields} = policy?.connections?.xero?.config ?? {};
const isConnectionShouldBeRemovedFromCompanyCard = !exportConfiguration?.nonReimbursableAccount && backTo;

const {bankAccounts} = policy?.connections?.xero?.data ?? {};
const selectedBankAccountName = useMemo(() => {
Expand Down Expand Up @@ -94,7 +95,7 @@ function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
title="workspace.xero.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
policyID={policyID}
onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)}
onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/companyCards/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function getExportMenuItem(
return {
description,
exportType,
shouldShowMenuItem: true,
shouldShowMenuItem: !!exportConfiguration?.nonReimbursableAccount,
title: isDefaultTitle ? defaultCard : selectedAccount?.name,
onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID, backTo)),
data: (resultData ?? []).map((card) => {
Expand Down Expand Up @@ -274,7 +274,7 @@ function getExportMenuItem(
shouldShowMenuItem,
exportType,
title,
onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID, backTo)),
onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID, backTo)),
data,
};
}
Expand Down

0 comments on commit 38c538b

Please sign in to comment.