Skip to content

Commit

Permalink
Merge pull request #40896 from brunovjk/fix/40870
Browse files Browse the repository at this point in the history
[No QA]: Complete the final cleanup for distance request refactoring
  • Loading branch information
tgolen authored Apr 24, 2024
2 parents b3420dc + 2b0b12c commit d8ed250
Show file tree
Hide file tree
Showing 17 changed files with 12 additions and 407 deletions.
4 changes: 0 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const ONYXKEYS = {
CREDENTIALS: 'credentials',
STASHED_CREDENTIALS: 'stashedCredentials',

// Contains loading data for the IOU feature (MoneyRequestModal, IOUDetail, & MoneyRequestPreview Components)
IOU: 'iou',

/** Keeps track if there is modal currently visible or not */
MODAL: 'modal',

Expand Down Expand Up @@ -577,7 +574,6 @@ type OnyxValuesMapping = {
[ONYXKEYS.CURRENT_DATE]: string;
[ONYXKEYS.CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.STASHED_CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.IOU]: OnyxTypes.IOU;
[ONYXKEYS.MODAL]: OnyxTypes.Modal;
[ONYXKEYS.NETWORK]: OnyxTypes.Network;
[ONYXKEYS.NEW_GROUP_CHAT_DRAFT]: OnyxTypes.NewGroupChatDraft;
Expand Down
13 changes: 0 additions & 13 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ const ROUTES = {
route: 'r/:reportID/split/:reportActionID',
getRoute: (reportID: string, reportActionID: string) => `r/${reportID}/split/${reportActionID}` as const,
},
EDIT_SPLIT_BILL: {
route: `r/:reportID/split/:reportActionID/edit/:field/:tagIndex?`,
getRoute: (reportID: string, reportActionID: string, field: ValueOf<typeof CONST.EDIT_REQUEST_FIELD>, tagIndex?: number) =>
`r/${reportID}/split/${reportActionID}/edit/${field as string}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const,
},
TASK_TITLE: {
route: 'r/:reportID/title',
getRoute: (reportID: string) => `r/${reportID}/title` as const,
Expand Down Expand Up @@ -310,14 +305,6 @@ const ROUTES = {
getRoute: (type: ValueOf<typeof CONST.POLICY.TYPE>, transactionID: string, reportID: string, backTo: string) =>
`${type}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const,
},
MONEY_REQUEST_MERCHANT: {
route: ':iouType/new/merchant/:reportID?',
getRoute: (iouType: IOUType, reportID = '') => `${iouType}/new/merchant/${reportID}` as const,
},
MONEY_REQUEST_RECEIPT: {
route: ':iouType/new/receipt/:reportID?',
getRoute: (iouType: IOUType, reportID = '') => `${iouType}/new/receipt/${reportID}` as const,
},
MONEY_REQUEST_CREATE: {
route: ':action/:iouType/start/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `${action as string}/${iouType as string}/start/${transactionID}/${reportID}` as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,11 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator<MoneyRequestNa
[SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: () => require('../../../../pages/AddPersonalBankAccountPage').default as React.ComponentType,
[SCREENS.IOU_SEND.ADD_DEBIT_CARD]: () => require('../../../../pages/settings/Wallet/AddDebitCardPage').default as React.ComponentType,
[SCREENS.IOU_SEND.ENABLE_PAYMENTS]: () => require('../../../../pages/EnablePayments/EnablePaymentsPage').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.WAYPOINT]: () => require('../../../../pages/iou/MoneyRequestWaypointPage').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.RECEIPT]: () => require('../../../../pages/EditRequestReceiptPage').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.STATE_SELECTOR]: () => require('../../../../pages/settings/Profile/PersonalDetails/StateSelectionPage').default as React.ComponentType,
});

const SplitDetailsModalStackNavigator = createModalStackNavigator<SplitDetailsNavigatorParamList>({
[SCREENS.SPLIT_DETAILS.ROOT]: () => require('../../../../pages/iou/SplitBillDetailsPage').default as React.ComponentType,
[SCREENS.SPLIT_DETAILS.EDIT_REQUEST]: () => require('../../../../pages/EditSplitBillPage').default as React.ComponentType,
});

const DetailsModalStackNavigator = createModalStackNavigator<DetailsNavigatorParamList>({
Expand Down
2 changes: 0 additions & 2 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: ROUTES.MONEY_REQUEST_STEP_WAYPOINT.route,
[SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.route,
[SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: ROUTES.MONEY_REQUEST_STEP_TAX_RATE.route,
[SCREENS.MONEY_REQUEST.RECEIPT]: ROUTES.MONEY_REQUEST_RECEIPT.route,
[SCREENS.MONEY_REQUEST.STATE_SELECTOR]: {path: ROUTES.MONEY_REQUEST_STATE_SELECTOR.route, exact: true},
[SCREENS.IOU_SEND.ENABLE_PAYMENTS]: ROUTES.IOU_SEND_ENABLE_PAYMENTS,
[SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: ROUTES.IOU_SEND_ADD_BANK_ACCOUNT,
Expand All @@ -610,7 +609,6 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.RIGHT_MODAL.SPLIT_DETAILS]: {
screens: {
[SCREENS.SPLIT_DETAILS.ROOT]: ROUTES.SPLIT_BILL_DETAILS.route,
[SCREENS.SPLIT_DETAILS.EDIT_REQUEST]: ROUTES.EDIT_SPLIT_BILL.route,
},
},
[SCREENS.RIGHT_MODAL.TASK_DETAILS]: {
Expand Down
10 changes: 0 additions & 10 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,13 @@ type MoneyRequestNavigatorParamList = {
[SCREENS.IOU_SEND.ENABLE_PAYMENTS]: undefined;
[SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: undefined;
[SCREENS.IOU_SEND.ADD_DEBIT_CARD]: undefined;
[SCREENS.MONEY_REQUEST.WAYPOINT]: {
iouType: string;
transactionID: string;
waypointIndex: string;
threadReportID: number;
};
[SCREENS.MONEY_REQUEST.STEP_DISTANCE]: {
action: IOUAction;
iouType: IOUType;
transactionID: string;
reportID: string;
backTo: Routes;
};
[SCREENS.MONEY_REQUEST.RECEIPT]: {
iouType: string;
reportID: string;
};
[SCREENS.MONEY_REQUEST.CREATE]: {
iouType: IOUType;
reportID: string;
Expand Down
63 changes: 3 additions & 60 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ function clearMoneyRequest(transactionID: string, skipConfirmation = false) {
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, null);
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function startMoneyRequest(iouType: ValueOf<typeof CONST.IOU.TYPE>, reportID: string, requestType?: IOURequestType, skipConfirmation = false) {
clearMoneyRequest(CONST.IOU.OPTIMISTIC_TRANSACTION_ID, skipConfirmation);
switch (requestType) {
Expand All @@ -345,18 +344,15 @@ function startMoneyRequest(iouType: ValueOf<typeof CONST.IOU.TYPE>, reportID: st
}
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestAmount(transactionID: string, amount: number, currency: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount, currency});
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestCreated(transactionID: string, created: string, isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {created});
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestCurrency_temporaryForRefactor(transactionID: string, currency: string, isEditing = false) {
function setMoneyRequestCurrency(transactionID: string, currency: string, isEditing = false) {
const fieldToUpdate = isEditing ? 'modifiedCurrency' : 'currency';
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {[fieldToUpdate]: currency});
}
Expand All @@ -381,13 +377,11 @@ function setMoneyRequestTag(transactionID: string, tag: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {tag});
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestBillable_temporaryForRefactor(transactionID: string, billable: boolean) {
function setMoneyRequestBillable(transactionID: string, billable: boolean) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {billable});
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestParticipants_temporaryForRefactor(transactionID: string, participants: Participant[] = []) {
function setMoneyRequestParticipants(transactionID: string, participants: Participant[] = []) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants});
}

Expand All @@ -411,29 +405,6 @@ function updateDistanceRequestRate(transactionID: string, rateID: string, policy
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {comment: {customUnit: {customUnitRateID: rateID}}});
}

/** Reset expense info from the store with its initial value */
function resetMoneyRequestInfo(id = '') {
// Disabling this line since currentDate can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const created = currentDate || format(new Date(), CONST.DATE.FNS_FORMAT_STRING);
Onyx.merge(ONYXKEYS.IOU, {
id,
amount: 0,
currency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD,
comment: '',
participants: [],
merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
category: '',
tag: '',
created,
receiptPath: '',
receiptFilename: '',
transactionID: '',
billable: null,
isSplitRequest: false,
});
}

/** Helper function to get the receipt error for expenses, or the generic error if there's no receipt */
function getReceiptError(receipt?: Receipt, filename?: string, isScanRequest = true, errorKey?: number): Errors | ErrorFields {
return isEmptyObject(receipt) || !isScanRequest
Expand Down Expand Up @@ -2899,7 +2870,6 @@ function requestMoney(

// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.write(WRITE_COMMANDS.REQUEST_MONEY, parameters, onyxData);
resetMoneyRequestInfo();
}
}

Expand Down Expand Up @@ -3068,7 +3038,6 @@ function trackExpense(
};

API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData);
resetMoneyRequestInfo();
}
}
if (action === CONST.IOU.ACTION.SHARE) {
Expand Down Expand Up @@ -3571,7 +3540,6 @@ function splitBill({

API.write(WRITE_COMMANDS.SPLIT_BILL, parameters, onyxData);

resetMoneyRequestInfo();
Navigation.dismissModal(existingSplitChatReportID);
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
}
Expand Down Expand Up @@ -3630,7 +3598,6 @@ function splitBillAndOpenReport({

API.write(WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT, parameters, onyxData);

resetMoneyRequestInfo();
Navigation.dismissModal(splitData.chatReportID);
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
}
Expand Down Expand Up @@ -3930,7 +3897,6 @@ function startSplitBill({

API.write(WRITE_COMMANDS.START_SPLIT_BILL, parameters, {optimisticData, successData, failureData});

resetMoneyRequestInfo();
Navigation.dismissModalWithReport(splitChatReport);
Report.notifyNewAction(splitChatReport.chatReportID ?? '', currentUserAccountID);
}
Expand Down Expand Up @@ -5274,7 +5240,6 @@ function sendMoneyElsewhere(report: OnyxEntry<OnyxTypes.Report>, amount: number,

API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData});

resetMoneyRequestInfo();
Navigation.dismissModal(params.chatReportID);
Report.notifyNewAction(params.chatReportID, managerID);
}
Expand All @@ -5288,7 +5253,6 @@ function sendMoneyWithWallet(report: OnyxEntry<OnyxTypes.Report>, amount: number

API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData});

resetMoneyRequestInfo();
Navigation.dismissModal(params.chatReportID);
Report.notifyNewAction(params.chatReportID, managerID);
}
Expand Down Expand Up @@ -5820,14 +5784,6 @@ function setMoneyRequestParticipantsFromReport(transactionID: string, report: On
return participants;
}

function setMoneyRequestId(id: string) {
Onyx.merge(ONYXKEYS.IOU, {id});
}

function setMoneyRequestCurrency(currency: string) {
Onyx.merge(ONYXKEYS.IOU, {currency});
}

function setMoneyRequestTaxRate(transactionID: string, taxRate: TaxRatesOption) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {taxRate});
}
Expand All @@ -5836,14 +5792,6 @@ function setMoneyRequestTaxAmount(transactionID: string, taxAmount: number, isDr
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {taxAmount});
}

function setMoneyRequestBillable(billable: boolean) {
Onyx.merge(ONYXKEYS.IOU, {billable});
}

function setMoneyRequestParticipants(participants: Participant[], isSplitRequest?: boolean) {
Onyx.merge(ONYXKEYS.IOU, {participants, isSplitRequest});
}

function setShownHoldUseExplanation() {
Onyx.set(ONYXKEYS.NVP_HOLD_USE_EXPLAINED, true);
}
Expand Down Expand Up @@ -6020,25 +5968,20 @@ export {
putOnHold,
replaceReceipt,
requestMoney,
resetMoneyRequestInfo,
savePreferredPaymentMethod,
sendMoneyElsewhere,
sendMoneyWithWallet,
setCustomUnitRateID,
setDraftSplitTransaction,
setMoneyRequestAmount,
setMoneyRequestBillable,
setMoneyRequestBillable_temporaryForRefactor,
setMoneyRequestCategory,
setMoneyRequestCreated,
setMoneyRequestCurrency,
setMoneyRequestCurrency_temporaryForRefactor,
setMoneyRequestDescription,
setMoneyRequestId,
setMoneyRequestMerchant,
setMoneyRequestParticipants,
setMoneyRequestParticipantsFromReport,
setMoneyRequestParticipants_temporaryForRefactor,
setMoneyRequestPendingFields,
setMoneyRequestReceipt,
setMoneyRequestTag,
Expand Down
56 changes: 0 additions & 56 deletions src/pages/EditRequestReceiptPage.js

This file was deleted.

Loading

0 comments on commit d8ed250

Please sign in to comment.