Skip to content

Commit d4bc1b0

Browse files
authored
Merge pull request #39910 from software-mansion-labs/ts-migration/IOURequestStartPage
2 parents ad1a1a6 + 24e637d commit d4bc1b0

14 files changed

+276
-271
lines changed

src/ROUTES.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ const ROUTES = {
382382
},
383383
MONEY_REQUEST_STEP_WAYPOINT: {
384384
route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex',
385-
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, pageIndex = '', backTo = '') =>
385+
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID?: string, pageIndex = '', backTo = '') =>
386386
getUrlWithBackToParam(`${action}/${iouType}/waypoint/${transactionID}/${reportID}/${pageIndex}`, backTo),
387387
},
388388
// This URL is used as a redirect to one of the create tabs below. This is so that we can message users with a link

src/components/DistanceRequest/DistanceRequestRenderItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DistanceRequestProps = {
1717
onSecondaryInteraction?: () => void;
1818

1919
/** Function to get the index of the item */
20-
getIndex?: () => number;
20+
getIndex?: () => number | undefined;
2121

2222
/** Whether the item is active */
2323
isActive?: boolean;

src/libs/Navigation/OnyxTabNavigator.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React from 'react';
55
import {withOnyx} from 'react-native-onyx';
66
import type {OnyxEntry} from 'react-native-onyx';
77
import type {TabSelectorProps} from '@components/TabSelector/TabSelector';
8+
import type {IOURequestType} from '@libs/actions/IOU';
89
import Tab from '@userActions/Tab';
910
import ONYXKEYS from '@src/ONYXKEYS';
1011
import type {SelectedTabRequest} from '@src/types/onyx';
@@ -24,7 +25,7 @@ type OnyxTabNavigatorProps = OnyxTabNavigatorOnyxProps &
2425
selectedTab?: SelectedTabRequest;
2526

2627
/** A function triggered when a tab has been selected */
27-
onTabSelected?: (newIouType: string) => void;
28+
onTabSelected?: (newIouType: IOURequestType) => void;
2829

2930
tabBar: (props: TabSelectorProps) => React.ReactNode;
3031

@@ -52,7 +53,7 @@ function OnyxTabNavigator({id, selectedTab, children, onTabSelected = () => {},
5253
const index = state.index;
5354
const routeNames = state.routeNames;
5455
Tab.setSelectedTab(id, routeNames[index] as SelectedTabRequest);
55-
onTabSelected(routeNames[index]);
56+
onTabSelected(routeNames[index] as IOURequestType);
5657
},
5758
...(screenListeners ?? {}),
5859
}}

src/libs/Navigation/types.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
Route,
1212
} from '@react-navigation/native';
1313
import type {ValueOf} from 'type-fest';
14+
import type {IOURequestType} from '@libs/actions/IOU';
1415
import type CONST from '@src/CONST';
1516
import type {Country} from '@src/CONST';
1617
import type NAVIGATORS from '@src/NAVIGATORS';
@@ -349,13 +350,6 @@ type RoomInviteNavigatorParamList = {
349350
};
350351

351352
type MoneyRequestNavigatorParamList = {
352-
[SCREENS.MONEY_REQUEST.STEP_AMOUNT]: {
353-
action: ValueOf<typeof CONST.IOU.ACTION>;
354-
iouType: ValueOf<typeof CONST.IOU.TYPE>;
355-
transactionID: string;
356-
reportID: string;
357-
backTo: string;
358-
};
359353
[SCREENS.MONEY_REQUEST.PARTICIPANTS]: {
360354
iouType: string;
361355
reportID: string;
@@ -431,7 +425,7 @@ type MoneyRequestNavigatorParamList = {
431425
threadReportID: number;
432426
};
433427
[SCREENS.MONEY_REQUEST.STEP_DISTANCE]: {
434-
action: string;
428+
action: ValueOf<typeof CONST.IOU.ACTION>;
435429
iouType: ValueOf<typeof CONST.IOU.TYPE>;
436430
transactionID: string;
437431
reportID: string;
@@ -441,6 +435,29 @@ type MoneyRequestNavigatorParamList = {
441435
iouType: string;
442436
reportID: string;
443437
};
438+
[SCREENS.MONEY_REQUEST.CREATE]: {
439+
iouType: ValueOf<typeof CONST.IOU.TYPE>;
440+
reportID: string;
441+
transactionID: string;
442+
443+
// These are not used in the screen, but are needed for the navigation
444+
// for IOURequestStepDistance and IOURequestStepAmount components
445+
backTo: never;
446+
action: never;
447+
};
448+
[SCREENS.MONEY_REQUEST.START]: {
449+
iouType: ValueOf<typeof CONST.IOU.TYPE>;
450+
reportID: string;
451+
transactionID: string;
452+
iouRequestType: IOURequestType;
453+
};
454+
[SCREENS.MONEY_REQUEST.STEP_AMOUNT]: {
455+
iouType: ValueOf<typeof CONST.IOU.TYPE>;
456+
reportID: string;
457+
transactionID: string;
458+
backTo: Routes;
459+
action: ValueOf<typeof CONST.IOU.ACTION>;
460+
};
444461
[SCREENS.MONEY_REQUEST.STEP_PARTICIPANTS]: {
445462
iouType: ValueOf<typeof CONST.IOU.TYPE>;
446463
transactionID: string;

src/libs/actions/IOU.ts

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,15 +2177,24 @@ function updateMoneyRequestTaxRate(
21772177
API.write('UpdateMoneyRequestTaxRate', params, onyxData);
21782178
}
21792179

2180+
type UpdateMoneyRequestDistanceParams = {
2181+
transactionID: string;
2182+
transactionThreadReportID: string;
2183+
waypoints: WaypointCollection;
2184+
policy?: OnyxEntry<OnyxTypes.Policy>;
2185+
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagList>;
2186+
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
2187+
};
2188+
21802189
/** Updates the waypoints of a distance money request */
2181-
function updateMoneyRequestDistance(
2182-
transactionID: string,
2183-
transactionThreadReportID: string,
2184-
waypoints: WaypointCollection,
2185-
policy: OnyxEntry<OnyxTypes.Policy>,
2186-
policyTagList: OnyxEntry<OnyxTypes.PolicyTagList>,
2187-
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>,
2188-
) {
2190+
function updateMoneyRequestDistance({
2191+
transactionID,
2192+
transactionThreadReportID,
2193+
waypoints,
2194+
policy = {} as OnyxTypes.Policy,
2195+
policyTagList = {},
2196+
policyCategories = {},
2197+
}: UpdateMoneyRequestDistanceParams) {
21892198
const transactionChanges: TransactionChanges = {
21902199
waypoints,
21912200
};
@@ -3820,21 +3829,39 @@ function editMoneyRequest(
38203829
}
38213830
}
38223831

3832+
type UpdateMoneyRequestAmountAndCurrencyParams = {
3833+
transactionID: string;
3834+
transactionThreadReportID: string;
3835+
currency: string;
3836+
amount: number;
3837+
policy?: OnyxEntry<OnyxTypes.Policy>;
3838+
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagList>;
3839+
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
3840+
};
3841+
38233842
/** Updates the amount and currency fields of a money request */
3824-
function updateMoneyRequestAmountAndCurrency(
3825-
transactionID: string,
3826-
transactionThreadReportID: string,
3827-
currency: string,
3828-
amount: number,
3829-
policy: OnyxEntry<OnyxTypes.Policy>,
3830-
policyTagList: OnyxEntry<OnyxTypes.PolicyTagList>,
3831-
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>,
3832-
) {
3843+
function updateMoneyRequestAmountAndCurrency({
3844+
transactionID,
3845+
transactionThreadReportID,
3846+
currency,
3847+
amount,
3848+
policy,
3849+
policyTagList,
3850+
policyCategories,
3851+
}: UpdateMoneyRequestAmountAndCurrencyParams) {
38333852
const transactionChanges = {
38343853
amount,
38353854
currency,
38363855
};
3837-
const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy, policyTagList, policyCategories, true);
3856+
const {params, onyxData} = getUpdateMoneyRequestParams(
3857+
transactionID,
3858+
transactionThreadReportID,
3859+
transactionChanges,
3860+
policy ?? null,
3861+
policyTagList ?? null,
3862+
policyCategories ?? null,
3863+
true,
3864+
);
38383865
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_AMOUNT_AND_CURRENCY, params, onyxData);
38393866
}
38403867

src/pages/iou/request/IOURequestRedirectToStartPage.js renamed to src/pages/iou/request/IOURequestRedirectToStartPage.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
import PropTypes from 'prop-types';
21
import React, {useEffect} from 'react';
3-
import _ from 'underscore';
42
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
53
import ScreenWrapper from '@components/ScreenWrapper';
64
import Navigation from '@libs/Navigation/Navigation';
75
import * as ReportUtils from '@libs/ReportUtils';
86
import CONST from '@src/CONST';
97
import ROUTES from '@src/ROUTES';
8+
import type SCREENS from '@src/SCREENS';
9+
import type {WithWritableReportOrNotFoundProps} from './step/withWritableReportOrNotFound';
1010

11-
const propTypes = {
12-
/** Navigation route context info provided by react navigation */
13-
route: PropTypes.shape({
14-
/** Route specific parameters used on this screen */
15-
params: PropTypes.shape({
16-
/** The type of IOU report, i.e. bill, request, send */
17-
iouType: PropTypes.oneOf(_.values(CONST.IOU.TYPE)).isRequired,
18-
19-
/** The type of IOU Request, i.e. manual, scan, distance */
20-
iouRequestType: PropTypes.oneOf(_.values(CONST.IOU.REQUEST_TYPE)).isRequired,
21-
}),
22-
}).isRequired,
23-
};
11+
type IOURequestRedirectToStartPageProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.START>;
2412

2513
function IOURequestRedirectToStartPage({
2614
route: {
2715
params: {iouType, iouRequestType},
2816
},
29-
}) {
30-
const isIouTypeValid = _.values(CONST.IOU.TYPE).includes(iouType);
31-
const isIouRequestTypeValid = _.values(CONST.IOU.REQUEST_TYPE).includes(iouRequestType);
17+
}: IOURequestRedirectToStartPageProps) {
18+
const isIouTypeValid = Object.values(CONST.IOU.TYPE).includes(iouType);
19+
const isIouRequestTypeValid = Object.values(CONST.IOU.REQUEST_TYPE).includes(iouRequestType);
3220

3321
useEffect(() => {
3422
if (!isIouTypeValid || !isIouRequestTypeValid) {
@@ -64,6 +52,5 @@ function IOURequestRedirectToStartPage({
6452
}
6553

6654
IOURequestRedirectToStartPage.displayName = 'IOURequestRedirectToStartPage';
67-
IOURequestRedirectToStartPage.propTypes = propTypes;
6855

6956
export default IOURequestRedirectToStartPage;

0 commit comments

Comments
 (0)