-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[NoQA] fix: display fallback x button to dismiss the transaction report in createChat error #72606
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
Changes from all commits
d5e8738
a7a3304
5c59987
57ced93
637c0ae
13239eb
8f3f917
0b1d8c9
d1d334d
d17b9da
adb9a27
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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ import useReportIsArchived from '@hooks/useReportIsArchived'; | |
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import useTransactionViolations from '@hooks/useTransactionViolations'; | ||
| import {isReceiptError} from '@libs/ErrorUtils'; | ||
| import {getMicroSecondOnyxErrorWithTranslationKey, isReceiptError} from '@libs/ErrorUtils'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils'; | ||
| import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils'; | ||
|
|
@@ -97,7 +97,7 @@ function MoneyRequestReceiptView({ | |
| }: MoneyRequestReceiptViewProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
| const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout(); | ||
| const {getReportRHPActiveRoute} = useActiveRoute(); | ||
| const parentReportID = report?.parentReportID; | ||
| const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`]; | ||
|
|
@@ -108,7 +108,6 @@ function MoneyRequestReceiptView({ | |
| }); | ||
|
|
||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| const parentReportAction = report?.parentReportActionID ? parentReportActions?.[report.parentReportActionID] : undefined; | ||
| const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(parentReportAction); | ||
| const isTrackExpense = isTrackExpenseReport(report); | ||
|
|
@@ -190,11 +189,15 @@ function MoneyRequestReceiptView({ | |
| !isTransactionScanning && (hasReceipt || !!receiptRequiredViolation || !!customRulesViolation) && !!(receiptViolations.length || didReceiptScanSucceed) && isPaidGroupPolicy(report); | ||
| const shouldShowReceiptAudit = !isInvoice && (shouldShowReceiptEmptyState || hasReceipt); | ||
|
|
||
| const errors = { | ||
| ...(transaction?.errorFields?.route ?? transaction?.errorFields?.waypoints ?? transaction?.errors), | ||
| ...parentReportAction?.errors, | ||
| }; | ||
|
|
||
| const errorsWithoutReportCreation = useMemo( | ||
| () => ({ | ||
| ...(transaction?.errorFields?.route ?? transaction?.errorFields?.waypoints ?? transaction?.errors), | ||
| ...parentReportAction?.errors, | ||
| }), | ||
| [transaction?.errorFields?.route, transaction?.errorFields?.waypoints, transaction?.errors, parentReportAction?.errors], | ||
| ); | ||
| const reportCreationError = useMemo(() => (getCreationReportErrors(report) ? getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage') : {}), [report]); | ||
| const errors = useMemo(() => ({...errorsWithoutReportCreation, ...reportCreationError}), [errorsWithoutReportCreation, reportCreationError]); | ||
| const showReceiptErrorWithEmptyState = shouldShowReceiptEmptyState && !hasReceipt && !isEmptyObject(errors); | ||
|
|
||
| const [showConfirmDismissReceiptError, setShowConfirmDismissReceiptError] = useState(false); | ||
|
|
@@ -221,10 +224,30 @@ function MoneyRequestReceiptView({ | |
| clearAllRelatedReportActionErrors(report.reportID, parentReportAction); | ||
| return; | ||
| } | ||
| revert(transaction, getLastModifiedExpense(report?.reportID)); | ||
| clearError(transaction.transactionID); | ||
| clearAllRelatedReportActionErrors(report.reportID, parentReportAction); | ||
| }, [transaction, chatReport, parentReportAction, linkedTransactionID, report?.reportID, iouReport, chatIOUReport, isChatIOUReportArchived]); | ||
| if (!isEmptyObject(errorsWithoutReportCreation)) { | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| revert(transaction, getLastModifiedExpense(report?.reportID)); | ||
| clearError(transaction.transactionID); | ||
| clearAllRelatedReportActionErrors(report.reportID, parentReportAction); | ||
| } | ||
| if (!isEmptyObject(reportCreationError)) { | ||
| if (isInNarrowPaneModal) { | ||
| Navigation.goBack(); | ||
| } | ||
| navigateToConciergeChatAndDeleteReport(report.reportID, true, true); | ||
| } | ||
| }, [ | ||
| transaction, | ||
| chatReport, | ||
| parentReportAction, | ||
| linkedTransactionID, | ||
| report?.reportID, | ||
| iouReport, | ||
| chatIOUReport, | ||
| isChatIOUReportArchived, | ||
|
Contributor
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. ❌ PERF-6 (docs)The Suggested fix: const dismissReceiptError = useCallback(() => {
// ... function body
}, [
transaction?.transactionID,
transaction?.pendingAction,
chatReport?.reportID,
parentReportAction, // May need to break down further if only specific properties are used
linkedTransactionID,
report?.reportID,
iouReport, // May need to break down further
chatIOUReport, // May need to break down further
isChatIOUReportArchived,
errorsWithoutReportCreation,
reportCreationError,
isInNarrowPaneModal,
]); |
||
| errorsWithoutReportCreation, | ||
| reportCreationError, | ||
| isInNarrowPaneModal, | ||
| ]); | ||
|
|
||
| let receiptStyle: StyleProp<ViewStyle>; | ||
|
|
||
|
|
||
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.
❌ PERF-6 (docs)
Passing the entire
reportobject as a dependency causes thisuseMemoto re-execute whenever any property ofreportchanges. The function only usesgetCreationReportErrors(report), so you should depend on the specific properties thatgetCreationReportErrorsactually checks.Suggested fix:
If
getCreationReportErrorschecks specific properties likereport.errorFieldsor similar, use those: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.
Not much we can do about this one as the method expects full report cc @kacper-mikolajczak