-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e32ed93
commit 98287b6
Showing
3 changed files
with
18 additions
and
64 deletions.
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
36 changes: 5 additions & 31 deletions
36
src/components/ReportActionItem/MoneyRequestPreview/index.tsx
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 |
---|---|---|
@@ -1,44 +1,18 @@ | ||
import lodashIsEmpty from 'lodash/isEmpty'; | ||
import React from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import * as ReportActionsUtils from '@libs/ReportActionsUtils'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import MoneyRequestPreviewContent from './MoneyRequestPreviewContent'; | ||
import type {MoneyRequestPreviewOnyxProps, MoneyRequestPreviewProps} from './types'; | ||
import type {MoneyRequestPreviewProps} from './types'; | ||
|
||
function MoneyRequestPreview(props: MoneyRequestPreviewProps) { | ||
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${props.iouReportID || '-1'}`); | ||
// We should not render the component if there is no iouReport and it's not a split or track expense. | ||
// Moved outside of the component scope to allow for easier use of hooks in the main component. | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return lodashIsEmpty(props.iouReport) && !(props.isBillSplit || props.isTrackExpense) ? null : <MoneyRequestPreviewContent {...props} />; | ||
return lodashIsEmpty(iouReport) && !(props.isBillSplit || props.isTrackExpense) ? null : <MoneyRequestPreviewContent {...props} />; | ||
} | ||
|
||
MoneyRequestPreview.displayName = 'MoneyRequestPreview'; | ||
|
||
export default withOnyx<MoneyRequestPreviewProps, MoneyRequestPreviewOnyxProps>({ | ||
personalDetails: { | ||
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
}, | ||
chatReport: { | ||
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, | ||
}, | ||
iouReport: { | ||
key: ({iouReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`, | ||
}, | ||
session: { | ||
key: ONYXKEYS.SESSION, | ||
}, | ||
transaction: { | ||
key: ({action}) => { | ||
const isMoneyRequestAction = ReportActionsUtils.isMoneyRequestAction(action); | ||
const transactionID = isMoneyRequestAction ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID : 0; | ||
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; | ||
}, | ||
}, | ||
walletTerms: { | ||
key: ONYXKEYS.WALLET_TERMS, | ||
}, | ||
transactionViolations: { | ||
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
}, | ||
})(MoneyRequestPreview); | ||
export default MoneyRequestPreview; |
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