Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Workflow payer page #37629

Merged
merged 87 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
9f10186
adds workflow payer page
ishpaul777 Mar 1, 2024
6492353
fixes scrollins issue and adds submenuitem for payer
ishpaul777 Mar 1, 2024
bbefc40
Merge branch 'main' into workflow/payer
ishpaul777 Mar 1, 2024
3bc8478
fixes type error
ishpaul777 Mar 1, 2024
f5bcfa5
fix failing tests
ishpaul777 Mar 1, 2024
5ac67c2
fixes type errors
ishpaul777 Mar 1, 2024
b9e0dc0
fixes conflicts with mail
ishpaul777 Mar 1, 2024
927aacc
basic structure for payer page
ishpaul777 Mar 1, 2024
654e080
toggle setWorkspaceReimbursement v1
ishpaul777 Mar 1, 2024
81d0698
adds section list for payerpage
ishpaul777 Mar 1, 2024
58ebe8c
fixes crash for ios
ishpaul777 Mar 1, 2024
90b959c
Merge branch 'Expensify:main' into workflow/payer
ishpaul777 Mar 2, 2024
d7a55d5
fixes lint issue and add api command
ishpaul777 Mar 2, 2024
cd83702
fixes offline behaviour and offline behaviour
ishpaul777 Mar 2, 2024
03b63c0
fixes option toggle on/off
ishpaul777 Mar 4, 2024
4c3bd57
fixes bank account fetch logic
ishpaul777 Mar 4, 2024
6618475
resolve lint
ishpaul777 Mar 4, 2024
99f932c
remove unused type
ishpaul777 Mar 4, 2024
0cb874c
fix error indicator for menu item
ishpaul777 Mar 4, 2024
a5c5ed9
prettier diffs
ishpaul777 Mar 4, 2024
2356983
fixes copy for the error
ishpaul777 Mar 4, 2024
2959971
Merge branch 'main' into workflow/payer
ishpaul777 Mar 4, 2024
af86bf7
fixes translations and lint
ishpaul777 Mar 4, 2024
eec2653
fixes command name
ishpaul777 Mar 4, 2024
b2ce7fc
Update src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
ishpaul777 Mar 4, 2024
bb9bc3a
fixes type error
ishpaul777 Mar 4, 2024
7b28613
fixes conditons for toggle
ishpaul777 Mar 4, 2024
1a1e764
fixes lint and wrong conditional
ishpaul777 Mar 4, 2024
10f914b
fixes offline behaviour and error handling
ishpaul777 Mar 4, 2024
87dc36d
Merge branch 'main' into workflow/payer
ishpaul777 Mar 7, 2024
1d4f4f9
resolve conflict
ishpaul777 Mar 7, 2024
9bbb535
fix dupe type in policy
ishpaul777 Mar 7, 2024
3056fd0
changes command as per requirements
ishpaul777 Mar 7, 2024
5fa216b
Merge branch 'main' into workflow/payer
ishpaul777 Mar 7, 2024
9af4517
use usenetwork hook for fetch data
ishpaul777 Mar 7, 2024
370b597
Merge branch 'workflow/payer' of https://github.com/ishpaul777/App in…
ishpaul777 Mar 7, 2024
d4bf8fd
lint and use account instead of email for fetching the reimburser det…
ishpaul777 Mar 7, 2024
e1c9f12
fix type and lint warning
ishpaul777 Mar 8, 2024
8931440
remove unused var
ishpaul777 Mar 8, 2024
b7a8a49
fix style for connect account page
ishpaul777 Mar 8, 2024
980be51
remove useCallback usage
ishpaul777 Mar 8, 2024
ff0c8bd
prettier diffs
ishpaul777 Mar 8, 2024
ffd918d
remove console
ishpaul777 Mar 8, 2024
ee6e202
Update src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
ishpaul777 Mar 8, 2024
73f98f5
Merge branch 'Expensify:main' into workflow/payer
ishpaul777 Mar 8, 2024
a523144
fix error handling in payer page
ishpaul777 Mar 8, 2024
c80ab58
remove unneccessary changes in offline with feedback
ishpaul777 Mar 8, 2024
77a7760
remove unused prop
ishpaul777 Mar 8, 2024
b81746e
get the errors correctly
ishpaul777 Mar 8, 2024
d2ddb3c
remove test data
ishpaul777 Mar 8, 2024
8144944
use the latest error field
ishpaul777 Mar 8, 2024
3f35739
fixes prettier diffs
ishpaul777 Mar 8, 2024
67dd749
use accountid for selected member
ishpaul777 Mar 8, 2024
bf8e92b
remove unused changes
ishpaul777 Mar 8, 2024
d18a177
Merge branch 'main' into workflow/payer
ishpaul777 Mar 8, 2024
31d58cd
fix prettier diffs
ishpaul777 Mar 8, 2024
69b65cd
Merge branch 'Expensify:main' into workflow/payer
ishpaul777 Mar 11, 2024
3d7b851
fix variable naming
ishpaul777 Mar 11, 2024
ab3ee95
remove chnages to fix 37403
ishpaul777 Mar 11, 2024
4f06287
resolves prettier diffs
ishpaul777 Mar 11, 2024
efbac74
remove unnecessary offline behavior
ishpaul777 Mar 11, 2024
0dc3e04
use correct offline behaviour in payer page
ishpaul777 Mar 11, 2024
bf659a0
use correct translation key
ishpaul777 Mar 11, 2024
6f7333a
fix console error for virtualized list
ishpaul777 Mar 11, 2024
511fc1f
Merge branch 'main' into workflow/payer
ishpaul777 Mar 11, 2024
3d80721
show RBR in workflow menu
ishpaul777 Mar 11, 2024
e8a0a22
hide expensify team member from the list
ishpaul777 Mar 11, 2024
a4bc907
use single variable for skipping a member in the list
ishpaul777 Mar 11, 2024
bd8004c
fix console error
ishpaul777 Mar 11, 2024
673057a
show laoding indicator while call in progress
ishpaul777 Mar 11, 2024
48a10f2
Merge branch 'Expensify:main' into workflow/payer
ishpaul777 Mar 11, 2024
e43ece9
fix how we get displayname for the payer
ishpaul777 Mar 11, 2024
c9f7af9
set reimburserAccountID optimistically
ishpaul777 Mar 11, 2024
438e3b1
fix lint
ishpaul777 Mar 11, 2024
b821a4b
lint fix and sync reimburseremail and accountid
ishpaul777 Mar 11, 2024
1f285df
Merge branch 'main' into workflow/payer
ishpaul777 Mar 11, 2024
3993760
resolve exhaustive deps warning
ishpaul777 Mar 11, 2024
5a34a96
Merge branch 'workflow/payer' of https://github.com/ishpaul777/App in…
ishpaul777 Mar 11, 2024
17e3427
lint fix and sync reimburserEmail and accountid in setWorkspacePayer
ishpaul777 Mar 11, 2024
e3b8564
removes unnecessary changes
ishpaul777 Mar 11, 2024
499dafe
adds required styling
ishpaul777 Mar 12, 2024
ddac89e
remove unnecessary changes
ishpaul777 Mar 12, 2024
1847389
add failing error for toggle button
ishpaul777 Mar 12, 2024
2237dfe
added onclose error message callback
ishpaul777 Mar 12, 2024
fe8a1da
lint fix
ishpaul777 Mar 12, 2024
2215017
remove unnecessary changes
ishpaul777 Mar 12, 2024
7db1690
lint fix
ishpaul777 Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ const ROUTES = {
route: 'workspace/:policyID/workflows',
getRoute: (policyID: string) => `workspace/${policyID}/workflows` as const,
},
WORKSPACE_WORKFLOWS_PAYER: {
route: 'workspace/:policyID/settings/workflows/payer',
getRoute: (policyId: string) => `workspace/${policyId}/settings/workflows/payer` as const,
},
WORKSPACE_WORKFLOWS_APPROVER: {
route: 'workspace/:policyID/settings/workflows/approver',
getRoute: (policyId: string) => `workspace/${policyId}/settings/workflows/approver` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const SCREENS = {
CATEGORIES: 'Workspace_Categories',
CURRENCY: 'Workspace_Profile_Currency',
WORKFLOWS: 'Workspace_Workflows',
WORKFLOWS_PAYER: 'Workspace_Workflows_Payer',
WORKFLOWS_APPROVER: 'Workspace_Workflows_Approver',
WORKFLOWS_AUTO_REPORTING_FREQUENCY: 'Workspace_Workflows_Auto_Reporting_Frequency',
WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET: 'Workspace_Workflows_Auto_Reporting_Monthly_Offset',
Expand Down
6 changes: 6 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,15 @@ export default {
addApprovalsDescription: 'Require additional approval before authorizing a payment.',
makeOrTrackPaymentsTitle: 'Make or track payments',
makeOrTrackPaymentsDescription: 'Add an authorized payer for payments made in Expensify, or simply track payments made elsewhere.',
authorizedPayer: 'Authorized payer',
admins: 'Admins',
editor: {
submissionFrequency: 'Choose how long Expensify should wait before sharing error-free spend.',
},
// TODO: confirm copy
genericErrorMessage: {
authorizedPayer: 'The authorized payer could not be updated. Please try again.',
},
frequencies: {
lakchote marked this conversation as resolved.
Show resolved Hide resolved
weekly: 'Weekly',
monthly: 'Monthly',
Expand Down
8 changes: 8 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,17 @@ export default {
addApprovalsDescription: 'Requiere una aprobación adicional antes de autorizar un pago.',
makeOrTrackPaymentsTitle: 'Realizar o seguir pagos',
makeOrTrackPaymentsDescription: 'Añade un pagador autorizado para los pagos realizados en Expensify, o simplemente realiza un seguimiento de los pagos realizados en otro lugar.',
// todo: add translations and cofirm copy
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
authorizedPayer: 'Authorized payer',
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
// todo: add translations and cofirm copy
admins: 'Administradores',
editor: {
submissionFrequency: 'Elige cuánto tiempo Expensify debe esperar antes de compartir los gastos sin errores.',
},
// todo: add translations and cofirm copy
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
genericErrorMessage: {
authorizedPayer: 'The authorized payer could not be updated. Please try again.',
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
},
frequencies: {
weekly: 'Semanal',
monthly: 'Mensual',
Expand Down
9 changes: 9 additions & 0 deletions src/libs/API/parameters/SetReimbursementFromChoiceParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {ValueOf} from 'type-fest';
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
import type CONST from '@src/CONST';

type SetReimbursementFromChoiceParams = {
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
policyID: string;
reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>;
};

export default SetReimbursementFromChoiceParams;
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions src/libs/API/parameters/SetWorkspaceReimbursementParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type SetWorkspaceReimbursementParams = {
policyID: string;
reimburserEmail: string;
};

export default SetWorkspaceReimbursementParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ export type {default as SetWorkspaceAutoReportingParams} from './SetWorkspaceAut
export type {default as SetWorkspaceAutoReportingFrequencyParams} from './SetWorkspaceAutoReportingFrequencyParams';
export type {default as SetWorkspaceAutoReportingMonthlyOffsetParams} from './SetWorkspaceAutoReportingMonthlyOffsetParams';
export type {default as SetWorkspaceApprovalModeParams} from './SetWorkspaceApprovalModeParams';
export type {default as SetWorkspaceReimbursementParams} from './SetWorkspaceReimbursementParams';
export type {default as SetReimbursementFromChoiceParams} from './SetReimbursementFromChoiceParams';
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
export type {default as SwitchToOldDotParams} from './SwitchToOldDotParams';
4 changes: 4 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const WRITE_COMMANDS = {
SET_WORKSPACE_AUTO_REPORTING_FREQUENCY: 'SetWorkspaceAutoReportingFrequency',
SET_WORKSPACE_AUTO_REPORTING_MONTHLY_OFFSET: 'UpdatePolicy',
SET_WORKSPACE_APPROVAL_MODE: 'SetWorkspaceApprovalMode',
SET_WORKSPACE_REIMBURSEMENT: 'SetWorkspaceReimbursement',
SET_REIMBURSEMENT_FROM_CHOICE: 'Policy_setReimbursementFromChoice',
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
DISMISS_REFERRAL_BANNER: 'DismissReferralBanner',
UPDATE_PREFERRED_LOCALE: 'UpdatePreferredLocale',
OPEN_APP: 'OpenApp',
Expand Down Expand Up @@ -309,6 +311,8 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.SET_WORKSPACE_AUTO_REPORTING_FREQUENCY]: Parameters.SetWorkspaceAutoReportingFrequencyParams;
[WRITE_COMMANDS.SET_WORKSPACE_AUTO_REPORTING_MONTHLY_OFFSET]: Parameters.SetWorkspaceAutoReportingMonthlyOffsetParams;
[WRITE_COMMANDS.SET_WORKSPACE_APPROVAL_MODE]: Parameters.SetWorkspaceApprovalModeParams;
[WRITE_COMMANDS.SET_WORKSPACE_REIMBURSEMENT]: Parameters.SetWorkspaceReimbursementParams;
[WRITE_COMMANDS.SET_REIMBURSEMENT_FROM_CHOICE]: Parameters.SetReimbursementFromChoiceParams;
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
[WRITE_COMMANDS.SWITCH_TO_OLD_DOT]: Parameters.SwitchToOldDotParams;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.WORKSPACE.INVITE]: () => require('../../../pages/workspace/WorkspaceInvitePage').default as React.ComponentType,
[SCREENS.WORKSPACE.WORKFLOWS_APPROVER]: () => require('../../../pages/workspace/workflows/WorkspaceWorkflowsApproverPage').default as React.ComponentType,
[SCREENS.WORKSPACE.INVITE_MESSAGE]: () => require('../../../pages/workspace/WorkspaceInviteMessagePage').default as React.ComponentType,
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: () => require('../../../pages/workspace/workflows/WorkspaceWorkflowsPayerPage').default as React.ComponentType,
[SCREENS.WORKSPACE.NAME]: () => require('../../../pages/workspace/WorkspaceNamePage').default as React.ComponentType,
[SCREENS.WORKSPACE.DESCRIPTION]: () => require('../../../pages/workspace/WorkspaceProfileDescriptionPage').default as React.ComponentType,
[SCREENS.WORKSPACE.SHARE]: () => require('../../../pages/workspace/WorkspaceProfileSharePage').default as React.ComponentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CENTRAL_PANE_TO_RHP_MAPPING: Partial<Record<CentralPaneName, string[]>> =
[SCREENS.WORKSPACE.PROFILE]: [SCREENS.WORKSPACE.NAME, SCREENS.WORKSPACE.CURRENCY, SCREENS.WORKSPACE.DESCRIPTION, SCREENS.WORKSPACE.SHARE],
[SCREENS.WORKSPACE.REIMBURSE]: [SCREENS.WORKSPACE.RATE_AND_UNIT, SCREENS.WORKSPACE.RATE_AND_UNIT_RATE, SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT],
[SCREENS.WORKSPACE.MEMBERS]: [SCREENS.WORKSPACE.INVITE, SCREENS.WORKSPACE.INVITE_MESSAGE],
[SCREENS.WORKSPACE.WORKFLOWS]: [SCREENS.WORKSPACE.WORKFLOWS_APPROVER],
[SCREENS.WORKSPACE.WORKFLOWS]: [SCREENS.WORKSPACE.WORKFLOWS_PAYER, SCREENS.WORKSPACE.WORKFLOWS_APPROVER],
};

export default CENTRAL_PANE_TO_RHP_MAPPING;
3 changes: 3 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.WORKSPACE.CATEGORIES_SETTINGS]: {
path: ROUTES.WORKSPACE_CATEGORIES_SETTINGS.route,
},
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: {
path: ROUTES.WORKSPACE_WORKFLOWS_PAYER.route,
},
[SCREENS.REIMBURSEMENT_ACCOUNT]: {
path: ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.route,
exact: true,
Expand Down
9 changes: 6 additions & 3 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type CentralPaneNavigatorParamList = {
[SCREENS.WORKSPACE.WORKFLOWS]: {
policyID: string;
};
[SCREENS.WORKSPACE.WORKFLOWS_APPROVER]: {
policyID: string;
};
[SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY]: {
policyID: string;
};
Expand Down Expand Up @@ -161,6 +158,12 @@ type SettingsNavigatorParamList = {
/** domain passed via route /settings/wallet/card/:domain */
domain: string;
};
[SCREENS.WORKSPACE.WORKFLOWS_APPROVER]: {
policyID: string;
};
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: {
policyID: string;
};
[SCREENS.SETTINGS.WALLET.TRANSFER_BALANCE]: undefined;
[SCREENS.SETTINGS.WALLET.CHOOSE_TRANSFER_ACCOUNT]: undefined;
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS]: undefined;
Expand Down
113 changes: 113 additions & 0 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import type {
OpenWorkspaceMembersPageParams,
OpenWorkspaceParams,
OpenWorkspaceReimburseViewParams,
SetReimbursementFromChoiceParams,
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
SetWorkspaceApprovalModeParams,
SetWorkspaceAutoReportingFrequencyParams,
SetWorkspaceAutoReportingMonthlyOffsetParams,
SetWorkspaceAutoReportingParams,
SetWorkspaceReimbursementParams,
UpdateWorkspaceAvatarParams,
UpdateWorkspaceCustomUnitAndRateParams,
UpdateWorkspaceDescriptionParams,
Expand Down Expand Up @@ -560,6 +562,114 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
API.write(WRITE_COMMANDS.SET_WORKSPACE_APPROVAL_MODE, params, {optimisticData, failureData, successData});
}

/**
*
* @param policyID
* @param reimburserEmail
*/
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
function setWorkspaceReimbursement(policyID: string, reimburserEmail: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be SetWorkspacePayer? It seems like we're just setting the authorized payer here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command name is SetWorkspaceReimbursement, so i tried to keep it same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, we have 2 commands SetWorkspaceReimbursement and WorkspaceWorkflowsPayer, one enables the feature, the other sets the payer. Looking at the Onyx data and the params for this command, it seems like it should be WorkspaceWorkflowsPayer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a clarification from @lakchote 🙇‍♂️ keeping it unresolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as here

Seems like we mismatched names SetWorkspaceReimbursement and WorkspaceWorkflowsPayer in the DD.

const policy = ReportUtils.getPolicy(policyID);

ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
const currentPolicyReimburserEmail = policy.reimburserEmail;

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimburserEmail,
errorFields: {reimburserEmail: null},
pendingFields: {reimburserEmail: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimburserEmail: currentPolicyReimburserEmail,
errorFields: {reimburserEmail: ErrorUtils.getMicroSecondOnyxError('workflowsPage.genericErrorMessage.authorizedPayer')},
pendingFields: {reimburserEmail: null},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
errorFields: {reimburserEmail: null},
pendingFields: {reimburserEmail: null},
},
},
];

const params: SetWorkspaceReimbursementParams = {policyID, reimburserEmail};

API.write(WRITE_COMMANDS.SET_WORKSPACE_REIMBURSEMENT, params, {optimisticData, failureData, successData});
}

/**
* clear the workspace reimbursement error while setting the authorized payer
* @param policyID
*/
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
function clearWorkspaceReimbursementError(policyID: string) {
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {reimburserEmail: null}});
}

/**
* set the workspace reimbursement choice
* @param policyID
* @param reimbursementChoice
*/
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
function setReimbursementFromChoice(policyID: string, reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>) {
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
const policy = ReportUtils.getPolicy(policyID);

const currentPolicyReimbursementChoice = policy.reimbursementChoice;

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimbursementChoice,
errorFields: {reimbursementChoice: null},
pendingFields: {reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
},
];

const failureData: OnyxUpdate[] = [
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimbursementChoice: currentPolicyReimbursementChoice,
errorFields: {reimbursementChoice: ErrorUtils.getMicroSecondOnyxError('workflowsPage.genericErrorMessage.reimbursementChoice')},
pendingFields: {reimbursementChoice: null},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
errorFields: {reimbursementChoice: null},
pendingFields: {reimbursementChoice: null},
},
},
];

const params: SetReimbursementFromChoiceParams = {policyID, reimbursementChoice};

API.write(WRITE_COMMANDS.SET_REIMBURSEMENT_FROM_CHOICE, params, {optimisticData, failureData, successData});
}

/**
* Build optimistic data for removing users from the announcement room
*/
Expand Down Expand Up @@ -2536,4 +2646,7 @@ export {
setWorkspaceCategoryEnabled,
setWorkspaceRequiresCategory,
clearCategoryErrors,
setWorkspaceReimbursement,
clearWorkspaceReimbursementError,
setReimbursementFromChoice,
};
12 changes: 11 additions & 1 deletion src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const propTypes = {
/** A step to navigate to if we need to drop the user into a specific point in the flow */
stepToOpen: PropTypes.string,
policyID: PropTypes.string,
backTo: PropTypes.string,
}),
}),
};
Expand Down Expand Up @@ -252,6 +253,7 @@ function ReimbursementAccountPage({reimbursementAccount, route, onfidoToken, pol
const currentStep = achData.currentStep || CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
const policyName = lodashGet(policy, 'name', '');
const policyID = lodashGet(route.params, 'policyID', '');
const backTo = lodashGet(route.params, 'backTo');
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
Expand All @@ -275,10 +277,17 @@ function ReimbursementAccountPage({reimbursementAccount, route, onfidoToken, pol
BankAccounts.openReimbursementAccountPage(stepToOpen, subStep, ignoreLocalCurrentStep ? '' : localCurrentStep, policyID);
}

function shouldClearReimbursementAccount() {
return backTo !== ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID)
}

useEffect(
() => {
fetchData();
return () => {
if (!shouldClearReimbursementAccount()) {
return;
}
BankAccounts.clearReimbursementAccount();
};
},
Expand Down Expand Up @@ -337,9 +346,10 @@ function ReimbursementAccountPage({reimbursementAccount, route, onfidoToken, pol
BankAccounts.hideBankAccountErrors();
}

const backTo = lodashGet(route.params, 'backTo');
// eslint-disable-next-line no-shadow
const policyID = lodashGet(route.params, 'policyID');
// eslint-disable-next-line no-shadow
const backTo = lodashGet(route.params, 'backTo');

Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(getRouteForCurrentStep(currentStep), policyID, backTo));
},
Expand Down
Loading
Loading