Skip to content

Commit

Permalink
Merge pull request #39910 from software-mansion-labs/ts-migration/IOU…
Browse files Browse the repository at this point in the history
…RequestStartPage
  • Loading branch information
luacmartins authored Apr 12, 2024
2 parents ad1a1a6 + 24e637d commit d4bc1b0
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 271 deletions.
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ const ROUTES = {
},
MONEY_REQUEST_STEP_WAYPOINT: {
route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, pageIndex = '', backTo = '') =>
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID?: string, pageIndex = '', backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/waypoint/${transactionID}/${reportID}/${pageIndex}`, backTo),
},
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DistanceRequestProps = {
onSecondaryInteraction?: () => void;

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

/** Whether the item is active */
isActive?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/Navigation/OnyxTabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {TabSelectorProps} from '@components/TabSelector/TabSelector';
import type {IOURequestType} from '@libs/actions/IOU';
import Tab from '@userActions/Tab';
import ONYXKEYS from '@src/ONYXKEYS';
import type {SelectedTabRequest} from '@src/types/onyx';
Expand All @@ -24,7 +25,7 @@ type OnyxTabNavigatorProps = OnyxTabNavigatorOnyxProps &
selectedTab?: SelectedTabRequest;

/** A function triggered when a tab has been selected */
onTabSelected?: (newIouType: string) => void;
onTabSelected?: (newIouType: IOURequestType) => void;

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

Expand Down Expand Up @@ -52,7 +53,7 @@ function OnyxTabNavigator({id, selectedTab, children, onTabSelected = () => {},
const index = state.index;
const routeNames = state.routeNames;
Tab.setSelectedTab(id, routeNames[index] as SelectedTabRequest);
onTabSelected(routeNames[index]);
onTabSelected(routeNames[index] as IOURequestType);
},
...(screenListeners ?? {}),
}}
Expand Down
33 changes: 25 additions & 8 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
Route,
} from '@react-navigation/native';
import type {ValueOf} from 'type-fest';
import type {IOURequestType} from '@libs/actions/IOU';
import type CONST from '@src/CONST';
import type {Country} from '@src/CONST';
import type NAVIGATORS from '@src/NAVIGATORS';
Expand Down Expand Up @@ -349,13 +350,6 @@ type RoomInviteNavigatorParamList = {
};

type MoneyRequestNavigatorParamList = {
[SCREENS.MONEY_REQUEST.STEP_AMOUNT]: {
action: ValueOf<typeof CONST.IOU.ACTION>;
iouType: ValueOf<typeof CONST.IOU.TYPE>;
transactionID: string;
reportID: string;
backTo: string;
};
[SCREENS.MONEY_REQUEST.PARTICIPANTS]: {
iouType: string;
reportID: string;
Expand Down Expand Up @@ -431,7 +425,7 @@ type MoneyRequestNavigatorParamList = {
threadReportID: number;
};
[SCREENS.MONEY_REQUEST.STEP_DISTANCE]: {
action: string;
action: ValueOf<typeof CONST.IOU.ACTION>;
iouType: ValueOf<typeof CONST.IOU.TYPE>;
transactionID: string;
reportID: string;
Expand All @@ -441,6 +435,29 @@ type MoneyRequestNavigatorParamList = {
iouType: string;
reportID: string;
};
[SCREENS.MONEY_REQUEST.CREATE]: {
iouType: ValueOf<typeof CONST.IOU.TYPE>;
reportID: string;
transactionID: string;

// These are not used in the screen, but are needed for the navigation
// for IOURequestStepDistance and IOURequestStepAmount components
backTo: never;
action: never;
};
[SCREENS.MONEY_REQUEST.START]: {
iouType: ValueOf<typeof CONST.IOU.TYPE>;
reportID: string;
transactionID: string;
iouRequestType: IOURequestType;
};
[SCREENS.MONEY_REQUEST.STEP_AMOUNT]: {
iouType: ValueOf<typeof CONST.IOU.TYPE>;
reportID: string;
transactionID: string;
backTo: Routes;
action: ValueOf<typeof CONST.IOU.ACTION>;
};
[SCREENS.MONEY_REQUEST.STEP_PARTICIPANTS]: {
iouType: ValueOf<typeof CONST.IOU.TYPE>;
transactionID: string;
Expand Down
63 changes: 45 additions & 18 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2177,15 +2177,24 @@ function updateMoneyRequestTaxRate(
API.write('UpdateMoneyRequestTaxRate', params, onyxData);
}

type UpdateMoneyRequestDistanceParams = {
transactionID: string;
transactionThreadReportID: string;
waypoints: WaypointCollection;
policy?: OnyxEntry<OnyxTypes.Policy>;
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagList>;
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
};

/** Updates the waypoints of a distance money request */
function updateMoneyRequestDistance(
transactionID: string,
transactionThreadReportID: string,
waypoints: WaypointCollection,
policy: OnyxEntry<OnyxTypes.Policy>,
policyTagList: OnyxEntry<OnyxTypes.PolicyTagList>,
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>,
) {
function updateMoneyRequestDistance({
transactionID,
transactionThreadReportID,
waypoints,
policy = {} as OnyxTypes.Policy,
policyTagList = {},
policyCategories = {},
}: UpdateMoneyRequestDistanceParams) {
const transactionChanges: TransactionChanges = {
waypoints,
};
Expand Down Expand Up @@ -3820,21 +3829,39 @@ function editMoneyRequest(
}
}

type UpdateMoneyRequestAmountAndCurrencyParams = {
transactionID: string;
transactionThreadReportID: string;
currency: string;
amount: number;
policy?: OnyxEntry<OnyxTypes.Policy>;
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagList>;
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
};

/** Updates the amount and currency fields of a money request */
function updateMoneyRequestAmountAndCurrency(
transactionID: string,
transactionThreadReportID: string,
currency: string,
amount: number,
policy: OnyxEntry<OnyxTypes.Policy>,
policyTagList: OnyxEntry<OnyxTypes.PolicyTagList>,
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>,
) {
function updateMoneyRequestAmountAndCurrency({
transactionID,
transactionThreadReportID,
currency,
amount,
policy,
policyTagList,
policyCategories,
}: UpdateMoneyRequestAmountAndCurrencyParams) {
const transactionChanges = {
amount,
currency,
};
const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy, policyTagList, policyCategories, true);
const {params, onyxData} = getUpdateMoneyRequestParams(
transactionID,
transactionThreadReportID,
transactionChanges,
policy ?? null,
policyTagList ?? null,
policyCategories ?? null,
true,
);
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_AMOUNT_AND_CURRENCY, params, onyxData);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
import PropTypes from 'prop-types';
import React, {useEffect} from 'react';
import _ from 'underscore';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ScreenWrapper from '@components/ScreenWrapper';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {WithWritableReportOrNotFoundProps} from './step/withWritableReportOrNotFound';

const propTypes = {
/** Navigation route context info provided by react navigation */
route: PropTypes.shape({
/** Route specific parameters used on this screen */
params: PropTypes.shape({
/** The type of IOU report, i.e. bill, request, send */
iouType: PropTypes.oneOf(_.values(CONST.IOU.TYPE)).isRequired,

/** The type of IOU Request, i.e. manual, scan, distance */
iouRequestType: PropTypes.oneOf(_.values(CONST.IOU.REQUEST_TYPE)).isRequired,
}),
}).isRequired,
};
type IOURequestRedirectToStartPageProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.START>;

function IOURequestRedirectToStartPage({
route: {
params: {iouType, iouRequestType},
},
}) {
const isIouTypeValid = _.values(CONST.IOU.TYPE).includes(iouType);
const isIouRequestTypeValid = _.values(CONST.IOU.REQUEST_TYPE).includes(iouRequestType);
}: IOURequestRedirectToStartPageProps) {
const isIouTypeValid = Object.values(CONST.IOU.TYPE).includes(iouType);
const isIouRequestTypeValid = Object.values(CONST.IOU.REQUEST_TYPE).includes(iouRequestType);

useEffect(() => {
if (!isIouTypeValid || !isIouRequestTypeValid) {
Expand Down Expand Up @@ -64,6 +52,5 @@ function IOURequestRedirectToStartPage({
}

IOURequestRedirectToStartPage.displayName = 'IOURequestRedirectToStartPage';
IOURequestRedirectToStartPage.propTypes = propTypes;

export default IOURequestRedirectToStartPage;
Loading

0 comments on commit d4bc1b0

Please sign in to comment.