Skip to content

Commit

Permalink
Merge pull request #35456 from dukenv0307/fix/34819
Browse files Browse the repository at this point in the history
Grey out report preview and IOU report's header when paying request offline
  • Loading branch information
iwiznia authored Feb 8, 2024
2 parents 342da2e + 236b89d commit ad3d78c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ type ReportRouteParams = {
};

type ReportOfflinePendingActionAndErrors = {
addWorkspaceRoomOrChatPendingAction: PendingAction | undefined;
addWorkspaceRoomOrChatErrors: Errors | null | undefined;
reportPendingAction: PendingAction | undefined;
reportErrors: Errors | null | undefined;
};

type OptimisticApprovedReportAction = Pick<
Expand Down Expand Up @@ -4244,14 +4244,20 @@ function getOriginalReportID(reportID: string, reportAction: OnyxEntry<ReportAct
}

/**
* Return the pendingAction and the errors we have when creating a chat or a workspace room offline
* Return the pendingAction and the errors resulting from either
*
* - creating a workspace room
* - starting a chat
* - paying the money request
*
* while being offline
*/
function getReportOfflinePendingActionAndErrors(report: OnyxEntry<Report>): ReportOfflinePendingActionAndErrors {
// We are either adding a workspace room, or we're creating a chat, it isn't possible for both of these to be pending, or to have errors for the same report at the same time, so
// simply looking up the first truthy value for each case will get the relevant property if it's set.
const addWorkspaceRoomOrChatPendingAction = report?.pendingFields?.addWorkspaceRoom ?? report?.pendingFields?.createChat;
const addWorkspaceRoomOrChatErrors = getAddWorkspaceRoomOrChatReportErrors(report);
return {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors};
// It shouldn't be possible for all of these actions to be pending (or to have errors) for the same report at the same time, so just take the first that exists
const reportPendingAction = report?.pendingFields?.addWorkspaceRoom ?? report?.pendingFields?.createChat ?? report?.pendingFields?.reimbursed;

const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report);
return {reportPendingAction, reportErrors};
}

function getPolicyExpenseChatReportIDByOwner(policyOwner: string): string | null {
Expand Down
14 changes: 14 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3163,6 +3163,10 @@ function getPayMoneyRequestParams(chatReport: OnyxTypes.Report, iouReport: OnyxT
lastMessageHtml: optimisticIOUReportAction.message?.[0].html,
hasOutstandingChildRequest: false,
statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
pendingFields: {
preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
reimbursed: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
{
Expand All @@ -3182,6 +3186,16 @@ function getPayMoneyRequestParams(chatReport: OnyxTypes.Report, iouReport: OnyxT
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
value: {
pendingFields: {
preview: null,
reimbursed: null,
},
},
},
];

const failureData: OnyxUpdate[] = [
Expand Down
8 changes: 4 additions & 4 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function ReportScreen({
}

const reportID = getReportID(route);
const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report);
const {reportPendingAction, reportErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report);
const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}];
const isEmptyChat = useMemo(() => _.isEmpty(reportActions), [reportActions]);
// There are no reportActions at all to display and we are still in the process of loading the next set of actions.
Expand Down Expand Up @@ -521,8 +521,8 @@ function ReportScreen({
shouldShowLink={false}
>
<OfflineWithFeedback
pendingAction={addWorkspaceRoomOrChatPendingAction}
errors={addWorkspaceRoomOrChatErrors}
pendingAction={reportPendingAction}
errors={reportErrors}
shouldShowErrorMessages={false}
needsOffscreenAlphaCompositing
>
Expand Down Expand Up @@ -572,7 +572,7 @@ function ReportScreen({
{isReportReadyForDisplay ? (
<ReportFooter
report={report}
pendingAction={addWorkspaceRoomOrChatPendingAction}
pendingAction={reportPendingAction}
isComposerFullSize={isComposerFullSize}
listHeight={listHeight}
isEmptyChat={isEmptyChat}
Expand Down

0 comments on commit ad3d78c

Please sign in to comment.