Skip to content

Commit

Permalink
Merge pull request #42374 from tienifr/feature/hold-one-transaction-view
Browse files Browse the repository at this point in the history
feat: hold expense in one transaction view
  • Loading branch information
NikkiWines authored Jun 5, 2024
2 parents 952d844 + dc328eb commit f15ba48
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 138 deletions.
244 changes: 157 additions & 87 deletions src/components/MoneyReportHeader.tsx

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,17 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow

const getStatusBarProps: () => MoneyRequestHeaderStatusBarProps | undefined = () => {
if (isOnHold) {
return {title: translate('iou.hold'), description: translate('iou.expenseOnHold'), danger: true, shouldShowBorderBottom: true};
return {title: translate('iou.hold'), description: translate('iou.expenseOnHold'), danger: true};
}

if (TransactionUtils.isExpensifyCardTransaction(transaction) && TransactionUtils.isPending(transaction)) {
return {title: getStatusIcon(Expensicons.CreditCardHourglass), description: translate('iou.transactionPendingDescription'), shouldShowBorderBottom: true};
return {title: getStatusIcon(Expensicons.CreditCardHourglass), description: translate('iou.transactionPendingDescription')};
}
if (TransactionUtils.hasPendingRTERViolation(TransactionUtils.getTransactionViolations(transaction?.transactionID ?? '', transactionViolations))) {
return {
title: getStatusIcon(Expensicons.Hourglass),
description: translate('iou.pendingMatchWithCreditCardDescription'),
shouldShowBorderBottom: true,
};
return {title: getStatusIcon(Expensicons.Hourglass), description: translate('iou.pendingMatchWithCreditCardDescription')};
}
if (isScanning) {
return {title: getStatusIcon(Expensicons.ReceiptScan), description: translate('iou.receiptScanInProgressDescription'), shouldShowBorderBottom: true};
return {title: getStatusIcon(Expensicons.ReceiptScan), description: translate('iou.receiptScanInProgressDescription')};
}
};

Expand Down Expand Up @@ -241,12 +237,13 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
</View>
)}
{statusBarProps && (
<MoneyRequestHeaderStatusBar
title={statusBarProps.title}
description={statusBarProps.description}
danger={statusBarProps.danger}
shouldShowBorderBottom={statusBarProps.shouldShowBorderBottom}
/>
<View style={[styles.ph5, styles.pb3, styles.borderBottom]}>
<MoneyRequestHeaderStatusBar
title={statusBarProps.title}
description={statusBarProps.description}
danger={statusBarProps.danger}
/>
</View>
)}
</View>
<ConfirmModal
Expand Down
20 changes: 2 additions & 18 deletions src/components/MoneyRequestHeaderStatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,17 @@ type MoneyRequestHeaderStatusBarProps = {
/** Banner Description */
description: string;

/** Whether we show the border bottom */
shouldShowBorderBottom: boolean;

/** Whether we should use the danger theme color */
danger?: boolean;

/** Whether we style flex grow */
shouldStyleFlexGrow?: boolean;
};

function MoneyRequestHeaderStatusBar({title, description, shouldShowBorderBottom, danger = false, shouldStyleFlexGrow = true}: MoneyRequestHeaderStatusBarProps) {
function MoneyRequestHeaderStatusBar({title, description, danger = false, shouldStyleFlexGrow = true}: MoneyRequestHeaderStatusBarProps) {
const styles = useThemeStyles();
const borderBottomStyle = shouldShowBorderBottom ? styles.borderBottom : {};
return (
<View
style={[
styles.dFlex,
styles.flexRow,
styles.alignItemsCenter,
shouldStyleFlexGrow && styles.flexGrow1,
styles.overflowHidden,
styles.ph5,
styles.pb3,
borderBottomStyle,
styles.headerStatusBarContainer,
]}
>
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, shouldStyleFlexGrow && styles.flexGrow1, styles.overflowHidden, styles.headerStatusBarContainer]}>
{typeof title === 'string' ? (
<View style={[styles.mr3]}>
<Badge
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ export default {
reason: 'Reason',
holdReasonRequired: 'A reason is required when holding.',
expenseOnHold: 'This expense was put on hold. Review the comments for next steps.',
expensesOnHold: 'All expenses were put on hold. Review the comments for next steps.',
confirmApprove: 'Confirm approval amount',
confirmApprovalAmount: "Approve what's not on hold, or approve the entire report.",
confirmPay: 'Confirm payment amount',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ export default {
reason: 'Razón',
holdReasonRequired: 'Se requiere una razón para bloquear.',
expenseOnHold: 'Este gasto está bloqueado. Revisa los comentarios para saber como proceder.',
expensesOnHold: 'Todos los gastos quedaron bloqueado. Revisa los comentarios para saber como proceder.',
confirmApprove: 'Confirmar importe a aprobar',
confirmApprovalAmount: 'Aprueba lo que no está bloqueado, o aprueba todo el informe.',
confirmPay: 'Confirmar importe de pago',
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6372,9 +6372,9 @@ function hasHeldExpenses(iouReportID?: string): boolean {
/**
* Check if all expenses in the Report are on hold
*/
function hasOnlyHeldExpenses(iouReportID: string): boolean {
const transactions = TransactionUtils.getAllReportTransactions(iouReportID);
return !transactions.some((transaction) => !TransactionUtils.isOnHold(transaction));
function hasOnlyHeldExpenses(iouReportID: string, transactions?: OnyxCollection<Transaction>): boolean {
const reportTransactions = TransactionUtils.getAllReportTransactions(iouReportID, transactions);
return !reportTransactions.some((transaction) => !TransactionUtils.isOnHold(transaction));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,12 @@ function hasRoute(transaction: OnyxEntry<Transaction>, isDistanceRequestType: bo
return !!transaction?.routes?.route0?.geometry?.coordinates || (isDistanceRequestType && !!transaction?.comment?.customUnit?.quantity);
}

function getAllReportTransactions(reportID?: string): Transaction[] {
function getAllReportTransactions(reportID?: string, transactions?: OnyxCollection<Transaction>): Transaction[] {
// `reportID` from the `/CreateDistanceRequest` endpoint return's number instead of string for created `transaction`.
// For reference, https://github.com/Expensify/App/pull/26536#issuecomment-1703573277.
// We will update this in a follow-up Issue. According to this comment: https://github.com/Expensify/App/pull/26536#issuecomment-1703591019.
const transactions: Transaction[] = Object.values(allTransactions ?? {}).filter((transaction): transaction is Transaction => transaction !== null);
return transactions.filter((transaction) => `${transaction.reportID}` === `${reportID}`);
const nonNullableTransactions: Transaction[] = Object.values(transactions ?? allTransactions ?? {}).filter((transaction): transaction is Transaction => transaction !== null);
return nonNullableTransactions.filter((transaction) => `${transaction.reportID}` === `${reportID}`);
}

function waypointHasValidAddress(waypoint: RecentWaypoint | Waypoint): boolean {
Expand Down
27 changes: 14 additions & 13 deletions src/pages/iou/SplitBillDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,20 @@ function SplitBillDetailsPage({personalDetails, report, route, reportActions, tr
<HeaderWithBackButton title={translate('common.details')} />
<View style={[styles.containerWithSpaceBetween, styles.pointerEventsBoxNone]}>
{isScanning && (
<MoneyRequestHeaderStatusBar
title={
<Icon
src={Expensicons.ReceiptScan}
height={variables.iconSizeSmall}
width={variables.iconSizeSmall}
fill={theme.icon}
/>
}
description={translate('iou.receiptScanInProgressDescription')}
shouldShowBorderBottom
shouldStyleFlexGrow={false}
/>
<View style={[styles.ph5, styles.pb3, styles.borderBottom]}>
<MoneyRequestHeaderStatusBar
title={
<Icon
src={Expensicons.ReceiptScan}
height={variables.iconSizeSmall}
width={variables.iconSizeSmall}
fill={theme.icon}
/>
}
description={translate('iou.receiptScanInProgressDescription')}
shouldStyleFlexGrow={false}
/>
</View>
)}
{!!participants.length && (
<MoneyRequestConfirmationList
Expand Down

0 comments on commit f15ba48

Please sign in to comment.