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

fix invoice category #49142

Merged
merged 14 commits into from
Sep 25, 2024
1 change: 1 addition & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ type OptionData = {
tabIndex?: 0 | -1;
isConciergeChat?: boolean;
isBold?: boolean;
isSender?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

This property is not used, let's remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we remove this property, we get a type error 'isSender' does not exist on type 'OptionData | Participant'. Property 'isSender' does not exist on type 'OptionData'.

Copy link
Contributor

@rayane-djouah rayane-djouah Sep 17, 2024

Choose a reason for hiding this comment

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

@Nodebrute Let's update the condition to:

const senderPolicyParticipant = participants?.find((participant) => !!participant && 'isSender' in participant && participant.isSender);

and remove isSender property from OptionData type.

} & Report;

type OnyxDataTaskAssigneeChat = {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const isSender = participants?.find((participant) => participant.isSender);
const senderPolicyParticipant = participants?.find((participant) => participant.isSender);

Nodebrute marked this conversation as resolved.
Show resolved Hide resolved
if (isSender?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
Nodebrute marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I've noticed that when we change the invoice sender policy, the effect runs twice because the participants change and then the policy changes. This causes the API request to run twice. To prevent this, we need to add a check to ensure the API is called only once:

Suggested change
if (isSender?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
if (senderPolicyParticipant?.policyID && policy?.id === senderPolicyParticipant?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @rayane-djouah, Even on the latest main branch, the effect runs three times and the API is called three times when we use submit expense flow.

Screen.Recording.2024-09-16.at.3.00.24.AM.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

@Nodebrute I believe this is a bug. We only need to call the API once when the policy changes, so isOffline, participants, and policy?.pendingAction should be the only necessary useEffect dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rayane-djouah With the recent changes, I tested it again, and it’s working fine now.

openDraftWorkspaceRequest(isSender.policyID);
Nodebrute marked this conversation as resolved.
Show resolved Hide resolved
}
}, [isOffline, participants, transaction?.billable, policy, transactionID]);

const defaultBillable = !!policy?.defaultBillable;
Expand Down
Loading