-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[CP Staging] Expense - No option to cancel payment for paid expense as 3-dot menu is removed #45130
Changes from all commits
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 |
---|---|---|
|
@@ -109,6 +109,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |
const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false); | ||
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); | ||
const [isUnapproveModalVisible, setIsUnapproveModalVisible] = useState(false); | ||
const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); | ||
const policy = useMemo(() => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`], [policies, report?.policyID]); | ||
const isPolicyAdmin = useMemo(() => PolicyUtils.isPolicyAdmin(policy), [policy]); | ||
const isPolicyEmployee = useMemo(() => PolicyUtils.isPolicyEmployee(report?.policyID ?? '-1', policies), [report?.policyID, policies]); | ||
|
@@ -263,6 +264,21 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |
const shouldShowWriteCapability = !isMoneyRequestReport; | ||
const shouldShowMenuItem = shouldShowNotificationPref || shouldShowWriteCapability || (!!report?.visibility && report.chatType !== CONST.REPORT.CHAT_TYPE.INVOICE); | ||
|
||
const isPayer = ReportUtils.isPayer(session, moneyRequestReport); | ||
const isSettled = ReportUtils.isSettled(moneyRequestReport?.reportID ?? '-1'); | ||
|
||
const shouldShowCancelPaymentButton = caseID === CASES.MONEY_REPORT && isPayer && isSettled && ReportUtils.isExpenseReport(moneyRequestReport); | ||
Comment on lines
+267
to
+270
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. Should we make a utility function out of this? 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. Also, why are we adding this extra check here? This did not exist in the 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 don't think that is necessary, this is done in the same way as This is also the only place where the payment cancellation use-case gets called. 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. Again, the extra check is due to |
||
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID ?? '-1'}`); | ||
|
||
const cancelPayment = useCallback(() => { | ||
if (!chatReport) { | ||
return; | ||
} | ||
|
||
IOU.cancelPayment(moneyRequestReport, chatReport); | ||
setIsConfirmModalVisible(false); | ||
}, [moneyRequestReport, chatReport]); | ||
|
||
const menuItems: ReportDetailsPageMenuItem[] = useMemo(() => { | ||
const items: ReportDetailsPageMenuItem[] = []; | ||
|
||
|
@@ -356,6 +372,16 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |
} | ||
} | ||
|
||
if (shouldShowCancelPaymentButton) { | ||
items.push({ | ||
key: CONST.REPORT_DETAILS_MENU_ITEM.CANCEL_PAYMENT, | ||
icon: Expensicons.Trashcan, | ||
translationKey: 'iou.cancelPayment', | ||
isAnonymousAction: false, | ||
action: () => setIsConfirmModalVisible(true), | ||
}); | ||
} | ||
|
||
if (shouldShowLeaveButton) { | ||
items.push({ | ||
key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM, | ||
|
@@ -403,6 +429,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |
isCanceledTaskReport, | ||
shouldShowLeaveButton, | ||
activeChatMembers.length, | ||
shouldShowCancelPaymentButton, | ||
isPolicyAdmin, | ||
session, | ||
leaveChat, | ||
|
@@ -710,6 +737,17 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |
confirmText={translate('common.leave')} | ||
cancelText={translate('common.cancel')} | ||
/> | ||
<ConfirmModal | ||
title={translate('iou.cancelPayment')} | ||
isVisible={isConfirmModalVisible} | ||
onConfirm={cancelPayment} | ||
onCancel={() => setIsConfirmModalVisible(false)} | ||
prompt={translate('iou.cancelPaymentConfirmation')} | ||
confirmText={translate('iou.cancelPayment')} | ||
cancelText={translate('common.dismiss')} | ||
danger | ||
shouldEnableNewFocusManagement | ||
/> | ||
<ConfirmModal | ||
title={caseID === CASES.DEFAULT ? translate('task.deleteTask') : translate('iou.deleteExpense')} | ||
isVisible={isDeleteModalVisible} | ||
|
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 wonder if we need this default really
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.
This might be obsolete but I wanted to add it as an extra percussion to make sure this doesn't cause a crash anytime in the app.