From 021d61eff89b0231ee8c0cd0a04245fdea373879 Mon Sep 17 00:00:00 2001 From: Anusha Date: Fri, 13 Sep 2024 02:22:02 +0500 Subject: [PATCH 01/10] fix invoice category --- src/libs/ReportUtils.ts | 1 + src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0e7418a306a..5245d96378b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -458,6 +458,7 @@ type OptionData = { tabIndex?: 0 | -1; isConciergeChat?: boolean; isBold?: boolean; + isSender?: boolean; } & Report; type OnyxDataTaskAssigneeChat = { diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 6c1457abef6..5db903a2d90 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -168,6 +168,10 @@ function IOURequestStepConfirmation({ if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(policyExpenseChat.policyID); } + const isSender = participants?.find((participant) => participant.isSender); + if (isSender?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { + openDraftWorkspaceRequest(isSender.policyID); + } }, [isOffline, participants, transaction?.billable, policy, transactionID]); const defaultBillable = !!policy?.defaultBillable; From fc706e9c6c082137fdc0c9bf80f9de445efec5b2 Mon Sep 17 00:00:00 2001 From: Anusha <93134676+Nodebrute@users.noreply.github.com> Date: Mon, 16 Sep 2024 02:57:19 +0500 Subject: [PATCH 02/10] Update src/pages/iou/request/step/IOURequestStepConfirmation.tsx Co-authored-by: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 5db903a2d90..c91a897e66b 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -168,7 +168,7 @@ function IOURequestStepConfirmation({ if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(policyExpenseChat.policyID); } - const isSender = participants?.find((participant) => participant.isSender); + const senderPolicyParticipant = participants?.find((participant) => participant.isSender); if (isSender?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(isSender.policyID); } From d4007d43d6eea41f7ec6bb9da85a33bcbff7fcd7 Mon Sep 17 00:00:00 2001 From: Anusha <93134676+Nodebrute@users.noreply.github.com> Date: Mon, 16 Sep 2024 02:57:26 +0500 Subject: [PATCH 03/10] Update src/pages/iou/request/step/IOURequestStepConfirmation.tsx Co-authored-by: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index c91a897e66b..7e31e9bfe29 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -169,7 +169,7 @@ function IOURequestStepConfirmation({ openDraftWorkspaceRequest(policyExpenseChat.policyID); } const senderPolicyParticipant = participants?.find((participant) => participant.isSender); - if (isSender?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { + if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(isSender.policyID); } }, [isOffline, participants, transaction?.billable, policy, transactionID]); From 6d9836a677720a9e8839b4aaa3474aa12abde7c5 Mon Sep 17 00:00:00 2001 From: Anusha <93134676+Nodebrute@users.noreply.github.com> Date: Mon, 16 Sep 2024 02:57:41 +0500 Subject: [PATCH 04/10] Update src/pages/iou/request/step/IOURequestStepConfirmation.tsx Co-authored-by: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 7e31e9bfe29..e852a980473 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -170,7 +170,7 @@ function IOURequestStepConfirmation({ } const senderPolicyParticipant = participants?.find((participant) => participant.isSender); if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { - openDraftWorkspaceRequest(isSender.policyID); + openDraftWorkspaceRequest(senderPolicyParticipant.policyID); } }, [isOffline, participants, transaction?.billable, policy, transactionID]); From 63f8dc37b9bff91704a5280e73c13ab6b2506722 Mon Sep 17 00:00:00 2001 From: Anusha Date: Mon, 16 Sep 2024 05:19:07 +0500 Subject: [PATCH 05/10] fix dependancy --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e852a980473..d3899f828d4 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -172,7 +172,7 @@ function IOURequestStepConfirmation({ if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(senderPolicyParticipant.policyID); } - }, [isOffline, participants, transaction?.billable, policy, transactionID]); + }, [isOffline, participants, policy?.pendingAction]); const defaultBillable = !!policy?.defaultBillable; useEffect(() => { From 88b3289ff361630e1af4a640f4f779c93791d8cb Mon Sep 17 00:00:00 2001 From: Anusha Date: Mon, 16 Sep 2024 05:36:42 +0500 Subject: [PATCH 06/10] add transaction?.billable --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index d3899f828d4..5d9f090c907 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -172,7 +172,7 @@ function IOURequestStepConfirmation({ if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(senderPolicyParticipant.policyID); } - }, [isOffline, participants, policy?.pendingAction]); + }, [isOffline, participants, policy?.pendingAction, transaction?.billable]); const defaultBillable = !!policy?.defaultBillable; useEffect(() => { From 7cd4281e699b923685377b2d4addb7231a58fd8d Mon Sep 17 00:00:00 2001 From: Anusha Date: Mon, 16 Sep 2024 05:40:48 +0500 Subject: [PATCH 07/10] fix useeffect dependancy --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 5d9f090c907..d3899f828d4 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -172,7 +172,7 @@ function IOURequestStepConfirmation({ if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(senderPolicyParticipant.policyID); } - }, [isOffline, participants, policy?.pendingAction, transaction?.billable]); + }, [isOffline, participants, policy?.pendingAction]); const defaultBillable = !!policy?.defaultBillable; useEffect(() => { From 8616749fec22d7f9e6a1042c05262d36267e7313 Mon Sep 17 00:00:00 2001 From: Anusha Date: Thu, 19 Sep 2024 07:04:35 +0500 Subject: [PATCH 08/10] fix isSender type --- src/libs/ReportUtils.ts | 1 - src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 607f48ce715..79948d51bcd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -458,7 +458,6 @@ type OptionData = { tabIndex?: 0 | -1; isConciergeChat?: boolean; isBold?: boolean; - isSender?: boolean; } & Report; type OnyxDataTaskAssigneeChat = { diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index d3899f828d4..31c3fc69996 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -168,7 +168,7 @@ function IOURequestStepConfirmation({ if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(policyExpenseChat.policyID); } - const senderPolicyParticipant = participants?.find((participant) => participant.isSender); + const senderPolicyParticipant = participants?.find((participant) => !!participant && 'isSender' in participant && participant.isSender); if (senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { openDraftWorkspaceRequest(senderPolicyParticipant.policyID); } From 68e75a0031280953121dbebd2a3126aa6f863a00 Mon Sep 17 00:00:00 2001 From: Anusha Date: Tue, 24 Sep 2024 22:16:11 +0500 Subject: [PATCH 09/10] migrate to useOnyx --- .../step/IOURequestStepConfirmation.tsx | 52 ++++--------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 31c3fc69996..bf618aa8742 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -1,7 +1,7 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -41,33 +41,10 @@ import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; -type IOURequestStepConfirmationOnyxProps = { - /** The policy of the report */ - policy: OnyxEntry; - - /** The draft policy of the report */ - policyDraft: OnyxEntry; - - /** The category configuration of the report's policy */ - policyCategories: OnyxEntry; - - /** The draft category configuration of the report's policy */ - policyCategoriesDraft: OnyxEntry; - - /** The tag configuration of the report's policy */ - policyTags: OnyxEntry; -}; - -type IOURequestStepConfirmationProps = IOURequestStepConfirmationOnyxProps & - WithWritableReportOrNotFoundProps & +type IOURequestStepConfirmationProps = WithWritableReportOrNotFoundProps & WithFullTransactionOrNotFoundProps; function IOURequestStepConfirmation({ - policy: policyReal, - policyDraft, - policyTags, - policyCategories: policyCategoriesReal, - policyCategoriesDraft, report: reportReal, reportDraft, route: { @@ -78,6 +55,12 @@ function IOURequestStepConfirmation({ const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; + const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`); + const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, reportReal)}`); + const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, reportReal)}`); + const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`); + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${IOU.getIOURequestPolicyID(transaction, reportReal)}`); + const report = reportReal ?? reportDraft; const policy = policyReal ?? policyDraft; const policyCategories = policyCategoriesReal ?? policyCategoriesDraft; @@ -664,25 +647,8 @@ function IOURequestStepConfirmation({ IOURequestStepConfirmation.displayName = 'IOURequestStepConfirmation'; -const IOURequestStepConfirmationWithOnyx = withOnyx({ - policy: { - key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, report)}`, - }, - policyDraft: { - key: ({reportDraft, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`, - }, - policyCategories: { - key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, report)}`, - }, - policyCategoriesDraft: { - key: ({reportDraft, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`, - }, - policyTags: { - key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${IOU.getIOURequestPolicyID(transaction, report)}`, - }, -})(IOURequestStepConfirmation); /* eslint-disable rulesdir/no-negated-variables */ -const IOURequestStepConfirmationWithFullTransactionOrNotFound = withFullTransactionOrNotFound(IOURequestStepConfirmationWithOnyx); +const IOURequestStepConfirmationWithFullTransactionOrNotFound = withFullTransactionOrNotFound(IOURequestStepConfirmation); /* eslint-disable rulesdir/no-negated-variables */ const IOURequestStepConfirmationWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepConfirmationWithFullTransactionOrNotFound); export default IOURequestStepConfirmationWithWritableReportOrNotFound; From cffd880df2d8d545675b9ea46f116704510c9e91 Mon Sep 17 00:00:00 2001 From: Anusha Date: Tue, 24 Sep 2024 22:22:56 +0500 Subject: [PATCH 10/10] fix lint errors --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index bf618aa8742..b08f9a6ced5 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -32,7 +32,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Policy, PolicyCategories, PolicyTagLists} from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type {Receipt} from '@src/types/onyx/Transaction';