-
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
fix: Closing receipt view using device navigation redirects user to expense report #35497
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6144f13
fix: Closing receipt view using device navigation redirects user to e…
tienifr 2483bfb
update canEditReceipt
tienifr 2fda1ad
resolve conflict
tienifr 52883ff
add fallback value
tienifr 9a31934
resolve conflict
tienifr 0c8a977
remove linkingConfig gile
tienifr f28a3d4
show loading indicator when data is not loaded yet
tienifr a96b14d
show notfound page
tienifr 7de3fc1
resolve conflict
tienifr 5bb6c80
lint fix
tienifr 4a0b807
fix conflicts
tienifr 767dbbb
Merge branch 'main' into fix/33549
tienifr 9011c0f
resolve conflicts
tienifr 723d427
refactor
tienifr 4c53d2d
fix conflicts
tienifr 644b4ff
fix dismiss modal
tienifr e231af8
fix: typecheck
tienifr 96f90f0
change props order
tienifr c2006ab
change filename order
tienifr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React, {useEffect} from 'react'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import AttachmentModal from '@components/AttachmentModal'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {AuthScreensParamList} from '@libs/Navigation/types'; | ||
import * as ReceiptUtils from '@libs/ReceiptUtils'; | ||
import * as ReportActionUtils from '@libs/ReportActionsUtils'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import * as TransactionUtils from '@libs/TransactionUtils'; | ||
import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; | ||
import * as ReportActions from '@userActions/Report'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type {Report, ReportMetadata, Transaction} from '@src/types/onyx'; | ||
|
||
type TransactionReceiptOnyxProps = { | ||
report: OnyxEntry<Report>; | ||
transaction: OnyxEntry<Transaction>; | ||
reportMetadata: OnyxEntry<ReportMetadata>; | ||
}; | ||
|
||
type TransactionReceiptProps = TransactionReceiptOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSACTION_RECEIPT>; | ||
|
||
function TransactionReceipt({transaction, report, reportMetadata = {isLoadingInitialReportActions: true}, route}: TransactionReceiptProps) { | ||
const receiptURIs = ReceiptUtils.getThumbnailAndImageURIs(transaction); | ||
|
||
const imageSource = tryResolveUrlFromApiRoot(receiptURIs.image); | ||
|
||
const isLocalFile = receiptURIs.isLocalFile; | ||
|
||
const parentReportAction = ReportActionUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); | ||
const canEditReceipt = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.RECEIPT); | ||
const isEReceipt = transaction && TransactionUtils.hasEReceipt(transaction); | ||
|
||
useEffect(() => { | ||
if (report && transaction) { | ||
return; | ||
} | ||
ReportActions.openReport(route.params.reportID); | ||
// I'm disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<AttachmentModal | ||
source={imageSource} | ||
isAuthTokenRequired={!isLocalFile} | ||
report={report} | ||
isReceiptAttachment | ||
canEditReceipt={canEditReceipt} | ||
allowDownload={!isEReceipt} | ||
originalFileName={receiptURIs?.filename} | ||
defaultOpen | ||
onModalClose={() => { | ||
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '')); | ||
}} | ||
isLoading={!transaction && reportMetadata?.isLoadingInitialReportActions} | ||
shouldShowNotFoundPage={(report?.parentReportID ?? '') !== transaction?.reportID} | ||
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. @tienifr Is there a special reason to add this condition here ( This line is causing bugs in self DM track expense. |
||
/> | ||
); | ||
} | ||
|
||
TransactionReceipt.displayName = 'TransactionReceipt'; | ||
|
||
export default withOnyx<TransactionReceiptProps, TransactionReceiptOnyxProps>({ | ||
report: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID ?? '0'}`, | ||
}, | ||
transaction: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${route.params.transactionID ?? '0'}`, | ||
}, | ||
reportMetadata: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_METADATA}${route.params.reportID ?? '0'}`, | ||
}, | ||
})(TransactionReceipt); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Same here
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.
Yes, I updated