Skip to content

Commit

Permalink
Merge pull request #54534 from callstack-internal/chore/eslint-consis…
Browse files Browse the repository at this point in the history
…tent-id-iou

Align default IDs in IOU.ts file
  • Loading branch information
neil-marcellini authored Jan 21, 2025
2 parents c07fa50 + 4d75438 commit f40c622
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 296 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
},
overrides: [
{
files: ['src/libs/actions/IOU.ts', 'src/pages/workspace/WorkspaceInitialPage.tsx', 'src/pages/home/report/PureReportActionItem.tsx', 'src/libs/SidebarUtils.ts'],
files: ['src/pages/workspace/WorkspaceInitialPage.tsx', 'src/pages/home/report/PureReportActionItem.tsx', 'src/libs/SidebarUtils.ts'],
rules: {
'rulesdir/no-default-id-values': 'off',
},
Expand Down
12 changes: 10 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ const ROUTES = {
},
ROOM_INVITE: {
route: 'r/:reportID/invite/:role?',
getRoute: (reportID: string, role?: string, backTo?: string) => {
getRoute: (reportID: string | undefined, role?: string, backTo?: string) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the ROOM_INVITE route');
}
const route = role ? (`r/${reportID}/invite/${role}` as const) : (`r/${reportID}/invite` as const);
return getUrlWithBackToParam(route, backTo);
},
Expand Down Expand Up @@ -770,7 +773,12 @@ const ROUTES = {
},
WORKSPACE_PROFILE_ADDRESS: {
route: 'settings/workspaces/:policyID/profile/address',
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/profile/address` as const, backTo),
getRoute: (policyID: string | undefined, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the WORKSPACE_PROFILE_ADDRESS route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/profile/address` as const, backTo);
},
},
WORKSPACE_PROFILE_PLAN: {
route: 'settings/workspaces/:policyID/profile/plan',
Expand Down
12 changes: 6 additions & 6 deletions src/libs/API/parameters/CategorizeTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ type CategorizeTrackedExpenseParams = {
comment: string;
created: string;
merchant: string;
policyID: string;
transactionID: string;
moneyRequestPreviewReportActionID: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
policyID: string | undefined;
transactionID: string | undefined;
moneyRequestPreviewReportActionID: string | undefined;
moneyRequestReportID: string | undefined;
moneyRequestCreatedReportActionID: string | undefined;
actionableWhisperReportActionID: string;
modifiedExpenseReportActionID: string;
reportPreviewReportActionID: string;
reportPreviewReportActionID: string | undefined;
category?: string;
tag?: string;
receipt?: Receipt;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/CompleteSplitBillParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type CompleteSplitBillParams = {
transactionID: string;
transactionID: string | undefined;
amount?: number;
currency?: string;
created?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type ConvertTrackedExpenseToRequestParams = {
chatReportID: string;
transactionID: string;
actionableWhisperReportActionID: string;
createdChatReportActionID: string;
createdChatReportActionID?: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
moneyRequestCreatedReportActionID: string | undefined;
moneyRequestPreviewReportActionID: string;
reportPreviewReportActionID: string;
};
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/CreateDistanceRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type CreateDistanceRequestParams = {
transactionID: string;
chatReportID: string;
createdChatReportActionID: string;
createdChatReportActionID?: string;
reportActionID: string;
waypoints: string;
customUnitRateID: string;
Expand Down
6 changes: 3 additions & 3 deletions src/libs/API/parameters/CreatePerDiemRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type CreatePerDiemRequestParams = {
chatReportID: string;
transactionID: string;
reportActionID: string;
createdChatReportActionID: string;
createdIOUReportActionID: string;
createdChatReportActionID?: string;
createdIOUReportActionID?: string;
reportPreviewReportActionID: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
};

export default CreatePerDiemRequestParams;
2 changes: 1 addition & 1 deletion src/libs/API/parameters/DeleteMoneyRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type DeleteMoneyRequestParams = {
transactionID: string;
transactionID: string | undefined;
reportActionID: string;
};

Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/PayInvoiceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type CreateWorkspaceParams from './CreateWorkspaceParams';

type PayInvoiceParams = Partial<CreateWorkspaceParams> & {
reportID: string;
reportID: string | undefined;
reportActionID: string;
paymentMethodType: PaymentMethodType;
payAsBusiness: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/PayMoneyRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type PayMoneyRequestParams = {
iouReportID: string;
iouReportID: string | undefined;
chatReportID: string;
reportActionID: string;
paymentMethodType: PaymentMethodType;
Expand Down
6 changes: 3 additions & 3 deletions src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type RequestMoneyParams = {
chatReportID: string;
transactionID: string;
reportActionID: string;
createdChatReportActionID: string;
createdIOUReportActionID: string;
createdChatReportActionID?: string;
createdIOUReportActionID?: string;
reportPreviewReportActionID: string;
receipt?: Receipt;
receiptState?: ValueOf<typeof CONST.IOU.RECEIPT_STATE>;
Expand All @@ -26,7 +26,7 @@ type RequestMoneyParams = {
billable?: boolean;
receiptGpsPoints?: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
reimbursible?: boolean;
};

Expand Down
4 changes: 2 additions & 2 deletions src/libs/API/parameters/SendInvoiceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {RequireAtLeastOne} from 'type-fest';

type SendInvoiceParams = RequireAtLeastOne<
{
senderWorkspaceID: string;
senderWorkspaceID: string | undefined;
accountID: number;
receiverEmail?: string;
receiverInvoiceRoomID?: string;
Expand All @@ -21,7 +21,7 @@ type SendInvoiceParams = RequireAtLeastOne<
companyName?: string;
companyWebsite?: string;
createdIOUReportActionID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
reportActionID: string;
},
'receiverEmail' | 'receiverInvoiceRoomID'
Expand Down
4 changes: 2 additions & 2 deletions src/libs/API/parameters/SendMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ type SendMoneyParams = {
paymentMethodType: PaymentMethodType;
transactionID: string;
newIOUReportDetails: string;
createdReportActionID: string;
createdReportActionID: string | undefined;
reportPreviewReportActionID: string;
createdIOUReportActionID: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
createdReportActionIDForThread: string | undefined;
};

export default SendMoneyParams;
12 changes: 6 additions & 6 deletions src/libs/API/parameters/ShareTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ type ShareTrackedExpenseParams = {
comment: string;
created: string;
merchant: string;
policyID: string;
transactionID: string;
moneyRequestPreviewReportActionID: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
policyID: string | undefined;
transactionID: string | undefined;
moneyRequestPreviewReportActionID: string | undefined;
moneyRequestReportID: string | undefined;
moneyRequestCreatedReportActionID: string | undefined;
actionableWhisperReportActionID: string;
modifiedExpenseReportActionID: string;
reportPreviewReportActionID: string;
reportPreviewReportActionID: string | undefined;
category?: string;
tag?: string;
receipt?: Receipt;
Expand Down
12 changes: 6 additions & 6 deletions src/libs/API/parameters/TrackExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type TrackExpenseParams = {
created: string;
merchant: string;
iouReportID?: string;
chatReportID: string;
transactionID: string;
reportActionID: string;
createdChatReportActionID: string;
chatReportID: string | undefined;
transactionID: string | undefined;
reportActionID: string | undefined;
createdChatReportActionID?: string;
createdIOUReportActionID?: string;
reportPreviewReportActionID?: string;
receipt?: Receipt;
Expand All @@ -23,8 +23,8 @@ type TrackExpenseParams = {
taxAmount: number;
billable?: boolean;
receiptGpsPoints?: string;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
transactionThreadReportID: string | undefined;
createdReportActionIDForThread: string | undefined;
waypoints?: string;
actionableWhisperReportActionID?: string;
customUnitRateID?: string;
Expand Down
5 changes: 4 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,10 @@ function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry<ReportAction
/**
* Get IOU action for a reportID and transactionID
*/
function getIOUActionForReportID(reportID: string, transactionID: string): OnyxEntry<ReportAction> {
function getIOUActionForReportID(reportID: string | undefined, transactionID: string): OnyxEntry<ReportAction> {
if (!reportID) {
return;
}
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const reportActions = getAllReportActions(report?.reportID);
const action = Object.values(reportActions ?? {})?.find((reportAction) => {
Expand Down
28 changes: 17 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ Onyx.connect({

reportsTransactions = Object.values(value).reduce<Record<string, Transaction[]>>((all, transaction) => {
const reportsMap = all;
if (!transaction) {
if (!transaction?.reportID) {
return reportsMap;
}

Expand Down Expand Up @@ -3191,6 +3191,10 @@ function getReportFieldKey(reportFieldId: string | undefined) {
* Get the report fields attached to the policy given policyID
*/
function getReportFieldsByPolicyID(policyID: string | undefined): Record<string, PolicyReportField> {
if (!policyID) {
return {};
}

const policyReportFields = Object.entries(allPolicies ?? {}).find(([key]) => key.replace(ONYXKEYS.COLLECTION.POLICY, '') === policyID);
const fieldList = policyReportFields?.[1]?.fieldList;

Expand Down Expand Up @@ -4801,7 +4805,7 @@ function buildOptimisticIOUReport(
payeeAccountID: number,
payerAccountID: number,
total: number,
chatReportID: string,
chatReportID: string | undefined,
currency: string,
isSendingMoney = false,
parentReportActionID?: string,
Expand Down Expand Up @@ -4873,7 +4877,14 @@ function populateOptimisticReportFormula(formula: string, report: OptimisticExpe
}

/** Builds an optimistic invoice report with a randomly generated reportID */
function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, receiverAccountID: number, receiverName: string, total: number, currency: string): OptimisticExpenseReport {
function buildOptimisticInvoiceReport(
chatReportID: string,
policyID: string | undefined,
receiverAccountID: number,
receiverName: string,
total: number,
currency: string,
): OptimisticExpenseReport {
const formattedTotal = convertToDisplayString(total, currency);
const invoiceReport = {
reportID: generateReportID(),
Expand Down Expand Up @@ -4945,8 +4956,8 @@ function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>) {
* @param parentReportActionID – The parent ReportActionID of the PolicyExpenseChat
*/
function buildOptimisticExpenseReport(
chatReportID: string,
policyID: string,
chatReportID: string | undefined,
policyID: string | undefined,
payeeAccountID: number,
total: number,
currency: string,
Expand Down Expand Up @@ -5547,7 +5558,7 @@ function buildOptimisticModifiedExpenseReportAction(
* @param transactionThreadID - The reportID of the transaction thread
* @param movedToReportID - The reportID of the report the transaction is moved to
*/
function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction {
function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string | undefined, movedToReportID: string | undefined): OptimisticModifiedExpenseReportAction {
const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);

return {
Expand Down Expand Up @@ -8581,10 +8592,6 @@ function canReportBeMentionedWithinPolicy(report: OnyxEntry<Report>, policyID: s
return isChatRoom(report) && !isInvoiceRoom(report) && !isThread(report);
}

function shouldShowMerchantColumn(transactions: Transaction[]) {
return transactions.some((transaction) => isExpenseReport(allReports?.[transaction.reportID] ?? null));
}

/**
* Whether a given report is used for onboarding tasks. In the past, it could be either the Concierge chat or the system
* DM, and we saved the report ID in the user's `onboarding` NVP. As a fallback for users who don't have the NVP, we now
Expand Down Expand Up @@ -9123,7 +9130,6 @@ export {
getTripIDFromTransactionParentReportID,
buildOptimisticInvoiceReport,
getInvoiceChatByParticipants,
shouldShowMerchantColumn,
isCurrentUserInvoiceReceiver,
isDraftReport,
changeMoneyRequestHoldStatus,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import getDistanceInMeters from './getDistanceInMeters';
type TransactionParams = {
amount: number;
currency: string;
reportID: string;
reportID: string | undefined;
comment?: string;
attendees?: Attendee[];
created?: string;
Expand Down
12 changes: 6 additions & 6 deletions src/libs/TripReservationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import type {Reservation, ReservationType} from '@src/types/onyx/Transaction';
import type Transaction from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import * as Link from './actions/Link';
import {openTravelDotLink} from './actions/Link';
import Log from './Log';
import Navigation from './Navigation/Navigation';
import * as PolicyUtils from './PolicyUtils';
import {getPolicy} from './PolicyUtils';

let travelSettings: OnyxEntry<TravelSettings>;
Onyx.connect({
Expand Down Expand Up @@ -65,7 +65,7 @@ function getTripReservationIcon(reservationType?: ReservationType): IconAsset {
}
}

type ReservationData = {reservation: Reservation; transactionID: string; reportID: string; reservationIndex: number};
type ReservationData = {reservation: Reservation; transactionID: string; reportID: string | undefined; reservationIndex: number};

function getReservationsFromTripTransactions(transactions: Transaction[]): ReservationData[] {
return transactions
Expand Down Expand Up @@ -100,9 +100,9 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag
setCtaErrorMessage(translate('travel.phoneError'));
return;
}
const policy = PolicyUtils.getPolicy(activePolicyID);
const policy = getPolicy(activePolicyID);
if (isEmptyObject(policy?.address)) {
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_ADDRESS.getRoute(activePolicyID ?? '-1', Navigation.getActiveRoute()));
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_ADDRESS.getRoute(activePolicyID, Navigation.getActiveRoute()));
return;
}
if (!travelSettings?.hasAcceptedTerms) {
Expand All @@ -112,7 +112,7 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag
if (ctaErrorMessage) {
setCtaErrorMessage('');
}
Link.openTravelDotLink(activePolicyID)
openTravelDotLink(activePolicyID)
?.then(() => {
if (!NativeModules.HybridAppModule || !isSingleNewDotEntry) {
return;
Expand Down
Loading

0 comments on commit f40c622

Please sign in to comment.