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 all 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 @@ -497,6 +497,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 @@ -220,6 +220,7 @@ const SCREENS = {
TAGS_EDIT: 'Tags_Edit',
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
5 changes: 5 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,11 @@ export default {
},
},
},
workflowsPayerPage: {
title: 'Authorized payer',
genericErrorMessage: 'The authorized payer could not be changed. Please try again.',
admins: 'Admins',
},
reportFraudPage: {
title: 'Report virtual card fraud',
description: 'If your virtual card details have been stolen or compromised, we’ll permanently deactivate your existing card and provide you with a new virtual card and number.',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,11 @@ export default {
},
},
},
workflowsPayerPage: {
title: 'Pagador autorizado',
genericErrorMessage: 'El pagador autorizado no se pudo cambiar. Por favor, inténtalo mas tarde.',
admins: 'Administradores',
},
reportFraudPage: {
title: 'Reportar fraude con la tarjeta virtual',
description:
Expand Down
5 changes: 5 additions & 0 deletions src/libs/API/parameters/OpenPolicyWorkflowsPageParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OpenPolicyWorkflowsPageParams = {
policyID: string;
};

export default OpenPolicyWorkflowsPageParams;
6 changes: 6 additions & 0 deletions src/libs/API/parameters/SetWorkspacePayerParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type SetWorkspacePayerParams = {
policyID: string;
reimburserEmail: string;
};

export default SetWorkspacePayerParams;
9 changes: 9 additions & 0 deletions src/libs/API/parameters/SetWorkspaceReimbursementParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';

type SetWorkspaceReimbursementParams = {
policyID: string;
reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>;
};

export default SetWorkspaceReimbursementParams;
3 changes: 3 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ 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 SetWorkspacePayerParams} from './SetWorkspacePayerParams';
export type {default as SetWorkspaceReimbursementParams} from './SetWorkspaceReimbursementParams';
export type {default as SetPolicyRequiresTag} from './SetPolicyRequiresTag';
export type {default as RenamePolicyTaglist} from './RenamePolicyTaglist';
export type {default as SwitchToOldDotParams} from './SwitchToOldDotParams';
Expand All @@ -169,4 +171,5 @@ export type {default as EnablePolicyReportFieldsParams} from './EnablePolicyRepo
export type {default as AcceptJoinRequestParams} from './AcceptJoinRequest';
export type {default as DeclineJoinRequestParams} from './DeclineJoinRequest';
export type {default as JoinPolicyInviteLinkParams} from './JoinPolicyInviteLink';
export type {default as OpenPolicyWorkflowsPageParams} from './OpenPolicyWorkflowsPageParams';
export type {default as OpenPolicyDistanceRatesPageParams} from './OpenPolicyDistanceRatesPageParams';
6 changes: 6 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_PAYER: 'SetWorkspacePayer',
SET_WORKSPACE_REIMBURSEMENT: 'SetWorkspaceReimbursement',
DISMISS_REFERRAL_BANNER: 'DismissReferralBanner',
UPDATE_PREFERRED_LOCALE: 'UpdatePreferredLocale',
OPEN_APP: 'OpenApp',
Expand Down Expand Up @@ -325,6 +327,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_PAYER]: Parameters.SetWorkspacePayerParams;
[WRITE_COMMANDS.SET_WORKSPACE_REIMBURSEMENT]: Parameters.SetWorkspaceReimbursementParams;
[WRITE_COMMANDS.SWITCH_TO_OLD_DOT]: Parameters.SwitchToOldDotParams;
[WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES]: Parameters.EnablePolicyCategoriesParams;
[WRITE_COMMANDS.ENABLE_POLICY_CONNECTIONS]: Parameters.EnablePolicyConnectionsParams;
Expand Down Expand Up @@ -370,6 +374,7 @@ const READ_COMMANDS = {
OPEN_POLICY_TAGS_PAGE: 'OpenPolicyTagsPage',
OPEN_WORKSPACE_INVITE_PAGE: 'OpenWorkspaceInvitePage',
OPEN_DRAFT_WORKSPACE_REQUEST: 'OpenDraftWorkspaceRequest',
OPEN_POLICY_WORKFLOWS_PAGE: 'OpenPolicyWorkflowsPage',
OPEN_POLICY_DISTANCE_RATES_PAGE: 'OpenPolicyDistanceRatesPage',
} as const;

Expand Down Expand Up @@ -407,6 +412,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_POLICY_TAGS_PAGE]: Parameters.OpenPolicyTagsPageParams;
[READ_COMMANDS.OPEN_WORKSPACE_INVITE_PAGE]: Parameters.OpenWorkspaceInvitePageParams;
[READ_COMMANDS.OPEN_DRAFT_WORKSPACE_REQUEST]: Parameters.OpenDraftWorkspaceRequestParams;
[READ_COMMANDS.OPEN_POLICY_WORKFLOWS_PAGE]: Parameters.OpenPolicyWorkflowsPageParams;
[READ_COMMANDS.OPEN_POLICY_DISTANCE_RATES_PAGE]: Parameters.OpenPolicyDistanceRatesPageParams;
};

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,12 @@ 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.MEMBER_DETAILS, SCREENS.WORKSPACE.MEMBER_DETAILS_ROLE_SELECTION],
[SCREENS.WORKSPACE.WORKFLOWS]: [SCREENS.WORKSPACE.WORKFLOWS_APPROVER, SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY, SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET],
[SCREENS.WORKSPACE.WORKFLOWS]: [
SCREENS.WORKSPACE.WORKFLOWS_APPROVER,
SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY,
SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET,
SCREENS.WORKSPACE.WORKFLOWS_PAYER,
],
[SCREENS.WORKSPACE.TAGS]: [SCREENS.WORKSPACE.TAGS_SETTINGS, SCREENS.WORKSPACE.TAGS_EDIT],
[SCREENS.WORKSPACE.CATEGORIES]: [SCREENS.WORKSPACE.CATEGORY_CREATE, SCREENS.WORKSPACE.CATEGORY_SETTINGS, SCREENS.WORKSPACE.CATEGORIES_SETTINGS],
};
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,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.WORKSPACE.MEMBER_DETAILS]: {
path: ROUTES.WORKSPACE_MEMBER_DETAILS.route,
},
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ type SettingsNavigatorParamList = {
/** domain passed via route /settings/wallet/card/:domain */
domain: 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
152 changes: 152 additions & 0 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
OpenPolicyCategoriesPageParams,
OpenPolicyDistanceRatesPageParams,
OpenPolicyTagsPageParams,
OpenPolicyWorkflowsPageParams,
OpenWorkspaceInvitePageParams,
OpenWorkspaceMembersPageParams,
OpenWorkspaceParams,
Expand All @@ -34,6 +35,8 @@ import type {
SetWorkspaceAutoReportingFrequencyParams,
SetWorkspaceAutoReportingMonthlyOffsetParams,
SetWorkspaceAutoReportingParams,
SetWorkspacePayerParams,
SetWorkspaceReimbursementParams,
UpdateWorkspaceAvatarParams,
UpdateWorkspaceCustomUnitAndRateParams,
UpdateWorkspaceDescriptionParams,
Expand Down Expand Up @@ -589,6 +592,106 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
API.write(WRITE_COMMANDS.SET_WORKSPACE_APPROVAL_MODE, params, {optimisticData, failureData, successData});
}

function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburserAccountID: number) {
const policy = ReportUtils.getPolicy(policyID);

ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimburserEmail,
reimburserAccountID,
errorFields: {reimburserEmail: null},
pendingFields: {reimburserEmail: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
},
];

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

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

const params: SetWorkspacePayerParams = {policyID, reimburserEmail};

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

function clearWorkspacePayerError(policyID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {reimburserEmail: null}});
}

function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>, reimburserAccountID: number, reimburserEmail: string) {
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimbursementChoice,
reimburserAccountID,
reimburserEmail,
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
errorFields: {reimbursementChoice: null},
pendingFields: {reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
},
];

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

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

const params: SetWorkspaceReimbursementParams = {policyID, reimbursementChoice};

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

function clearWorkspaceReimbursementErrors(policyID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {reimbursementChoice: null}});
}

/**
* Build optimistic data for removing users from the announcement room
*/
Expand Down Expand Up @@ -1887,6 +1990,50 @@ function openWorkspaceReimburseView(policyID: string) {
API.read(READ_COMMANDS.OPEN_WORKSPACE_REIMBURSE_VIEW, params, {successData, failureData});
}

function openPolicyWorkflowsPage(policyID: string) {
if (!policyID) {
Log.warn('openPolicyWorkflowsPage invalid params', {policyID});
return;
}

const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${policyID}`,
value: {
isLoading: true,
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${policyID}`,
value: {
isLoading: false,
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
// @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM
key: `${ONYXKEYS.REIMBURSEMENT_ACCOUNT}${policyID}`,
value: {
isLoading: false,
},
},
],
};

const params: OpenPolicyWorkflowsPageParams = {policyID};

API.read(READ_COMMANDS.OPEN_POLICY_WORKFLOWS_PAGE, params, onyxData);
}

function setPolicyIDForReimburseView(policyID: string) {
Onyx.merge(ONYXKEYS.WORKSPACE_RATE_AND_UNIT, {policyID, rate: null, unit: null});
}
Expand Down Expand Up @@ -3292,6 +3439,10 @@ export {
declineJoinRequest,
createPolicyCategory,
clearCategoryErrors,
setWorkspacePayer,
clearWorkspacePayerError,
setWorkspaceReimbursement,
openPolicyWorkflowsPage,
setPolicyRequiresTag,
renamePolicyTaglist,
enablePolicyCategories,
Expand All @@ -3302,4 +3453,5 @@ export {
enablePolicyTaxes,
enablePolicyWorkflows,
openPolicyDistanceRatesPage,
clearWorkspaceReimbursementErrors,
};
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ 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');
const backTo = lodashGet(route.params, 'backTo');

Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(getRouteForCurrentStep(currentStep), policyID, backTo));
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
icon: Expensicons.Workflows,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.WORKFLOWS,
brickRoadIndicator: !isEmptyObject(policy?.errorFields?.reimburserEmail ?? {}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
});
}

Expand Down
7 changes: 6 additions & 1 deletion src/pages/workspace/WorkspacePageWithSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type WorkspacePageWithSectionsProps = WithPolicyAndFullscreenLoadingProps &
* taller header on desktop and different font of the title.
* */
icon?: IconAsset;

/** Whether the page is loading, example any other API call in progres */
isLoading?: boolean;
};

function fetchData(policyID: string, skipVBBACal?: boolean) {
Expand Down Expand Up @@ -110,12 +113,14 @@ function WorkspacePageWithSections({
shouldShowOfflineIndicatorInWideScreen = false,
shouldShowNonAdmin = false,
shouldShowNotFoundPage = false,
isLoading: isPageLoading = false,
}: WorkspacePageWithSectionsProps) {
const styles = useThemeStyles();
const policyID = route.params?.policyID ?? '';
useNetwork({onReconnect: () => fetchData(policyID, shouldSkipVBBACall)});

const isLoading = reimbursementAccount?.isLoading ?? true;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const isLoading = (reimbursementAccount?.isLoading || isPageLoading) ?? true;
const achState = reimbursementAccount?.achData?.state ?? '';
const isUsingECard = user?.isUsingExpensifyCard ?? false;
const hasVBA = achState === BankAccount.STATE.OPEN;
Expand Down
Loading
Loading