-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat: [Held requests] option does not show in the preview overflow menu. #42034
Changes from all commits
be5bcfa
2e36d00
d8fc20b
9f330e4
0fac245
3b2e151
ed98b40
051180b
7946f0c
f33575d
2df4f55
721e407
41276b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2404,6 +2404,14 @@ function isReportFieldOfTypeTitle(reportField: OnyxEntry<PolicyReportField>): bo | |
return reportField?.type === 'formula' && reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID; | ||
} | ||
|
||
/** | ||
* Check if Report has any held expenses | ||
*/ | ||
function isHoldCreator(transaction: OnyxEntry<Transaction>, reportID: string): boolean { | ||
const holdReportAction = ReportActionsUtils.getReportAction(reportID, `${transaction?.comment?.hold ?? ''}`); | ||
return isActionCreator(holdReportAction); | ||
} | ||
|
||
/** | ||
* Check if report fields are available to use in a report | ||
*/ | ||
|
@@ -2721,6 +2729,71 @@ function canEditReportAction(reportAction: OnyxEntry<ReportAction>): boolean { | |
); | ||
} | ||
|
||
function canHoldUnholdReportAction(reportAction: OnyxEntry<ReportAction>): {canHoldRequest: boolean; canUnholdRequest: boolean} { | ||
if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { | ||
return {canHoldRequest: false, canUnholdRequest: false}; | ||
} | ||
|
||
const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0; | ||
const moneyRequestReport = getReport(String(moneyRequestReportID)); | ||
|
||
if (!moneyRequestReportID || !moneyRequestReport) { | ||
return {canHoldRequest: false, canUnholdRequest: false}; | ||
} | ||
|
||
const isRequestSettled = isSettled(moneyRequestReport?.reportID); | ||
const isApproved = isReportApproved(moneyRequestReport); | ||
const transactionID = moneyRequestReport ? reportAction?.originalMessage?.IOUTransactionID : 0; | ||
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); | ||
|
||
const parentReport = getReport(String(moneyRequestReport.parentReportID)); | ||
const parentReportAction = ReportActionsUtils.getParentReportAction(moneyRequestReport); | ||
|
||
const isRequestIOU = parentReport?.type === 'iou'; | ||
const isRequestHoldCreator = isHoldCreator(transaction, moneyRequestReport?.reportID) && isRequestIOU; | ||
const isTrackExpenseMoneyReport = isTrackExpenseReport(moneyRequestReport); | ||
const isActionOwner = | ||
typeof parentReportAction?.actorAccountID === 'number' && | ||
typeof currentUserPersonalDetails?.accountID === 'number' && | ||
parentReportAction.actorAccountID === currentUserPersonalDetails?.accountID; | ||
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 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; | ||
const canUnholdRequest = !!(canHoldOrUnholdRequest && isOnHold && (isRequestHoldCreator || (!isRequestIOU && canModifyStatus))); | ||
|
||
return {canHoldRequest, canUnholdRequest}; | ||
} | ||
|
||
const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>): void => { | ||
if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { | ||
return; | ||
} | ||
const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0; | ||
|
||
const moneyRequestReport = getReport(String(moneyRequestReportID)); | ||
if (!moneyRequestReportID || !moneyRequestReport) { | ||
return; | ||
} | ||
|
||
const transactionID = reportAction?.originalMessage?.IOUTransactionID ?? ''; | ||
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); | ||
const isOnHold = TransactionUtils.isOnHold(transaction); | ||
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; | ||
|
||
if (isOnHold) { | ||
IOU.unholdRequest(transactionID, reportAction.childReportID ?? ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In here, you updated the hold expense with its There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems that we will need BE changes here cc @robertjchen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hungvu193, thanks a lot for looking into this, I agree with you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, so the backend should also push updates for the parent report here, is that correct? Could you let me know which particular field changes in the parent report that makes the update from the backend necessary? 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, we can investigate- can this PR go out ahead of the backend changes or is it blocked until that field is available? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can go ahead with this PR first, but let's leave a note for QA team that the issue about counting replies will be fixed once BE PR is deployed. |
||
} else { | ||
const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); | ||
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', activeRoute)); | ||
} | ||
}; | ||
|
||
/** | ||
* Gets all transactions on an IOU report with a receipt | ||
*/ | ||
|
@@ -6386,14 +6459,6 @@ function navigateToPrivateNotes(report: OnyxEntry<Report>, session: OnyxEntry<Se | |
Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); | ||
} | ||
|
||
/** | ||
* Check if Report has any held expenses | ||
*/ | ||
function isHoldCreator(transaction: OnyxEntry<Transaction>, reportID: string): boolean { | ||
const holdReportAction = ReportActionsUtils.getReportAction(reportID, `${transaction?.comment?.hold ?? ''}`); | ||
return isActionCreator(holdReportAction); | ||
} | ||
|
||
/** | ||
* Get all held transactions of a iouReport | ||
*/ | ||
|
@@ -6905,6 +6970,7 @@ export { | |
canCreateTaskInReport, | ||
canCurrentUserOpenReport, | ||
canDeleteReportAction, | ||
canHoldUnholdReportAction, | ||
canEditFieldOfMoneyRequest, | ||
canEditMoneyRequest, | ||
canEditPolicyDescription, | ||
|
@@ -7132,6 +7198,7 @@ export { | |
shouldShowMerchantColumn, | ||
isCurrentUserInvoiceReceiver, | ||
isDraftReport, | ||
changeMoneyRequestHoldStatus, | ||
createDraftWorkspaceAndNavigateToConfirmationScreen, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge these 2 conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think thats fine,
reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU
check is required before definingmoneyRequestReport
ormoneyRequestReportID
.