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

Feat/36985 create new rate field #38543

Merged
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
1db16d9
feat: create new rate field
koko57 Feb 26, 2024
2c19aa3
feat: create rate selection page
koko57 Feb 26, 2024
f3b17ad
fix: resolve conflicts
koko57 Feb 29, 2024
b3e1f48
feat: add translation for the rate page
koko57 Feb 29, 2024
6e94444
feat: wip - display rates for policy
koko57 Feb 29, 2024
e759979
fix: resolve conflicts
koko57 Mar 1, 2024
cde1d19
feat: wip - get rate for p2p
koko57 Mar 1, 2024
c3cb80b
feat: wip - new rate field logic
koko57 Mar 1, 2024
5bf399a
fix: revert filtering changes
koko57 Mar 1, 2024
857c320
fix: resolve conflicts
koko57 Mar 12, 2024
bf5e278
fix: resolve conflicts
koko57 Mar 13, 2024
ef7b30e
refactor: use canUseP2PDistanceRequests from usePermissions
koko57 Mar 13, 2024
6f3afdd
fix: remove mock rates
koko57 Mar 13, 2024
50174f3
feat: create function for getting personal policy
koko57 Mar 13, 2024
eb3aff8
feat: add rate field to MoneyRequestView
koko57 Mar 14, 2024
18e2c7c
fix: resolve conflicts
koko57 Mar 15, 2024
1ddc839
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Mar 18, 2024
7dc206c
feat: change customRateID when participant changes, other improvements
koko57 Mar 18, 2024
7698b5a
fix: resolve conflicts
koko57 Mar 19, 2024
a0227e0
fix: run prettier
koko57 Mar 19, 2024
eb350ee
fix: lint fix
koko57 Mar 19, 2024
af94a75
fix: resolve conflicts
koko57 Mar 28, 2024
272c300
fix: resolve conflicts
koko57 Mar 28, 2024
0682afb
fix: add missing screen
koko57 Mar 28, 2024
6105b5d
fix: show check mark on lastSelectedDistanceRate
koko57 Mar 28, 2024
063a8b6
fix: fix distance edit route
koko57 Mar 28, 2024
7fe595a
fix: path fix
koko57 Mar 28, 2024
9e68814
fix: minor fix
koko57 Mar 28, 2024
68eecf0
fix: enable fields for split, fix route
koko57 Mar 28, 2024
35baf30
fix: minor fix
koko57 Mar 28, 2024
e9a15d7
fix: change copy on rate selection page
koko57 Mar 28, 2024
e9f448b
fix: minor fix
koko57 Mar 29, 2024
4217a98
fix: remove a comment
koko57 Mar 29, 2024
ae3ded4
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Mar 29, 2024
f432cb5
fix: resolve conflicts
koko57 Apr 2, 2024
b100cf1
fix: resolve conflicts
koko57 Apr 2, 2024
0826359
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 4, 2024
c7b8854
fix: display distance and rate properly
koko57 Apr 4, 2024
b16107a
fix: minor fixes
koko57 Apr 4, 2024
3bd9aad
fix: apply requested changes
koko57 Apr 5, 2024
bd83588
fix: revert unnecessary change
koko57 Apr 5, 2024
27f1fc1
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 8, 2024
7712cec
fix: get rates from withOnyx hoc, rename DefaultMileageRate
koko57 Apr 8, 2024
72d3142
fix: apply requested changes
koko57 Apr 8, 2024
34908eb
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 9, 2024
fcbdddd
fix: remove unnecessary line
koko57 Apr 9, 2024
7bf1e97
fix: change hardcoded transactionID value for the one from the route …
koko57 Apr 9, 2024
6b04d40
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 10, 2024
fc2c260
fix: type IOURequestStepRate properly
koko57 Apr 10, 2024
7fb35ab
fix: minor fix
koko57 Apr 10, 2024
c37ef58
fix: resolve conflicts
koko57 Apr 10, 2024
ddf117d
fix: minor fixes
koko57 Apr 10, 2024
118aa7b
fix: add comment
koko57 Apr 10, 2024
a9d6ef7
fix: resolve conflicts
koko57 Apr 10, 2024
ec0bfec
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 11, 2024
1511b2e
fix: display only rate when no rate name
koko57 Apr 11, 2024
5c03b38
fix: remove use of lastSelectedDistanceRate
koko57 Apr 11, 2024
96c281d
fix: minor fix
koko57 Apr 11, 2024
4658af3
fix: amend comment
koko57 Apr 11, 2024
2d99306
fix: resolve conflicts
koko57 Apr 11, 2024
6234c99
fix: lint
koko57 Apr 11, 2024
96a7032
fix: add missing arg
koko57 Apr 11, 2024
5de2028
fix: minor fix
koko57 Apr 11, 2024
80f9b5e
fix: recalculate amount, fallback to default rate
koko57 Apr 11, 2024
42206ee
fix: extract logic to a new function
koko57 Apr 12, 2024
8f26c89
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 12, 2024
592bf7a
fix: fix problem with workspace customRateID
koko57 Apr 12, 2024
dfa02a3
fix: minor fix
koko57 Apr 15, 2024
5dc83c5
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 15, 2024
410fdb1
fix: apply requested changes
koko57 Apr 15, 2024
3c47a2c
fix: restore setting customUnitRateID when data available
koko57 Apr 15, 2024
997ef8d
fix: resolve conflicts
koko57 Apr 15, 2024
949bf4e
fix: fallback to first rate when all custom named
koko57 Apr 16, 2024
64951eb
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 16, 2024
28948ab
fix: apply requested changes
koko57 Apr 16, 2024
6bcd257
fix: check for quantity instead of route
koko57 Apr 16, 2024
520cf1f
fix: minor fix
koko57 Apr 16, 2024
5b9b4d1
fix: resolve conflicts
koko57 Apr 16, 2024
706ba6f
fix: resolve conflicts
koko57 Apr 16, 2024
fb59ef1
fix: navigation fix
koko57 Apr 16, 2024
2955ee9
fix: translation
koko57 Apr 16, 2024
05fe83a
fix: resolve conflicts
koko57 Apr 17, 2024
f6ef05f
fix: minor fix
koko57 Apr 17, 2024
a73490b
fix: currency and rate for p2p
koko57 Apr 17, 2024
779cbea
fix: resolve conflicts
koko57 Apr 17, 2024
d6d6f96
fix: remove hasRoute condition from getRateForDisplay
koko57 Apr 17, 2024
fc8f59c
fix: resolve conflicts
koko57 Apr 17, 2024
bdfbbdb
fix: prettier
koko57 Apr 18, 2024
911d684
Merge branch 'main' into feat/36985-create-new-rate-field
koko57 Apr 18, 2024
1a142b8
fix: resolve conflicts
koko57 Apr 18, 2024
5229462
fix: add missing export
koko57 Apr 18, 2024
9c8fbdf
fix: minor fix
koko57 Apr 18, 2024
63c5edd
fix: copy temporary confirmation list content to the original file
koko57 Apr 18, 2024
1bb47d0
fix: resolve conflicts
koko57 Apr 18, 2024
8fe0f19
fix: minor fix
koko57 Apr 18, 2024
29da5dc
fix: resolve conflicts
koko57 Apr 19, 2024
6bb3199
fix: resolve conflicts
koko57 Apr 19, 2024
a93e729
fix: sending customUnitRateID
koko57 Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import * as KeyCommand from 'react-native-key-command';
import type {ValueOf} from 'type-fest';
import * as Url from './libs/Url';
import SCREENS from './SCREENS';
import type {Unit} from './types/onyx/Policy';

type RateAndUnit = {
unit: string;
unit: Unit;
rate: number;
};
type CurrencyDefaultMileageRate = Record<string, RateAndUnit>;
Expand Down Expand Up @@ -4352,6 +4353,6 @@ type Country = keyof typeof CONST.ALL_COUNTRIES;
type IOUType = ValueOf<typeof CONST.IOU.TYPE>;
type IOUAction = ValueOf<typeof CONST.IOU.ACTION>;

export type {Country, IOUAction, IOUType};
export type {Country, IOUAction, IOUType, RateAndUnit};

export default CONST;
5 changes: 5 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ const ROUTES = {
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action as string}/${iouType as string}/distance/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_DISTANCE_RATE: {
route: ':action/:iouType/distanceRate/:transactionID/:reportID',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/distanceRate/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_MERCHANT: {
route: ':action/:iouType/merchant/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') =>
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const SCREENS = {
STEP_DATE: 'Money_Request_Step_Date',
STEP_DESCRIPTION: 'Money_Request_Step_Description',
STEP_DISTANCE: 'Money_Request_Step_Distance',
STEP_DISTANCE_RATE: 'Money_Request_Step_Rate',
STEP_MERCHANT: 'Money_Request_Step_Merchant',
STEP_PARTICIPANTS: 'Money_Request_Step_Participants',
STEP_SCAN: 'Money_Request_Step_Scan',
Expand Down
984 changes: 567 additions & 417 deletions src/components/MoneyRequestConfirmationList.tsx

Large diffs are not rendered by default.

185 changes: 112 additions & 73 deletions src/components/MoneyTemporaryForRefactorRequestConfirmationList.tsx

Large diffs are not rendered by default.

94 changes: 77 additions & 17 deletions src/components/ReportActionItem/MoneyRequestView.tsx
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Switch from '@components/Switch';
import Text from '@components/Text';
import ViolationMessages from '@components/ViolationMessages';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
Expand All @@ -21,6 +22,8 @@ import type {ViolationField} from '@hooks/useViolations';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as CardUtils from '@libs/CardUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import type {MileageRate} from '@libs/DistanceRequestUtils';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -63,6 +66,9 @@ type MoneyRequestViewOnyxPropsWithoutTransaction = {

/** The actions from the parent report */
parentReportActions: OnyxEntry<OnyxTypes.ReportActions>;

/** The rates for the policy */
rates: Record<string, MileageRate>;
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
};

type MoneyRequestViewPropsWithoutTransaction = MoneyRequestViewOnyxPropsWithoutTransaction & {
Expand All @@ -89,13 +95,15 @@ function MoneyRequestView({
policy,
transactionViolations,
shouldShowAnimatedBackground,
rates,
}: MoneyRequestViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isOffline} = useNetwork();
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();
const {canUseViolations} = usePermissions();
const {translate, toLocaleDigit} = useLocalize();
const {canUseViolations, canUseP2PDistanceRequests} = usePermissions();
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null;
const moneyRequestReport = parentReport;
const {
Expand Down Expand Up @@ -170,6 +178,18 @@ function MoneyRequestView({

let amountDescription = `${translate('iou.amount')}`;

const hasRoute = TransactionUtils.hasRoute(transaction, isDistanceRequest);
const rateID = transaction?.comment.customUnit?.customUnitRateID ?? '0';
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved

const currency = policy ? policy.outputCurrency : PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : rates[rateID as string] ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: There's another complication here that we forgot about. Let's handle it in a follow up PR please, since I don't want to delay this one more and add more complexity.

If we're viewing an old request, and the defaultP2P rates have changed since the request was created, then we might display the wrong rate because the rate the request was created with is no longer in the default mapping.

Therefore when viewing a created request we should first try to get the default rate from transaction.comment.customUnit.defaultP2PRate. It stores the rate value number only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neil-marcellini ok I missed this one - will implement this

const {unit, rate} = mileageRate;
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved

const distance = DistanceRequestUtils.getDistanceFromMerchant(transactionMerchant, unit);
const rateToDisplay = DistanceRequestUtils.getRateForDisplay(unit, rate, currency, translate, toLocaleDigit, isOffline);
const distanceToDisplay = DistanceRequestUtils.getDistanceForDisplay(hasRoute, distance, unit, rate, translate);

const saveBillable = useCallback(
(newBillable: boolean) => {
// If the value hasn't changed, don't request to save changes on the server and just close the modal
Expand Down Expand Up @@ -255,6 +275,48 @@ function MoneyRequestView({
[transactionAmount, isSettled, isCancelled, isPolicyExpenseChat, isEmptyMerchant, transactionDate, hasErrors, canUseViolations, hasViolations, translate, getViolationsForField],
);

const distanceRequestFields = canUseP2PDistanceRequests ? (
<>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={distanceToDisplay}
interactive={canEditDistance}
shouldShowRightIcon={canEditDistance}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID))
}
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
<MenuItemWithTopDescription
description={translate('common.rate')}
title={rateToDisplay}
// TODO: https://github.com/Expensify/App/issues/36987 make it interactive and show right icon when EditRatePage is ready
interactive={false}
shouldShowRightIcon={false}
titleStyle={styles.flex1}
// TODO: https://github.com/Expensify/App/issues/36987 Add route for editing rate
onPress={() => {}}
/>
</OfflineWithFeedback>
</>
) : (
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={transactionMerchant}
interactive={canEditDistance}
shouldShowRightIcon={canEditDistance}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID))
}
/>
</OfflineWithFeedback>
);

return (
<View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth, true, shouldShowAnimatedBackground)]}>
{shouldShowAnimatedBackground && <AnimatedEmptyStateBackground />}
Expand Down Expand Up @@ -343,20 +405,7 @@ function MoneyRequestView({
/>
</OfflineWithFeedback>
{isDistanceRequest ? (
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={transactionMerchant}
interactive={canEditDistance}
shouldShowRightIcon={canEditDistance}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID),
)
}
/>
</OfflineWithFeedback>
distanceRequestFields
) : (
<OfflineWithFeedback pendingAction={getPendingFieldAction('merchant')}>
<MenuItemWithTopDescription
Expand Down Expand Up @@ -424,7 +473,14 @@ function MoneyRequestView({
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, orderWeight, transaction?.transactionID ?? '', report.reportID),
)
}
brickRoadIndicator={getErrorForField('tag', {tagListIndex: index, tagListName: name}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
brickRoadIndicator={
getErrorForField('tag', {
tagListIndex: index,
tagListName: name,
})
? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR
: undefined
}
error={getErrorForField('tag', {tagListIndex: index, tagListName: name})}
/>
</OfflineWithFeedback>
Expand Down Expand Up @@ -520,6 +576,10 @@ export default withOnyx<MoneyRequestViewPropsWithoutTransaction, MoneyRequestVie
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`,
canEvict: false,
},
rates: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
selector: DistanceRequestUtils.getMileageRates,
},
})(
withOnyx<MoneyRequestViewProps, MoneyRequestViewTransactionOnyxProps>({
transaction: {
Expand Down
6 changes: 5 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import type {
PayerPaidParams,
PayerSettledParams,
PaySomeoneParams,
ReimbursementRateParams,
RemovedTheRequestParams,
RenamedRoomActionParams,
ReportArchiveReasonsClosedParams,
Expand Down Expand Up @@ -315,6 +316,7 @@ export default {
member: 'Member',
role: 'Role',
currency: 'Currency',
rate: 'Rate',
emptyLHN: {
title: 'Woohoo! All caught up.',
subtitleText1: 'Find a chat using the',
Expand Down Expand Up @@ -628,7 +630,8 @@ export default {
canceled: 'Canceled',
posted: 'Posted',
deleteReceipt: 'Delete receipt',
routePending: 'Route pending...',
routePending: 'Pending...',
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
defaultRate: 'Default rate',
receiptScanning: 'Scan in progress…',
receiptMissingDetails: 'Receipt missing details',
missingAmount: 'Missing amount',
Expand Down Expand Up @@ -732,6 +735,7 @@ export default {
set: 'set',
changed: 'changed',
removed: 'removed',
chooseARate: ({unit}: ReimbursementRateParams) => `Select a workspace reimbursement rate per ${unit}`,
},
notificationPreferencesPage: {
header: 'Notification preferences',
Expand Down
6 changes: 5 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import type {
PayerPaidParams,
PayerSettledParams,
PaySomeoneParams,
ReimbursementRateParams,
RemovedTheRequestParams,
RenamedRoomActionParams,
ReportArchiveReasonsClosedParams,
Expand Down Expand Up @@ -305,6 +306,7 @@ export default {
member: 'Miembro',
role: 'Role',
currency: 'Divisa',
rate: 'Tarifa',
emptyLHN: {
title: 'Woohoo! Todo al día.',
subtitleText1: 'Encuentra un chat usando el botón',
Expand Down Expand Up @@ -621,7 +623,8 @@ export default {
canceled: 'Canceló',
posted: 'Contabilizado',
deleteReceipt: 'Eliminar recibo',
routePending: 'Ruta pendiente...',
routePending: 'Pendiente...',
defaultRate: 'Tasa predeterminada',
receiptScanning: 'Escaneo en curso…',
receiptMissingDetails: 'Recibo con campos vacíos',
missingAmount: 'Falta importe',
Expand Down Expand Up @@ -727,6 +730,7 @@ export default {
set: 'estableció',
changed: 'cambió',
removed: 'eliminó',
chooseARate: ({unit}: ReimbursementRateParams) => `Seleccione una tasa de reembolso del espacio de trabajo por ${unit}`,
},
notificationPreferencesPage: {
header: 'Preferencias de avisos',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {ReportAction} from '@src/types/onyx';
import type {Unit} from '@src/types/onyx/Policy';
import type en from './en';

type AddressLineParams = {
Expand Down Expand Up @@ -299,6 +300,8 @@ type HeldRequestParams = {comment: string};

type DistanceRateOperationsParams = {count: number};

type ReimbursementRateParams = {unit: Unit};

export type {
AdminCanceledRequestParams,
ApprovedAmountParams,
Expand Down Expand Up @@ -403,4 +406,5 @@ export type {
LogSizeParams,
HeldRequestParams,
PaySomeoneParams,
ReimbursementRateParams,
};
Loading