-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33969 from infinitered/32571-money-request-preview
- Loading branch information
Showing
14 changed files
with
203 additions
and
144 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
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
44 changes: 44 additions & 0 deletions
44
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import lodashIsEmpty from 'lodash/isEmpty'; | ||
import React from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import * as ReportActionsUtils from '@libs/ReportActionsUtils'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import MoneyRequestPreviewContent from './MoneyRequestPreviewContent'; | ||
import type {MoneyRequestPreviewOnyxProps, MoneyRequestPreviewProps} from './types'; | ||
|
||
function MoneyRequestPreview(props: MoneyRequestPreviewProps) { | ||
// We should not render the component if there is no iouReport and it's not a split. | ||
// 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 ? 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 ? action?.originalMessage?.IOUTransactionID : 0; | ||
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; | ||
}, | ||
}, | ||
walletTerms: { | ||
key: ONYXKEYS.WALLET_TERMS, | ||
}, | ||
transactionViolations: { | ||
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
}, | ||
})(MoneyRequestPreview); |
71 changes: 71 additions & 0 deletions
71
src/components/ReportActionItem/MoneyRequestPreview/types.ts
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,71 @@ | ||
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native'; | ||
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
|
||
type MoneyRequestPreviewOnyxProps = { | ||
/** All of the personal details for everyone */ | ||
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>; | ||
|
||
/** Chat report associated with iouReport */ | ||
chatReport: OnyxEntry<OnyxTypes.Report>; | ||
|
||
/** IOU report data object */ | ||
iouReport: OnyxEntry<OnyxTypes.Report>; | ||
|
||
/** Session info for the currently logged in user. */ | ||
session: OnyxEntry<OnyxTypes.Session>; | ||
|
||
/** The transaction attached to the action.message.iouTransactionID */ | ||
transaction: OnyxEntry<OnyxTypes.Transaction>; | ||
|
||
/** The transaction violations attached to the action.message.iouTransactionID */ | ||
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>; | ||
|
||
/** Information about the user accepting the terms for payments */ | ||
walletTerms: OnyxEntry<OnyxTypes.WalletTerms>; | ||
}; | ||
|
||
type MoneyRequestPreviewProps = MoneyRequestPreviewOnyxProps & { | ||
/** The active IOUReport, used for Onyx subscription */ | ||
// The iouReportID is used inside withOnyx HOC | ||
// eslint-disable-next-line react/no-unused-prop-types | ||
iouReportID: string; | ||
|
||
/** The associated chatReport */ | ||
chatReportID: string; | ||
|
||
/** The ID of the current report */ | ||
reportID: string; | ||
|
||
/** Callback for the preview pressed */ | ||
onPreviewPressed: (event?: GestureResponderEvent | KeyboardEvent) => void; | ||
|
||
/** All the data of the action, used for showing context menu */ | ||
action: OnyxTypes.ReportAction; | ||
|
||
/** Popover context menu anchor, used for showing context menu */ | ||
contextMenuAnchor?: ContextMenuAnchor; | ||
|
||
/** Callback for updating context menu active state, used for showing context menu */ | ||
checkIfContextMenuActive?: () => void; | ||
|
||
/** Extra styles to pass to View wrapper */ | ||
containerStyles?: StyleProp<ViewStyle>; | ||
|
||
/** True if this is this IOU is a split instead of a 1:1 request */ | ||
isBillSplit: boolean; | ||
|
||
/** True if the IOU Preview card is hovered */ | ||
isHovered?: boolean; | ||
|
||
/** Whether or not an IOU report contains money requests in a different currency | ||
* that are either created or cancelled offline, and thus haven't been converted to the report's currency yet | ||
*/ | ||
shouldShowPendingConversionMessage?: boolean; | ||
|
||
/** Whether a message is a whisper */ | ||
isWhisper?: boolean; | ||
}; | ||
|
||
export type {MoneyRequestPreviewProps, MoneyRequestPreviewOnyxProps}; |
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
Oops, something went wrong.