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

[Held requests] Clean up the hold/unhold logic #45151

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
948e1f7
fix hold/unhold logic
cdOut Jul 10, 2024
e43ffe0
fix lint errors
cdOut Jul 11, 2024
1384fe1
fix isPolicyAdmin not being properly implemented in ReportUtils check
cdOut Jul 19, 2024
94ae4d3
Merge branch 'main' into @cdOut/cleanup-hold-unhold
cdOut Jul 19, 2024
ade4976
fix prettier
cdOut Jul 19, 2024
c8dce56
fix lint errors after merge
cdOut Jul 19, 2024
c4289b4
clean up code
cdOut Jul 19, 2024
1259a4a
correct logic for hold/unhold for ContextMenu action
cdOut Jul 31, 2024
dbf2421
fix prettier
cdOut Jul 31, 2024
1238c05
Merge branch 'main' into @cdOut/cleanup-hold-unhold
cdOut Jul 31, 2024
7dba3b9
refactor code for latest main hold logic changes
cdOut Jul 31, 2024
6730a11
clean up context menu related components
cdOut Jul 31, 2024
e5c06b8
unify logic for when hold action is shown in report details and conte…
cdOut Jul 31, 2024
689662e
Merge branch 'main' into @cdOut/cleanup-hold-unhold
cdOut Jul 31, 2024
4e91940
remove unused comments
cdOut Jul 31, 2024
9c97c2c
fix can hold logic for IOUs and self-held expenses
cdOut Jul 31, 2024
522447f
Merge branch 'main' into @cdOut/cleanup-hold-unhold
cdOut Aug 1, 2024
3521502
Merge branch 'main' into @cdOut/cleanup-hold-unhold
cdOut Aug 5, 2024
9bbd7a7
fix isHoldCreator not working properly for money requests
cdOut Aug 9, 2024
07c607d
fix prettier
cdOut Aug 9, 2024
70691da
Merge branch 'main' into @cdOut/cleanup-hold-unhold
cdOut Aug 9, 2024
eee69cb
correct logic for non-IOU unhold author conditional
cdOut Aug 9, 2024
03e5b25
fix prettier and formatting
cdOut Aug 9, 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
5 changes: 3 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2823,12 +2823,13 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
const isApprover = isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && currentUserPersonalDetails?.accountID === moneyRequestReport?.managerID;
const isOnHold = TransactionUtils.isOnHold(transaction);
const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction);
const isClosed = isClosedReport(moneyRequestReport);

const canModifyStatus = !isTrackExpenseMoneyReport && (isPolicyAdmin || isActionOwner || isApprover);
const isDeletedParentAction = isEmptyObject(parentReportAction) || ReportActionsUtils.isDeletedAction(parentReportAction);

const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction;
const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus)) && !isScanning && !!transaction?.reimbursable;
const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentAction && !isClosed;
const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestIOU || canModifyStatus) && !isScanning && !!transaction?.reimbursable;
const canUnholdRequest = !!(canHoldOrUnholdRequest && isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus))) && !!transaction?.reimbursable;

return {canHoldRequest, canUnholdRequest};
Expand Down
17 changes: 11 additions & 6 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
// 2. MoneyReport case
if (caseID === CASES.MONEY_REPORT) {
if (!reportActions || !transactionThreadReport?.parentReportActionID) {
return null;
return undefined;
}
return reportActions.find((action) => action.reportActionID === transactionThreadReport.parentReportActionID);
}
Expand Down Expand Up @@ -512,9 +512,14 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? ''
: '';

const canHoldUnholdReportAction = ReportUtils.canHoldUnholdReportAction(parentReportAction);
const shouldShowHoldAction =
caseID !== CASES.MONEY_REPORT && (canHoldUnholdReportAction.canHoldRequest || canHoldUnholdReportAction.canUnholdRequest) && !ReportUtils.isArchivedRoom(parentReport);
let holdReportAction: OnyxTypes.ReportAction | undefined;
if (caseID === CASES.MONEY_REQUEST) {
holdReportAction = parentReportAction;
} else if (caseID === CASES.MONEY_REPORT) {
holdReportAction = requestParentReportAction;
}
const canHoldUnholdReportAction = ReportUtils.canHoldUnholdReportAction(holdReportAction);
const shouldShowHoldAction = (canHoldUnholdReportAction.canHoldRequest || canHoldUnholdReportAction.canUnholdRequest) && !ReportUtils.isArchivedRoom(parentReport);

const canJoin = ReportUtils.canJoinChat(report, parentReportAction, policy);

Expand All @@ -526,7 +531,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
}

if (isExpenseReport && shouldShowHoldAction) {
result.push(PromotedActions.hold({isTextHold: canHoldUnholdReportAction.canHoldRequest, reportAction: parentReportAction}));
result.push(PromotedActions.hold({isTextHold: canHoldUnholdReportAction.canHoldRequest, reportAction: holdReportAction}));
}

if (report) {
Expand All @@ -536,7 +541,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
result.push(PromotedActions.share(report));

return result;
}, [report, parentReportAction, canJoin, isExpenseReport, shouldShowHoldAction, canHoldUnholdReportAction.canHoldRequest]);
}, [report, holdReportAction, canJoin, isExpenseReport, shouldShowHoldAction, canHoldUnholdReportAction.canHoldRequest]);

const nameSectionExpenseIOU = (
<View style={[styles.reportDetailsRoomInfo, styles.mw100]}>
Expand Down
6 changes: 2 additions & 4 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ const ContextMenuActions: ContextMenuAction[] = [
isAnonymousAction: false,
textTranslateKey: 'iou.unholdExpense',
icon: Expensicons.Stopwatch,
shouldShow: (type, reportAction) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && ReportUtils.canHoldUnholdReportAction(reportAction).canUnholdRequest,
shouldShow: (type, reportAction) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canHoldUnholdReportAction(reportAction).canUnholdRequest,
onPress: (closePopover, {reportAction}) => {
if (closePopover) {
hideContextMenu(false, () => ReportUtils.changeMoneyRequestHoldStatus(reportAction));
Expand All @@ -277,8 +276,7 @@ const ContextMenuActions: ContextMenuAction[] = [
isAnonymousAction: false,
textTranslateKey: 'iou.hold',
icon: Expensicons.Stopwatch,
shouldShow: (type, reportAction) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && ReportUtils.canHoldUnholdReportAction(reportAction).canHoldRequest,
shouldShow: (type, reportAction) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canHoldUnholdReportAction(reportAction).canHoldRequest,
onPress: (closePopover, {reportAction}) => {
if (closePopover) {
hideContextMenu(false, () => ReportUtils.changeMoneyRequestHoldStatus(reportAction));
Expand Down
Loading