Skip to content
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 x requests, y scanning count in ReportPreview #34191

Merged
merged 10 commits into from
Jan 15, 2024
50 changes: 21 additions & 29 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useEffect, useMemo, useState} from 'react';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand All @@ -13,6 +13,7 @@ import refPropTypes from '@components/refPropTypes';
import SettlementButton from '@components/SettlementButton';
import {showContextMenuForReport} from '@components/ShowContextMenuContext';
import Text from '@components/Text';
import transactionPropTypes from '@components/transactionPropTypes';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
Expand All @@ -23,7 +24,6 @@ import ControlSelection from '@libs/ControlSelection';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Navigation from '@libs/Navigation/Navigation';
import onyxSubscribe from '@libs/onyxSubscribe';
import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportActionUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -107,6 +107,9 @@ const propTypes = {
/** Whether a message is a whisper */
isWhisper: PropTypes.bool,

/** All the transactions, used to update ReportPreview label and status */
transactions: PropTypes.objectOf(transactionPropTypes),

...withLocalizePropTypes,
};

Expand All @@ -123,6 +126,7 @@ const defaultProps = {
policy: {
isHarvestingEnabled: false,
},
transactions: {},
};

function ReportPreview(props) {
Expand All @@ -131,10 +135,17 @@ function ReportPreview(props) {
const {getLineHeightStyle} = useStyleUtils();
const {translate} = useLocalize();

const [hasMissingSmartscanFields, sethasMissingSmartscanFields] = useState(false);
const [areAllRequestsBeingSmartScanned, setAreAllRequestsBeingSmartScanned] = useState(false);
const [hasOnlyDistanceRequests, setHasOnlyDistanceRequests] = useState(false);
const [hasNonReimbursableTransactions, setHasNonReimbursableTransactions] = useState(false);
const {hasMissingSmartscanFields, areAllRequestsBeingSmartScanned, hasOnlyDistanceRequests, hasNonReimbursableTransactions} = useMemo(
() => ({
hasMissingSmartscanFields: ReportUtils.hasMissingSmartscanFields(props.iouReportID),
areAllRequestsBeingSmartScanned: ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action),
hasOnlyDistanceRequests: ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID),
hasNonReimbursableTransactions: ReportUtils.hasNonReimbursableTransactions(props.iouReportID),
}),
// When transactions get updated these status may have changed, so that is a case where we also want to run this.
// eslint-disable-next-line react-hooks/exhaustive-deps
[props.transactions, props.iouReportID, props.action],
);

const managerID = props.iouReport.managerID || 0;
const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID');
Expand Down Expand Up @@ -165,7 +176,7 @@ function ReportPreview(props) {
const previewSubtitle =
formattedMerchant ||
props.translate('iou.requestCount', {
count: numberOfRequests,
count: numberOfRequests - numberOfScanningReceipts,
scanningReceipts: numberOfScanningReceipts,
});

Expand Down Expand Up @@ -221,28 +232,6 @@ function ReportPreview(props) {

const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);

useEffect(() => {
const unsubscribeOnyxTransaction = onyxSubscribe({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (allTransactions) => {
if (_.isEmpty(allTransactions)) {
return;
}

sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID));
setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action));
setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID));
setHasNonReimbursableTransactions(ReportUtils.hasNonReimbursableTransactions(props.iouReportID));
},
});

return () => {
unsubscribeOnyxTransaction();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(props.chatReport);
const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && lodashGet(props.policy, 'role') === CONST.POLICY.ROLE.ADMIN;
const isPayer = isPaidGroupPolicy
Expand Down Expand Up @@ -373,5 +362,8 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
transactions: {
key: ONYXKEYS.COLLECTION.TRANSACTION,
},
}),
)(ReportPreview);
4 changes: 3 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST';
import Str from 'expensify-common/lib/str';
import CONST from '@src/CONST';
import type {
AddressLineParams,
Expand Down Expand Up @@ -584,7 +585,8 @@ export default {
receiptStatusText: "Only you can see this receipt when it's scanning. Check back later or enter the details now.",
receiptScanningFailed: 'Receipt scanning failed. Enter the details manually.',
transactionPendingText: 'It takes a few days from the date the card was used for the transaction to post.',
requestCount: ({count, scanningReceipts = 0}: RequestCountParams) => `${count} requests${scanningReceipts > 0 ? `, ${scanningReceipts} scanning` : ''}`,
requestCount: ({count, scanningReceipts = 0}: RequestCountParams) =>
`${count} ${Str.pluralize('request', 'requests', count)}${scanningReceipts > 0 ? `, ${scanningReceipts} scanning` : ''}`,
deleteRequest: 'Delete request',
deleteConfirmation: 'Are you sure that you want to delete this request?',
settledExpensify: 'Paid',
Expand Down
4 changes: 3 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Str from 'expensify-common/lib/str';
import CONST from '@src/CONST';
import type {
AddressLineParams,
Expand Down Expand Up @@ -577,7 +578,8 @@ export default {
receiptStatusText: 'Solo tú puedes ver este recibo cuando se está escaneando. Vuelve más tarde o introduce los detalles ahora.',
receiptScanningFailed: 'El escaneo de recibo ha fallado. Introduce los detalles manualmente.',
transactionPendingText: 'La transacción tarda unos días en contabilizarse desde la fecha en que se utilizó la tarjeta.',
requestCount: ({count, scanningReceipts = 0}: RequestCountParams) => `${count} solicitudes${scanningReceipts > 0 ? `, ${scanningReceipts} escaneando` : ''}`,
requestCount: ({count, scanningReceipts = 0}: RequestCountParams) =>
`${count} ${Str.pluralize('solicitude', 'solicitudes', count)}${scanningReceipts > 0 ? `, ${scanningReceipts} escaneando` : ''}`,
deleteRequest: 'Eliminar pedido',
deleteConfirmation: '¿Estás seguro de que quieres eliminar este pedido?',
settledExpensify: 'Pagado',
Expand Down
Loading