From 5ccc7fa0e24b19963e63e65cffbe7269343df734 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Tue, 26 Mar 2024 17:50:51 -0300 Subject: [PATCH 01/11] replaceing usage of reimburserEamil with achAccount.reimburser and removing reimburserAccountID --- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/Policy.ts | 16 ++++++---------- .../workflows/WorkspaceWorkflowsPage.tsx | 14 +++++--------- .../workflows/WorkspaceWorkflowsPayerPage.tsx | 11 +++++------ src/types/onyx/Policy.ts | 7 +------ 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0bb3b1101b7c..32a712e20ece 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1287,8 +1287,8 @@ function isPayer(session: OnyxEntry, iouReport: OnyxEntry) { const isManager = iouReport?.managerID === session?.accountID; if (isPaidGroupPolicy(iouReport)) { if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { - const isReimburser = session?.email === policy?.reimburserEmail; - return (!policy?.reimburserEmail || isReimburser) && (isApproved || isManager); + const isReimburser = session?.email === policy?.achAccount?.reimburser; + return (!policy?.achAccount?.reimburser || isReimburser) && (isApproved || isManager); } if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) { return isAdmin && (isApproved || isManager); diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 53f5c99c7ffb..d68ad8ed89b9 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -653,7 +653,7 @@ 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) { +function setWorkspacePayer(policyID: string, reimburserEmail: string) { const policy = ReportUtils.getPolicy(policyID); const optimisticData: OnyxUpdate[] = [ @@ -661,8 +661,7 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - reimburserEmail, - reimburserAccountID, + achAccount: {reimburser: reimburserEmail}, errorFields: {reimburserEmail: null}, pendingFields: {reimburserEmail: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, }, @@ -685,8 +684,7 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - reimburserEmail: policy.reimburserEmail ?? null, - reimburserAccountID: policy.reimburserAccountID ?? null, + achAccount: policy.achAccount ?? null, errorFields: {reimburserEmail: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')}, pendingFields: {reimburserEmail: null}, }, @@ -702,7 +700,7 @@ function clearPolicyErrorField(policyID: string, fieldName: string) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {[fieldName]: null}}); } -function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueOf, reimburserAccountID: number, reimburserEmail: string) { +function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueOf, reimburserEmail: string) { const policy = ReportUtils.getPolicy(policyID); const optimisticData: OnyxUpdate[] = [ @@ -711,8 +709,7 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { reimbursementChoice, - reimburserAccountID, - reimburserEmail, + achAccount: {reimburser: reimburserEmail}, errorFields: {reimbursementChoice: null}, pendingFields: {reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, }, @@ -736,8 +733,7 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { reimbursementChoice: policy.reimbursementChoice ?? null, - reimburserAccountID: policy.reimburserAccountID ?? null, - reimburserEmail: policy.reimburserEmail ?? null, + achAccount: policy.achAccount ?? null, errorFields: {reimbursementChoice: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')}, pendingFields: {reimbursementChoice: null}, }, diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 6b17cfc46400..09a305d7d668 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -55,10 +55,9 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); const displayNameForAuthorizedPayer = useMemo(() => { - const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([policy?.reimburserAccountID ?? 0], session?.accountID ?? 0); - const displayNameFromReimburserEmail = PersonalDetailsUtils.getPersonalDetailByEmail(policy?.reimburserEmail ?? '')?.displayName ?? policy?.reimburserEmail; - return displayNameFromReimburserEmail ?? personalDetails?.[0]?.displayName; - }, [policy?.reimburserAccountID, policy?.reimburserEmail, session?.accountID]); + const displayNameFromReimburserEmail = PersonalDetailsUtils.getPersonalDetailByEmail(policy?.achAccount?.reimburser ?? '')?.displayName ?? policy?.achAccount?.reimburser; + return displayNameFromReimburserEmail; + }, [policy?.achAccount?.reimburser, session?.accountID]); const onPressAutoReportingFrequency = useCallback(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY.getRoute(policy?.id ?? '')), [policy?.id]); @@ -171,11 +170,8 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl newReimbursementChoice = hasVBA ? CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES : CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL; } - const newReimburserAccountID = - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - PersonalDetailsUtils.getPersonalDetailByEmail(policy?.reimburserEmail ?? '')?.accountID || policy?.reimburserAccountID || policy?.ownerAccountID; - const newReimburserEmail = PersonalDetailsUtils.getPersonalDetailsByIDs([newReimburserAccountID ?? 0], session?.accountID ?? 0)?.[0]?.login; - Policy.setWorkspaceReimbursement(policy?.id ?? '', newReimbursementChoice, newReimburserAccountID ?? 0, newReimburserEmail ?? ''); + const newReimburserEmail = policy?.achAccount?.reimburser ?? policy?.owner; + Policy.setWorkspaceReimbursement(policy?.id ?? '', newReimbursementChoice, newReimburserEmail ?? ''); }, subMenuItems: ( <> diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx index 6da120f95766..751db16b17f6 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx @@ -87,7 +87,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta /> ); - const isAuthorizedPayer = policy?.reimburserEmail === details?.login ?? policy?.reimburserAccountID === accountID; + const isAuthorizedPayer = policy?.achAccount?.reimburser === details?.login; const formattedMember = { keyForList: accountIDKey, @@ -109,7 +109,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta pendingAction: policyMember.pendingAction ?? isAuthorizedPayer ? policy?.pendingFields?.reimburserEmail : null, }; - if (policy?.reimburserEmail === details?.login ?? policy?.reimburserAccountID === accountID) { + if (policy?.achAccount?.reimburser === details?.login) { authorizedPayerDetails.push(formattedMember); } else { policyAdminDetails.push(formattedMember); @@ -120,12 +120,11 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta personalDetails, policyMembers, translate, - policy?.reimburserEmail, + policy?.achAccount?.reimburser, isDeletedPolicyMember, policy?.owner, styles, StyleUtils, - policy?.reimburserAccountID, policy?.pendingFields?.reimburserEmail, ]); @@ -171,13 +170,13 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta const setPolicyAuthorizedPayer = (member: MemberOption) => { const authorizedPayerEmail = personalDetails?.[member.accountID]?.login ?? ''; - if (policy?.reimburserEmail === authorizedPayerEmail || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { + if (policy?.achAccount?.reimburser === authorizedPayerEmail || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { Navigation.goBack(); return; } const authorizedPayerAccountID = member.accountID; - Policy.setWorkspacePayer(policy?.id ?? '', authorizedPayerEmail, authorizedPayerAccountID); + Policy.setWorkspacePayer(policy?.id ?? '', authorizedPayerEmail); Navigation.goBack(); }; diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 398a0fe0dd28..386b6ff7d4e9 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -189,6 +189,7 @@ type ACHAccount = { routingNumber: string; addressName: string; bankName: string; + reimburser: string; }; type AutoReportingOffset = number | ValueOf; @@ -390,12 +391,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< /** Collection of tax rates attached to a policy */ taxRates?: TaxRatesWithDefault; - /** Email of the reimburser when reimbursement is set direct */ - reimburserEmail?: string; - - /** AccountID of the reimburser when reimbursement is set direct */ - reimburserAccountID?: number; - /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; From a6a427017d21f8fedf8dc1280c1287c745fcba54 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Tue, 26 Mar 2024 18:04:28 -0300 Subject: [PATCH 02/11] prettier --- .../workflows/WorkspaceWorkflowsPayerPage.tsx | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx index 751db16b17f6..a6c5fc61b546 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx @@ -116,17 +116,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta } }); return [policyAdminDetails, authorizedPayerDetails]; - }, [ - personalDetails, - policyMembers, - translate, - policy?.achAccount?.reimburser, - isDeletedPolicyMember, - policy?.owner, - styles, - StyleUtils, - policy?.pendingFields?.reimburserEmail, - ]); + }, [personalDetails, policyMembers, translate, policy?.achAccount?.reimburser, isDeletedPolicyMember, policy?.owner, styles, StyleUtils, policy?.pendingFields?.reimburserEmail]); const sections: MembersSection[] = useMemo(() => { const sectionsArray: MembersSection[] = []; From 3d3089eb4478fb6132d5eb93ffede6d8db1cb66b Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 27 Mar 2024 11:56:32 -0300 Subject: [PATCH 03/11] Fixing typecheck --- src/libs/actions/Policy.ts | 12 ++++++------ src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- .../workspace/workflows/WorkspaceWorkflowsPage.tsx | 4 ++-- .../workflows/WorkspaceWorkflowsPayerPage.tsx | 4 ++-- src/types/onyx/Policy.ts | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 1f4ea5105c10..6aa1e83a41bb 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -673,8 +673,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { achAccount: {reimburser: reimburserEmail}, - errorFields: {reimburserEmail: null}, - pendingFields: {reimburserEmail: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, + errorFields: {reimburser: null}, + pendingFields: {reimburser: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, }, }, ]; @@ -684,8 +684,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - errorFields: {reimburserEmail: null}, - pendingFields: {reimburserEmail: null}, + errorFields: {reimburser: null}, + pendingFields: {reimburser: null}, }, }, ]; @@ -696,8 +696,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { achAccount: policy.achAccount ?? null, - errorFields: {reimburserEmail: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')}, - pendingFields: {reimburserEmail: null}, + errorFields: {reimburser: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')}, + pendingFields: {reimburser: null}, }, }, ]; diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 0d3bb027b8e6..512b637f7f46 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -165,7 +165,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, + brickRoadIndicator: !isEmptyObject(policy?.errorFields?.reimburser ?? {}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, }); } diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 09a305d7d668..bb41a1ea421c 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -88,7 +88,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl if (accountNumber && bankDisplayName !== accountNumber) { bankDisplayName += ' ' + accountNumber.slice(-5); } - const hasReimburserEmailError = !!policy?.errorFields?.reimburserEmail; + const hasReimburserEmailError = !!policy?.errorFields?.reimburser; const hasApprovalError = !!policy?.errorFields?.approvalMode; const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting; @@ -197,7 +197,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl /> {hasVBA && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && ( Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.REIMBURSER_EMAIL)} errorRowStyles={[styles.ml7]} diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx index a6c5fc61b546..4aca7f8ae267 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx @@ -106,7 +106,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta }, ], errors: policyMember.errors, - pendingAction: policyMember.pendingAction ?? isAuthorizedPayer ? policy?.pendingFields?.reimburserEmail : null, + pendingAction: policyMember.pendingAction ?? isAuthorizedPayer ? policy?.pendingFields?.reimburser : null, }; if (policy?.achAccount?.reimburser === details?.login) { @@ -116,7 +116,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta } }); return [policyAdminDetails, authorizedPayerDetails]; - }, [personalDetails, policyMembers, translate, policy?.achAccount?.reimburser, isDeletedPolicyMember, policy?.owner, styles, StyleUtils, policy?.pendingFields?.reimburserEmail]); + }, [personalDetails, policyMembers, translate, policy?.achAccount?.reimburser, isDeletedPolicyMember, policy?.owner, styles, StyleUtils, policy?.pendingFields?.reimburser]); const sections: MembersSection[] = useMemo(() => { const sectionsArray: MembersSection[] = []; diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 386b6ff7d4e9..860891dba327 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -433,7 +433,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< /** Indicates if the Policy ownership change is failed */ isChangeOwnerFailed?: boolean; } & Partial, - 'generalSettings' | 'addWorkspaceRoom' + 'generalSettings' | 'addWorkspaceRoom' | keyof ACHAccount >; export default Policy; From a31342840868d56aece1b69b2c4a556814392f61 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 27 Mar 2024 12:10:10 -0300 Subject: [PATCH 04/11] removing unused variable --- src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx index 4aca7f8ae267..b52cbc8ffc79 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx @@ -165,7 +165,6 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta return; } - const authorizedPayerAccountID = member.accountID; Policy.setWorkspacePayer(policy?.id ?? '', authorizedPayerEmail); Navigation.goBack(); }; From dace40b44c5092277da54962146d0e6d9788690e Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 27 Mar 2024 12:37:48 -0300 Subject: [PATCH 05/11] removing unused sesseion.accountID from hooks --- src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index b83c30181beb..a6951363baf5 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -55,9 +55,8 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); const displayNameForAuthorizedPayer = useMemo(() => { - const displayNameFromReimburserEmail = PersonalDetailsUtils.getPersonalDetailByEmail(policy?.achAccount?.reimburser ?? '')?.displayName ?? policy?.achAccount?.reimburser; - return displayNameFromReimburserEmail; - }, [policy?.achAccount?.reimburser, session?.accountID]); + return PersonalDetailsUtils.getPersonalDetailByEmail(policy?.achAccount?.reimburser ?? '')?.displayName ?? policy?.achAccount?.reimburser; + }, [policy?.achAccount?.reimburser]); const onPressAutoReportingFrequency = useCallback(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY.getRoute(policy?.id ?? '')), [policy?.id]); @@ -235,7 +234,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl preferredLocale, canUseDelayedSubmission, displayNameForAuthorizedPayer, - session?.accountID, ]); const renderOptionItem = (item: ToggleSettingOptionRowProps, index: number) => ( From 654469ce6a2c5fa35ed8d3ff3788839789d5b588 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 27 Mar 2024 13:00:25 -0300 Subject: [PATCH 06/11] fixing lint --- src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index a6951363baf5..95058c7ee89d 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -43,7 +43,7 @@ type WorkspaceWorkflowsPageOnyxProps = { }; type WorkspaceWorkflowsPageProps = WithPolicyProps & WorkspaceWorkflowsPageOnyxProps & StackScreenProps; -function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkflowsPageProps) { +function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPageProps) { const {translate, preferredLocale} = useLocalize(); const styles = useThemeStyles(); const {isSmallScreenWidth} = useWindowDimensions(); @@ -54,9 +54,10 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl const canUseDelayedSubmission = Permissions.canUseWorkflowsDelayedSubmission(betas); const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); - const displayNameForAuthorizedPayer = useMemo(() => { - return PersonalDetailsUtils.getPersonalDetailByEmail(policy?.achAccount?.reimburser ?? '')?.displayName ?? policy?.achAccount?.reimburser; - }, [policy?.achAccount?.reimburser]); + const displayNameForAuthorizedPayer = useMemo( + () => PersonalDetailsUtils.getPersonalDetailByEmail(policy?.achAccount?.reimburser ?? '')?.displayName ?? policy?.achAccount?.reimburser, + [policy?.achAccount?.reimburser], + ); const onPressAutoReportingFrequency = useCallback(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY.getRoute(policy?.id ?? '')), [policy?.id]); From 2720c9874b4a402334df38921d4051d8e5836d66 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 27 Mar 2024 14:18:29 -0300 Subject: [PATCH 07/11] fixing lint --- src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 95058c7ee89d..9044e829f16d 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -38,8 +38,6 @@ import type {AutoReportingFrequencyKey} from './WorkspaceAutoReportingFrequencyP type WorkspaceWorkflowsPageOnyxProps = { /** Beta features list */ betas: OnyxEntry; - /** Policy details */ - session: OnyxEntry; }; type WorkspaceWorkflowsPageProps = WithPolicyProps & WorkspaceWorkflowsPageOnyxProps & StackScreenProps; @@ -311,8 +309,5 @@ export default withPolicy( betas: { key: ONYXKEYS.BETAS, }, - session: { - key: ONYXKEYS.SESSION, - }, })(WorkspaceWorkflowsPage), ); From f7c2a551970c8e50f401a77328b327f0df5f6513 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 27 Mar 2024 15:36:04 -0300 Subject: [PATCH 08/11] removing one last use of session --- src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 9044e829f16d..619cb4440b46 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -29,7 +29,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Beta, Session} from '@src/types/onyx'; +import type {Beta} from '@src/types/onyx'; import ToggleSettingOptionRow from './ToggleSettingsOptionRow'; import type {ToggleSettingOptionRowProps} from './ToggleSettingsOptionRow'; import {getAutoReportingFrequencyDisplayNames} from './WorkspaceAutoReportingFrequencyPage'; From 312acc7911cbc7f2d0f1b6034e0163d3736460cc Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Mon, 1 Apr 2024 13:34:47 -0300 Subject: [PATCH 09/11] Renaming collection keys contant from reimburserEmail to reimburser --- src/CONST.ts | 2 +- src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index c57ac575f7e6..fcb4df7c5749 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1518,7 +1518,7 @@ const CONST = { }, COLLECTION_KEYS: { DESCRIPTION: 'description', - REIMBURSER_EMAIL: 'reimburserEmail', + REIMBURSER: 'reimburser', REIMBURSEMENT_CHOICE: 'reimbursementChoice', APPROVAL_MODE: 'approvalMode', AUTOREPORTING: 'autoReporting', diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 8aa62d4a0011..18838f7af0ce 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -198,8 +198,8 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr {hasVBA && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && ( Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.REIMBURSER_EMAIL)} + errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.REIMBURSER)} + onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.REIMBURSER)} errorRowStyles={[styles.ml7]} > Date: Wed, 3 Apr 2024 09:03:48 -0300 Subject: [PATCH 10/11] Update src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx index b52cbc8ffc79..c7860bf8abce 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx @@ -109,7 +109,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta pendingAction: policyMember.pendingAction ?? isAuthorizedPayer ? policy?.pendingFields?.reimburser : null, }; - if (policy?.achAccount?.reimburser === details?.login) { + if (isAuthorizedPayer) { authorizedPayerDetails.push(formattedMember); } else { policyAdminDetails.push(formattedMember); From 522a7e8d3f4bf07e366fa8146f861bdde128be1f Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 3 Apr 2024 09:06:58 -0300 Subject: [PATCH 11/11] better handling for reimburser failure --- src/libs/actions/Policy.ts | 4 ++-- src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 10d9a5676adb..048d475def99 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -695,7 +695,7 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - achAccount: policy.achAccount ?? null, + achAccount: {reimburser: policy.achAccount?.reimburser ?? null}, errorFields: {reimburser: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')}, pendingFields: {reimburser: null}, }, @@ -744,7 +744,7 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { reimbursementChoice: policy.reimbursementChoice ?? null, - achAccount: policy.achAccount ?? null, + achAccount: {reimburser: policy.achAccount?.reimburser ?? null}, errorFields: {reimbursementChoice: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')}, pendingFields: {reimbursementChoice: null}, }, diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index 18838f7af0ce..8510b6fe4362 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -87,7 +87,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr if (accountNumber && bankDisplayName !== accountNumber) { bankDisplayName += ` ${accountNumber.slice(-5)}`; } - const hasReimburserEmailError = !!policy?.errorFields?.reimburser; + const hasReimburserError = !!policy?.errorFields?.reimburser; const hasApprovalError = !!policy?.errorFields?.approvalMode; const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting; @@ -211,7 +211,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr shouldShowRightIcon wrapperStyle={containerStyle} hoverAndPressStyle={[styles.mr0, styles.br2]} - brickRoadIndicator={hasReimburserEmailError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} + brickRoadIndicator={hasReimburserError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} /> )}