From beb2a92e577bba046b2f09551639113ad6189644 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 9 Aug 2024 19:15:33 +0200 Subject: [PATCH 1/7] feat: [WIP] updateSettlementFrequency and updateSettlementAccount --- .../UpdateCardSettlementAccountParams.ts | 6 + .../UpdateCardSettlementFrequencyParams.ts | 9 + src/libs/API/parameters/index.ts | 2 + src/libs/API/types.ts | 4 + src/libs/actions/Card.ts | 164 ++++++++---------- .../WorkspaceExpensifyCardBankAccounts.tsx | 8 +- .../WorkspaceSettlementAccountPage.tsx | 14 +- .../WorkspaceSettlementFrequencyPage.tsx | 10 +- src/types/onyx/Policy.ts | 3 + 9 files changed, 121 insertions(+), 99 deletions(-) create mode 100644 src/libs/API/parameters/UpdateCardSettlementAccountParams.ts create mode 100644 src/libs/API/parameters/UpdateCardSettlementFrequencyParams.ts diff --git a/src/libs/API/parameters/UpdateCardSettlementAccountParams.ts b/src/libs/API/parameters/UpdateCardSettlementAccountParams.ts new file mode 100644 index 000000000000..8af37bb9d4ce --- /dev/null +++ b/src/libs/API/parameters/UpdateCardSettlementAccountParams.ts @@ -0,0 +1,6 @@ +type UpdateCardSettlementAccountParams = { + domainName: string; + settlementBankAccountID: number; +}; + +export default UpdateCardSettlementAccountParams; diff --git a/src/libs/API/parameters/UpdateCardSettlementFrequencyParams.ts b/src/libs/API/parameters/UpdateCardSettlementFrequencyParams.ts new file mode 100644 index 000000000000..6085713bac97 --- /dev/null +++ b/src/libs/API/parameters/UpdateCardSettlementFrequencyParams.ts @@ -0,0 +1,9 @@ +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; + +type UpdateCardSettlementFrequencyParams = { + settlementFrequency: ValueOf; + workspaceAccountID: number; +}; + +export default UpdateCardSettlementFrequencyParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index c89bf660fcd4..9a955fd0bd31 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -270,3 +270,5 @@ export type {default as ExportSearchItemsToCSVParams} from './ExportSearchItemsT export type {default as UpdateExpensifyCardLimitParams} from './UpdateExpensifyCardLimitParams'; export type {CreateWorkspaceApprovalParams, UpdateWorkspaceApprovalParams, RemoveWorkspaceApprovalParams} from './WorkspaceApprovalParams'; export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFlowParams'; +export type {default as UpdateCardSettlementFrequencyParams} from './UpdateCardSettlementFrequencyParams'; +export type {default as UpdateCardSettlementAccountParams} from './UpdateCardSettlementAccountParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 57350bf6de13..ac0ab098d238 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -325,6 +325,8 @@ const WRITE_COMMANDS = { CREATE_WORKSPACE_APPROVAL: 'CreateWorkspaceApproval', UPDATE_WORKSPACE_APPROVAL: 'UpdateWorkspaceApproval', REMOVE_WORKSPACE_APPROVAL: 'RemoveWorkspaceApproval', + UPDATE_CARD_SETTLEMENT_FREQUENCY: 'UpdateCardSettlementFrequency', + UPDATE_CARD_SETTLEMENT_ACCOUNT: 'UpdateCardSettlementAccount', } as const; type WriteCommand = ValueOf; @@ -656,6 +658,8 @@ type WriteCommandParameters = { [WRITE_COMMANDS.CREATE_WORKSPACE_APPROVAL]: Parameters.CreateWorkspaceApprovalParams; [WRITE_COMMANDS.UPDATE_WORKSPACE_APPROVAL]: Parameters.UpdateWorkspaceApprovalParams; [WRITE_COMMANDS.REMOVE_WORKSPACE_APPROVAL]: Parameters.RemoveWorkspaceApprovalParams; + [WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY]: Parameters.UpdateCardSettlementFrequencyParams; + [WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_ACCOUNT]: Parameters.UpdateCardSettlementAccountParams; }; const READ_COMMANDS = { diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts index 205a8dc41bba..414fbd1ffe4b 100644 --- a/src/libs/actions/Card.ts +++ b/src/libs/actions/Card.ts @@ -206,100 +206,84 @@ function revealVirtualCardDetails(cardID: number): Promise }); } -function updateSettlementFrequency(policyID: string, frequency: ValueOf) { - // TODO: remove this code when the API is ready - if (frequency === CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY) { - Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, { - monthlySettlementDate: null, - }); - } else { - Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, { - monthlySettlementDate: new Date(), - }); - } +function updateSettlementFrequency(workspaceAccountID: number, settlementFrequency: ValueOf) { + const monthlySettlementDate = settlementFrequency === CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY ? null : new Date(); + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, + value: { + monthlySettlementDate, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, + value: { + monthlySettlementDate, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, + value: { + monthlySettlementDate: null, + }, + }, + ]; + + const parameters = { + workspaceAccountID, + settlementFrequency, + }; - // TODO: uncomment this code when the API is ready - // const optimisticData: OnyxUpdate[] = [ - // { - // onyxMethod: Onyx.METHOD.MERGE, - // key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, - // value: { - // monthlySettlementDate: '', - // }, - // }, - // ]; - // - // const successData: OnyxUpdate[] = [ - // { - // onyxMethod: Onyx.METHOD.MERGE, - // key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, - // value: { - // monthlySettlementDate: '', - // }, - // }, - // ]; - // - // const failureData: OnyxUpdate[] = [ - // { - // onyxMethod: Onyx.METHOD.MERGE, - // key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, - // value: { - // monthlySettlementDate: null, - // }, - // }, - // ]; - // - // const parameters = { - // workspaceAccountID: policyID, - // settlementFrequency: frequency, - // }; - // - // API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData}); + API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData}); } -function updateSettlementAccount(policyID: string, accountID: number) { - // TODO: remove this code when the API is ready - Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, { - paymentBankAccountID: accountID, - }); +function updateSettlementAccount(workspaceAccountID: number, domainName: string, settlementBankAccountID: number) { + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, + value: { + paymentBankAccountID: settlementBankAccountID, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, + value: { + paymentBankAccountID: settlementBankAccountID, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, + value: { + paymentBankAccountID: null, + }, + }, + ]; + + const parameters = { + domainName, + settlementBankAccountID, + }; - // TODO: uncomment this code when the API is ready - // const optimisticData: OnyxUpdate[] = [ - // { - // onyxMethod: Onyx.METHOD.MERGE, - // key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, - // value: { - // paymentBankAccountID: accountID, - // }, - // }, - // ]; - // - // const successData: OnyxUpdate[] = [ - // { - // onyxMethod: Onyx.METHOD.MERGE, - // key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, - // value: { - // paymentBankAccountID: accountID, - // }, - // }, - // ]; - // - // const failureData: OnyxUpdate[] = [ - // { - // onyxMethod: Onyx.METHOD.MERGE, - // key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, - // value: { - // paymentBankAccountID: null, - // }, - // }, - // ]; - // - // const parameters = { - // workspaceAccountID: policyID, - // settlementBankAccountID: accountID, - // }; - // - // API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_ACCOUNT, parameters, {optimisticData, successData, failureData}); + API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_ACCOUNT, parameters, {optimisticData, successData, failureData}); } function setIssueNewCardStepAndData({data, isEditing, step}: IssueNewCardFlowData) { diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx index 470b2c683e70..52e2a1348fa3 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx @@ -30,13 +30,19 @@ function WorkspaceExpensifyCardBankAccounts({route}: WorkspaceExpensifyCardBankA const policyID = route?.params?.policyID ?? '-1'; + // TODO: change for getWorkspaceAccountID + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + + const workspaceAccountID = policy?.workspaceAccountID ?? 0; + const handleAddBankAccount = () => { // TODO: call to API - UpdateCardSettlementAccount Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('new', policyID, ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID))); }; const handleSelectBankAccount = (value: number) => { - Card.updateSettlementAccount(policyID, value); + // TODO: policy domainName + Card.updateSettlementAccount(workspaceAccountID, '', value); Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.getRoute(policyID)); }; diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx index cea951dec45b..fdb411319804 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx @@ -31,10 +31,15 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP const styles = useThemeStyles(); const {translate} = useLocalize(); const policyID = route.params?.policyID ?? '-1'; + // TODO: change for getWorkspaceAccountID + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + + const workspaceAccountID = policy?.workspaceAccountID ?? 0; + const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); - const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`); - const [isUsedContinuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${policyID}`); - const [reconciliationConnection] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${policyID}`); + const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`); + const [isUsedContinuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${workspaceAccountID}`); + const [reconciliationConnection] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${workspaceAccountID}`); const paymentBankAccountID = cardSettings?.paymentBankAccountID ?? ''; const paymentBankAccountNumber = bankAccountsList?.[paymentBankAccountID]?.accountData?.accountNumber ?? ''; @@ -70,7 +75,8 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP }, [eligibleBankAccounts, paymentBankAccountID, styles, translate]); const updateSettlementAccount = (value: number) => { - Card.updateSettlementAccount(policyID, value); + // TODO: policy domainName + Card.updateSettlementAccount(workspaceAccountID, '', value); Navigation.goBack(); }; diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx index 2d6b9bcfad58..254b8080d6a5 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx @@ -25,10 +25,12 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP const {translate} = useLocalize(); const policyID = route.params?.policyID ?? '-1'; - const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); - // TODO: change true for false after API is ready - true is for testing purposes - const shouldShowMonthlyOption = cardSettings?.isMonthlySettlementAllowed ?? true; + const workspaceAccountID = policy?.workspaceAccountID ?? 0; + const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`); + + const shouldShowMonthlyOption = cardSettings?.isMonthlySettlementAllowed ?? false; const selectedFrequency = cardSettings?.monthlySettlementDate ? CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.MONTHLY : CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY; const data = useMemo(() => { @@ -54,7 +56,7 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP }, [translate, shouldShowMonthlyOption, selectedFrequency]); const updateSettlementFrequency = (value: ValueOf) => { - Card.updateSettlementFrequency(policyID, value); + Card.updateSettlementFrequency(workspaceAccountID, value); }; return ( diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 9724229361ec..b1a20348d04d 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1539,6 +1539,9 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< /** Whether GL codes are enabled */ glCodes?: boolean; + + /** ID for the Expensify Card */ + workspaceAccountID?: number; } & Partial, 'generalSettings' | 'addWorkspaceRoom' | keyof ACHAccount >; From 9c26711b8132f48c90e49816785c047dca55580e Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 13 Aug 2024 13:21:08 +0200 Subject: [PATCH 2/7] feat: create getDomainNameForPolicy util --- src/CONST.ts | 3 +++ src/libs/PolicyUtils.ts | 9 +++++++++ .../expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx | 6 +++--- .../expensifyCard/WorkspaceSettlementAccountPage.tsx | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 84b393a1f5ae..a2086872dd9e 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -632,6 +632,9 @@ const CONST = { INBOX: 'inbox', }, + EXPENSIFY_POLICY_DOMAIN: 'expensify_policy', + EXPENSIFY_POLICY_DOMAIN_EXTENSION: '.exfy', + SIGN_IN_FORM_WIDTH: 300, REQUEST_CODE_DELAY: 30, diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 37016b8821fc..67085d9e3170 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -969,6 +969,14 @@ function getWorkspaceAccountID(policyID: string) { return policy.workspaceAccountID ?? 0; } +function getDomainNameForPolicy(policyID?: string): string { + if (!policyID) { + return ''; + } + + return `${CONST.EXPENSIFY_POLICY_DOMAIN}${policyID}${CONST.EXPENSIFY_POLICY_DOMAIN_EXTENSION}`; +} + export { canEditTaxRate, extractPolicyIDFromPath, @@ -1074,6 +1082,7 @@ export { getWorkspaceAccountID, getAllTaxRatesNamesAndKeys as getAllTaxRates, getTagNamesFromTagsLists, + getDomainNameForPolicy, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx index aa6f542ede5e..9d24330d0399 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx @@ -40,8 +40,8 @@ function WorkspaceExpensifyCardBankAccounts({route}: WorkspaceExpensifyCardBankA const handleSelectBankAccount = (value?: number) => { Card.configureExpensifyCardsForPolicy(policyID, value); const handleSelectBankAccount = (value: number) => { - // TODO: policy domainName - Card.updateSettlementAccount(workspaceAccountID, '', value); + const domainName = PolicyUtils.getDomainNameForPolicy(policyID); + Card.updateSettlementAccount(workspaceAccountID, domainName, value); Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.getRoute(policyID)); }; @@ -55,7 +55,7 @@ function WorkspaceExpensifyCardBankAccounts({route}: WorkspaceExpensifyCardBankA return eligibleBankAccounts.map((bankAccount) => { const bankName = (bankAccount.accountData?.addressName ?? '') as BankName; const bankAccountNumber = bankAccount.accountData?.accountNumber ?? ''; - const bankAccountID = bankAccount.accountData?.bankAccountID; + const bankAccountID = bankAccount.accountData?.bankAccountID; const {icon, iconSize, iconStyles} = getBankIcon({bankName, styles}); diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx index 6c885127d2f6..ab7ed2153c7c 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx @@ -73,8 +73,8 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP }, [eligibleBankAccounts, paymentBankAccountID, styles, translate]); const updateSettlementAccount = (value: number) => { - // TODO: policy domainName - Card.updateSettlementAccount(workspaceAccountID, value); + const domainName = PolicyUtils.getDomainNameForPolicy(policyID); + Card.updateSettlementAccount(workspaceAccountID, domainName, value); Navigation.goBack(); }; From 8a405f0f1ac6d0a9a5865a4842819bc988fc9ff0 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 13 Aug 2024 13:28:13 +0200 Subject: [PATCH 3/7] fix: minor fix --- src/libs/actions/Card.ts | 6 +- .../WorkspaceExpensifyCardBankAccounts.tsx | 110 +++++++++--------- 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts index c2c5aac1ad05..ec47e3beba73 100644 --- a/src/libs/actions/Card.ts +++ b/src/libs/actions/Card.ts @@ -247,7 +247,11 @@ function updateSettlementFrequency(workspaceAccountID: number, settlementFrequen API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData}); } -function updateSettlementAccount(workspaceAccountID: number, domainName: string, settlementBankAccountID: number) { +function updateSettlementAccount(workspaceAccountID: number, domainName: string, settlementBankAccountID?: number) { + if (!settlementBankAccountID) { + return; + } + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx index 9d24330d0399..ae9a660b0d59 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx @@ -37,69 +37,67 @@ function WorkspaceExpensifyCardBankAccounts({route}: WorkspaceExpensifyCardBankA Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('new', policyID, ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID))); }; - const handleSelectBankAccount = (value?: number) => { + const handleSelectBankAccount = (value: number) => { Card.configureExpensifyCardsForPolicy(policyID, value); - const handleSelectBankAccount = (value: number) => { - const domainName = PolicyUtils.getDomainNameForPolicy(policyID); - Card.updateSettlementAccount(workspaceAccountID, domainName, value); - Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.getRoute(policyID)); - }; + const domainName = PolicyUtils.getDomainNameForPolicy(policyID); + Card.updateSettlementAccount(workspaceAccountID, domainName, value); + Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.getRoute(policyID)); + }; - const renderBankOptions = () => { - if (!bankAccountsList || isEmptyObject(bankAccountsList)) { - return null; - } + const renderBankOptions = () => { + if (!bankAccountsList || isEmptyObject(bankAccountsList)) { + return null; + } - const eligibleBankAccounts = CardUtils.getEligibleBankAccountsForCard(bankAccountsList); + const eligibleBankAccounts = CardUtils.getEligibleBankAccountsForCard(bankAccountsList); - return eligibleBankAccounts.map((bankAccount) => { - const bankName = (bankAccount.accountData?.addressName ?? '') as BankName; - const bankAccountNumber = bankAccount.accountData?.accountNumber ?? ''; - const bankAccountID = bankAccount.accountData?.bankAccountID; + return eligibleBankAccounts.map((bankAccount) => { + const bankName = (bankAccount.accountData?.addressName ?? '') as BankName; + const bankAccountNumber = bankAccount.accountData?.accountNumber ?? ''; + const bankAccountID = bankAccount.accountData?.bankAccountID; - const {icon, iconSize, iconStyles} = getBankIcon({bankName, styles}); + const {icon, iconSize, iconStyles} = getBankIcon({bankName, styles}); - return ( - handleSelectBankAccount(bankAccountID)} - icon={icon} - iconHeight={iconSize} - iconWidth={iconSize} - iconStyles={iconStyles} - shouldShowRightIcon - displayInDefaultIconColor - /> - ); - }); - }; + return ( + handleSelectBankAccount(bankAccountID)} + icon={icon} + iconHeight={iconSize} + iconWidth={iconSize} + iconStyles={iconStyles} + shouldShowRightIcon + displayInDefaultIconColor + /> + ); + }); + }; - return ( - - Navigation.goBack()} - title={translate('workspace.expensifyCard.chooseBankAccount')} + return ( + + Navigation.goBack()} + title={translate('workspace.expensifyCard.chooseBankAccount')} + /> + + {translate('workspace.expensifyCard.chooseExistingBank')} + {renderBankOptions()} + - - {translate('workspace.expensifyCard.chooseExistingBank')} - {renderBankOptions()} - - - - ); - } + + + ); +} - WorkspaceExpensifyCardBankAccounts.displayName = 'WorkspaceExpensifyCardBankAccounts'; +WorkspaceExpensifyCardBankAccounts.displayName = 'WorkspaceExpensifyCardBankAccounts'; - export default WorkspaceExpensifyCardBankAccounts; +export default WorkspaceExpensifyCardBankAccounts; From cacd33ef34e89c1503b53a49017c320c777e522b Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 13 Aug 2024 16:16:11 +0200 Subject: [PATCH 4/7] fix: typecheck --- .../expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx index ae9a660b0d59..78060487d35f 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx @@ -37,7 +37,7 @@ function WorkspaceExpensifyCardBankAccounts({route}: WorkspaceExpensifyCardBankA Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('new', policyID, ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID))); }; - const handleSelectBankAccount = (value: number) => { + const handleSelectBankAccount = (value?: number) => { Card.configureExpensifyCardsForPolicy(policyID, value); const domainName = PolicyUtils.getDomainNameForPolicy(policyID); Card.updateSettlementAccount(workspaceAccountID, domainName, value); From 1005b60b643f77fcea3b664f5be209359cb70c5f Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 13 Aug 2024 16:29:01 +0200 Subject: [PATCH 5/7] fix: minor fix --- .../workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx index 182b05639248..84c02c65b3f3 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx @@ -29,7 +29,6 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`); - // TODO: change true for false after API is ready - true is for testing purposes const shouldShowMonthlyOption = cardSettings?.isMonthlySettlementAllowed ?? false; const selectedFrequency = cardSettings?.monthlySettlementDate ? CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.MONTHLY : CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY; From acc9224b298791af0e476b6cc1707f23843b1bce Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 13 Aug 2024 16:45:19 +0200 Subject: [PATCH 6/7] fix: apply requested changes --- src/libs/actions/Card.ts | 8 ++++---- .../expensifyCard/WorkspaceSettlementAccountPage.tsx | 2 +- .../expensifyCard/WorkspaceSettlementFrequencyPage.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts index 441c7ba45caa..2ca77c22c5ff 100644 --- a/src/libs/actions/Card.ts +++ b/src/libs/actions/Card.ts @@ -206,7 +206,7 @@ function revealVirtualCardDetails(cardID: number): Promise }); } -function updateSettlementFrequency(workspaceAccountID: number, settlementFrequency: ValueOf) { +function updateSettlementFrequency(workspaceAccountID: number, settlementFrequency: ValueOf, currentFrequency?: Date) { const monthlySettlementDate = settlementFrequency === CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY ? null : new Date(); const optimisticData: OnyxUpdate[] = [ @@ -234,7 +234,7 @@ function updateSettlementFrequency(workspaceAccountID: number, settlementFrequen onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, value: { - monthlySettlementDate: null, + monthlySettlementDate: currentFrequency, }, }, ]; @@ -247,7 +247,7 @@ function updateSettlementFrequency(workspaceAccountID: number, settlementFrequen API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData}); } -function updateSettlementAccount(workspaceAccountID: number, domainName: string, settlementBankAccountID?: number) { +function updateSettlementAccount(workspaceAccountID: number, domainName: string, settlementBankAccountID?: number, currentSettlementBankAccountID?: number) { if (!settlementBankAccountID) { return; } @@ -277,7 +277,7 @@ function updateSettlementAccount(workspaceAccountID: number, domainName: string, onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, value: { - paymentBankAccountID: null, + paymentBankAccountID: currentSettlementBankAccountID, }, }, ]; diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx index ab7ed2153c7c..9e91a55dd04e 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx @@ -74,7 +74,7 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP const updateSettlementAccount = (value: number) => { const domainName = PolicyUtils.getDomainNameForPolicy(policyID); - Card.updateSettlementAccount(workspaceAccountID, domainName, value); + Card.updateSettlementAccount(workspaceAccountID, domainName, value, paymentBankAccountID); Navigation.goBack(); }; diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx index 84c02c65b3f3..84f1bb810af2 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx @@ -55,7 +55,7 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP }, [translate, shouldShowMonthlyOption, selectedFrequency]); const updateSettlementFrequency = (value: ValueOf) => { - Card.updateSettlementFrequency(workspaceAccountID, value); + Card.updateSettlementFrequency(workspaceAccountID, value, cardSettings?.monthlySettlementDate); }; return ( From 4cd7ab1965cdbf4af83dabb0daec309fa52e283c Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 14 Aug 2024 11:35:05 +0200 Subject: [PATCH 7/7] fix: add a comment --- src/CONST.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CONST.ts b/src/CONST.ts index 312a084aba33..48b669bbe567 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -632,6 +632,7 @@ const CONST = { INBOX: 'inbox', }, + // TODO: change to expensify-policy once the new domain is available EXPENSIFY_POLICY_DOMAIN: 'expensify_policy', EXPENSIFY_POLICY_DOMAIN_EXTENSION: '.exfy',