Skip to content

Commit

Permalink
polish endpoints usages
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed Jul 9, 2024
1 parent a6d6588 commit 452d279
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type UpdateSageIntacctNonreimbursableExpensesExportAccountParams = {
policyID: string;
bankAccountID: string;
creditCardAccountID: string;
};

export default UpdateSageIntacctNonreimbursableExpensesExportAccountParams;
7 changes: 3 additions & 4 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,19 +617,18 @@ function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connect
return (connection as ConnectionWithLastSyncData)?.lastSync?.successfulDate;
}

function getSageIntacctVendors(policy?: Policy, selectedVendorId?: string | null): SelectorType[] {
function getSageIntacctVendors(policy?: Policy, selectedVendorId?: string): SelectorType[] {
const vendors = policy?.connections?.intacct?.data?.vendors ?? [];
const isMatchFound = vendors?.some(({id}) => id === selectedVendorId);

return vendors.map(({id, value}) => ({
value: id,
text: value,
keyForList: id,
isSelected: isMatchFound && selectedVendorId === id,
isSelected: selectedVendorId === id,
}));
}

function getSageIntacctNonReimbursableActiveDefaultVendor(policy?: Policy): string | null | undefined {
function getSageIntacctNonReimbursableActiveDefaultVendor(policy?: Policy): string | undefined {
const {
nonReimbursableCreditCardChargeDefaultVendor: creditCardDefaultVendor,
nonReimbursableVendor: expenseReportDefaultVendor,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/connections/SageIntacct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function updateSageIntacctNonreimbursableExpensesExportAccount(policyID: string,
const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT, nonReimbursableAccount);
const parameters: UpdateSageIntacctNonreimbursableExpensesExportAccountParams = {
policyID,
bankAccountID: nonReimbursableAccount,
creditCardAccountID: nonReimbursableAccount,
};

API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_ACCOUNT, parameters, {optimisticData, failureData, successData});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type MenuListItem = ListItem & {
value: ValueOf<typeof CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE>;
};

function getDefaultVendorName(defaultVendor: string, vendors: SageIntacctDataElementWithValue[]): string {
return vendors.find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor;
function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined {
return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor;
}

function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) {
Expand Down Expand Up @@ -55,10 +55,12 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) {

const defaultVendor = useMemo(() => {
const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy);
const defaultVendorName = getDefaultVendorName(activeDefaultVendor, intacctData?.vendors);

const defaultVendorSection = {
description: translate('workspace.sageIntacct.defaultVendor'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE.toLowerCase())),
title: activeDefaultVendor ? getDefaultVendorName(activeDefaultVendor, intacctData?.vendors ?? []) : translate('workspace.sageIntacct.notConfigured'),
title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'),
hasError:
config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL
? !!config?.errorFields?.nonReimbursableVendor
Expand Down Expand Up @@ -163,7 +165,7 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) {
switchAccessibilityLabel={translate('workspace.sageIntacct.defaultVendor')}
isActive={!!config?.export.nonReimbursableCreditCardChargeDefaultVendor}
onToggle={(enabled) => {
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? null : null;
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : '';
updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor);
}}
wrapperStyle={[styles.ph5, styles.pv3]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback} from 'react';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import ConnectionLayout from '@components/ConnectionLayout';
Expand All @@ -25,8 +25,8 @@ type MenuListItem = ListItem & {
value: ValueOf<typeof CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE>;
};

function getDefaultVendorName(defaultVendor: string, vendors: SageIntacctDataElementWithValue[]): string {
return vendors.find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor;
function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined {
return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor;
}

function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) {
Expand Down Expand Up @@ -55,30 +55,39 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) {
[reimbursable, policyID],
);

const defaultVendorSection = {
description: translate('workspace.sageIntacct.defaultVendor'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)),
title: reimbursableExpenseReportDefaultVendor
? getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors ?? [])
: translate('workspace.sageIntacct.notConfigured'),
hasError: !!config?.errorFields?.reimbursableExpenseReportDefaultVendor,
pendingAction: config?.pendingFields?.reimbursableExpenseReportDefaultVendor,
};
const defaultVendor = useMemo(() => {
const defaultVendorName = getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors);

const defaultVendor = (
<OfflineWithFeedback
key={defaultVendorSection.description}
pendingAction={defaultVendorSection.pendingAction}
>
<MenuItemWithTopDescription
title={defaultVendorSection.title}
description={defaultVendorSection.description}
shouldShowRightIcon
onPress={defaultVendorSection.action}
brickRoadIndicator={defaultVendorSection.hasError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
);
const defaultVendorSection = {
description: translate('workspace.sageIntacct.defaultVendor'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)),
title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'),
hasError: !!config?.errorFields?.reimbursableExpenseReportDefaultVendor,
pendingAction: config?.pendingFields?.reimbursableExpenseReportDefaultVendor,
};

return (
<OfflineWithFeedback
key={defaultVendorSection.description}
pendingAction={defaultVendorSection.pendingAction}
>
<MenuItemWithTopDescription
title={defaultVendorSection.title}
description={defaultVendorSection.description}
shouldShowRightIcon
onPress={defaultVendorSection.action}
brickRoadIndicator={defaultVendorSection.hasError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
</OfflineWithFeedback>
);
}, [
config?.errorFields?.reimbursableExpenseReportDefaultVendor,
config?.pendingFields?.reimbursableExpenseReportDefaultVendor,
intacctData?.vendors,
policyID,
reimbursableExpenseReportDefaultVendor,
translate,
]);

return (
<ConnectionLayout
Expand Down Expand Up @@ -120,7 +129,7 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) {
switchAccessibilityLabel={translate('workspace.sageIntacct.defaultVendor')}
isActive={!!reimbursableExpenseReportDefaultVendor}
onToggle={(enabled) => {
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? null : null;
const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : '';
updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor);
}}
pendingAction={config?.pendingFields?.reimbursableExpenseReportDefaultVendor}
Expand Down
6 changes: 3 additions & 3 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,16 @@ type SageIntacctExportConfig = {
nonReimbursableAccount: string;

/** Default vendor used for credit card transactions of non-reimbursable bill */
nonReimbursableCreditCardChargeDefaultVendor: string | null;
nonReimbursableCreditCardChargeDefaultVendor: string;

/** Default vendor of non-reimbursable bill */
nonReimbursableVendor: string | null;
nonReimbursableVendor: string;

/** Defines how reimbursable expenses are exported */
reimbursable: ValueOf<typeof CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE>;

/** Default vendor of reimbursable bill */
reimbursableExpenseReportDefaultVendor: string | null;
reimbursableExpenseReportDefaultVendor: string;
};

/**
Expand Down

0 comments on commit 452d279

Please sign in to comment.