Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
55 changes: 30 additions & 25 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import ReceiptGeneric from '@assets/images/receipt-generic.png';

import type {LocaleContextProps} from '@components/LocaleContextProvider';

import * as API from '@libs/API';
import type {CompleteSplitBillParams, CreateDistanceRequestParams, SplitBillParams, StartSplitBillParams} from '@libs/API/parameters';
import {WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
import {deferOrExecuteWrite} from '@libs/deferredLayoutWrite';
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import {calculateAmount as calculateIOUAmount, updateIOUOwnerAndTotal} from '@libs/IOUUtils';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import * as Localize from '@libs/Localize';
import Navigation from '@libs/Navigation/Navigation';
import TransitionTracker from '@libs/Navigation/TransitionTracker';
Expand Down Expand Up @@ -168,6 +169,7 @@
participantsPolicyTags: Record<string, OnyxTypes.PolicyTagLists>;
delegateAccountID: number | undefined;
isTrackIntentUser: boolean | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
};

type StartSplitBilActionParams = {
Expand All @@ -193,22 +195,7 @@
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
policyRecentlyUsedCurrencies: string[];
participantsPolicyTags: Record<string, OnyxTypes.PolicyTagLists>;
delegateAccountID: number | undefined;
};

type CompleteSplitBillActionParams = {
chatReportID: string;
reportAction: OnyxEntry<OnyxTypes.ReportAction>;
updatedTransaction: OnyxEntry<OnyxTypes.Transaction>;
sessionAccountID: number;
isASAPSubmitBetaEnabled: boolean;
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
delegateAccountID: number | undefined;
isTrackIntentUser: boolean | undefined;
sessionEmail?: string;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
};

type SplitBillActionsParams = {
Expand Down Expand Up @@ -243,6 +230,21 @@
shouldDeferForSearch?: boolean;
delegateAccountID: number | undefined;
isTrackIntentUser: boolean | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
};

type CompleteSplitBillInformation = {
chatReportID: string;
reportAction: OnyxEntry<OnyxTypes.ReportAction>;
updatedTransaction: OnyxEntry<OnyxTypes.Transaction>;
sessionAccountID: number;
isASAPSubmitBetaEnabled: boolean;
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
isTrackIntentUser: boolean | undefined;
sessionEmail?: string;
};

/**
Expand Down Expand Up @@ -280,6 +282,7 @@
shouldDeferForSearch = false,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
}: SplitBillActionsParams) {
const parsedComment = getParsedComment(comment);
const {splitData, splits, onyxData} = createSplitsAndOnyxData({
Expand Down Expand Up @@ -315,6 +318,7 @@
participantsPolicyTags: buildParticipantsPolicyTags(participants),
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
});

const parameters: SplitBillParams = {
Expand Down Expand Up @@ -394,6 +398,7 @@
shouldDeferForSearch = false,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
}: SplitBillActionsParams) {
const parsedComment = getParsedComment(comment);
const {splitData, splits, onyxData} = createSplitsAndOnyxData({
Expand Down Expand Up @@ -429,6 +434,7 @@
participantsPolicyTags: buildParticipantsPolicyTags(participants),
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
});

const parameters: SplitBillParams = {
Expand Down Expand Up @@ -501,7 +507,7 @@
participantsPolicyTags,
shouldHandleNavigation = true,
shouldDeferForSearch = false,
delegateAccountID,
formatPhoneNumber,
Comment thread
marufsharifi marked this conversation as resolved.
}: StartSplitBilActionParams) {
const currentUserEmailForIOUSplit = addSMSDomainIfPhoneNumber(currentUserLogin);
const participantAccountIDs = participants.map((participant) => Number(participant.accountID));
Expand Down Expand Up @@ -543,7 +549,7 @@
transactionID: splitTransaction.transactionID,
isOwnPolicyExpenseChat,
iouReportID: splitChatReport.reportID,
delegateAccountIDParam: delegateAccountID,
delegateAccountIDParam: undefined,
});

splitChatReport.lastReadTime = DateUtils.getDBTime();
Expand Down Expand Up @@ -692,7 +698,6 @@
policyRecentlyUsedCurrencies,
policyRecentlyUsedTags,
participantsPolicyTags,
delegateAccountID,
};

if (existingSplitChatReport) {
Expand All @@ -701,7 +706,7 @@
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`,
value: {
[splitIOUReportAction.reportActionID]: {
errors: getReceiptError(receipt, filename, undefined, undefined, CONST.IOU.ACTION_PARAMS.START_SPLIT_BILL, retryParams),

Check failure on line 709 in src/libs/actions/IOU/Split.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ participants: { accountID?: number; login?: string; displayName?: string; isPolicyExpenseChat?: boolean; isInvoiceRoom?: boolean; isOwnPolicyExpenseChat?: boolean; chatType?: ValueOf<typeof CONST.REPORT.CHAT_TYPE>; ... 16 more ...; avatar?: AvatarSource; }[]; ... 16 more ...; participantsPolicyTags: Record<...>; }' is not assignable to parameter of type 'StartSplitBilActionParams | CreateTrackExpenseParams | RequestMoneyInformation | ReplaceReceiptRetryParams | undefined'.
},
},
});
Expand All @@ -724,7 +729,7 @@
errors: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'),
},
[splitIOUReportAction.reportActionID]: {
errors: getReceiptError(receipt, filename, undefined, undefined, CONST.IOU.ACTION_PARAMS.START_SPLIT_BILL, retryParams),

Check failure on line 732 in src/libs/actions/IOU/Split.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ participants: { accountID?: number; login?: string; displayName?: string; isPolicyExpenseChat?: boolean; isInvoiceRoom?: boolean; isOwnPolicyExpenseChat?: boolean; chatType?: ValueOf<typeof CONST.REPORT.CHAT_TYPE>; ... 16 more ...; avatar?: AvatarSource; }[]; ... 16 more ...; participantsPolicyTags: Record<...>; }' is not assignable to parameter of type 'StartSplitBilActionParams | CreateTrackExpenseParams | RequestMoneyInformation | ReplaceReceiptRetryParams | undefined'.
},
},
},
Expand Down Expand Up @@ -890,10 +895,9 @@
transactionViolations,
betas,
personalDetails,
delegateAccountID,
isTrackIntentUser,
sessionEmail,
}: CompleteSplitBillActionParams) {
}: CompleteSplitBillInformation) {
if (!reportAction) {
return;
}
Expand Down Expand Up @@ -1096,14 +1100,14 @@
participants: [participant],
transactionID: oneOnOneTransaction.transactionID,
currentUserAccountID: sessionAccountID,
delegateAccountIDParam: delegateAccountID,
delegateAccountIDParam: undefined,
});

let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport?.reportID, oneOnOneIOUReport?.reportID);
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
} else {
oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction, undefined, undefined, delegateAccountID);
oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction, undefined, undefined, undefined);
}
const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations, sessionAccountID, sessionEmail ?? '');

Expand Down Expand Up @@ -1139,7 +1143,7 @@
},
quickAction,
personalDetails,
delegateAccountID,
delegateAccountID: undefined,
isTrackIntentUser,
});

Expand Down Expand Up @@ -1424,6 +1428,7 @@
participantsPolicyTags,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
}: CreateSplitsAndOnyxDataParams): SplitsAndOnyxData {
const currentUserEmailForIOUSplit = addSMSDomainIfPhoneNumber(currentUserLogin);
const participantAccountIDs = participants.map((participant) => Number(participant.accountID));
Expand Down Expand Up @@ -2017,7 +2022,7 @@
splitData,
splits,
onyxData: splitOnyxData,
} = createSplitsAndOnyxData({

Check failure on line 2025 in src/libs/actions/IOU/Split.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ participants: Participant[]; currentUserLogin: string; currentUserAccountID: number; existingSplitChatReportID: string | undefined; transactionParams: { amount: number; ... 12 more ...; attendees: Attendee[] | undefined; }; ... 10 more ...; isTrackIntentUser: boolean | undefined; }' is not assignable to parameter of type 'CreateSplitsAndOnyxDataParams'.
participants,
currentUserLogin: currentUserLogin ?? '',
currentUserAccountID,
Expand Down
14 changes: 8 additions & 6 deletions src/libs/actions/IOU/SplitTransactionUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import type {SearchActionsContextValue, SearchStateContextValue} from '@components/Search/types';

import {write as apiWrite} from '@libs/API';
Expand Down Expand Up @@ -107,8 +108,8 @@
transactionReport: OnyxEntry<OnyxTypes.Report>;
expenseReport: OnyxEntry<OnyxTypes.Report>;
isOffline: boolean;
delegateAccountID: number | undefined;
isTrackIntentUser: boolean | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
};

function updateSplitTransactions({
Expand Down Expand Up @@ -137,8 +138,8 @@
transactionReport,
expenseReport: expenseReportFromParams,
isOffline,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
}: UpdateSplitTransactionsParams) {
const parentTransactionReport = getReportOrDraftReport(transactionReport?.parentReportID);
// For selfDM-origin splits the caller can't resolve a real `expenseReport` (the draft/source
Expand Down Expand Up @@ -594,7 +595,7 @@
policyRecentlyUsedCurrencies,
betas,
personalDetails,
delegateAccountID,
delegateAccountID: undefined,
isTrackIntentUser,
} as MoneyRequestInformationParams;

Expand Down Expand Up @@ -708,8 +709,9 @@
policyRecentlyUsedCurrencies,
betas,
personalDetails,
delegateAccountID,
delegateAccountID: undefined,
isTrackIntentUser,
formatPhoneNumber,

Check failure on line 714 in src/libs/actions/IOU/SplitTransactionUpdate.ts

View workflow job for this annotation

GitHub Actions / typecheck

Object literal may only specify known properties, and 'formatPhoneNumber' does not exist in type 'MoneyRequestInformationParams'.
});

let updateMoneyRequestParamsOnyxData: OnyxData<UpdateMoneyRequestDataKeys> = {};
Expand Down Expand Up @@ -804,7 +806,7 @@
isSplitTransaction: true,
isSelfDMSplit,
isOffline,
delegateAccountID,
delegateAccountID: undefined,
isTrackIntentUser,
});
if (currentSplit) {
Expand Down Expand Up @@ -885,7 +887,7 @@
actorAccountID: commentAction.actorAccountID,
reportID: transactionThreadReportID,
reportActionID: newReportActionID,
delegateAccountIDParam: delegateAccountID,
delegateAccountIDParam: undefined,
});
const reportActionComment = {
...reportComment.reportAction,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Travel/TravelLegalNamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import useThemeStyles from '@hooks/useThemeStyles';

import {clearDraftValues} from '@libs/actions/FormActions';
import {updateLegalName} from '@libs/actions/PersonalDetails';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Navigation from '@libs/Navigation/Navigation';

import BaseLegalNamePage, {validateLegalName} from '@pages/settings/Profile/PersonalDetails/BaseLegalNamePage';
Expand All @@ -19,7 +18,7 @@ import INPUT_IDS from '@src/types/form/PersonalDetailsForm';
import React, {useEffect} from 'react';

function TravelLegalNamePage() {
const {translate} = useLocalize();
const {translate, formatPhoneNumber} = useLocalize();
const styles = useThemeStyles();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID,

const [transactions] = useOptimisticDraftTransactions(transaction);
const {isMultiScanEnabled} = useMultiScanState();
const {translate} = useLocalize();
const {translate, formatPhoneNumber} = useLocalize();
const {disableMultiScan} = useMultiScanActions();
const {setIsLoaderVisible} = useFullScreenLoaderActions();
const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false);
Expand Down Expand Up @@ -235,6 +235,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID,
...splitBaseParams,
shouldHandleNavigation: overrides.shouldHandleNavigation,
shouldDeferForSearch: false,
formatPhoneNumber,
});
cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, {
report,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
} = params;

// Localization
const {translate, toLocaleDigit} = useLocalize();
const {translate, toLocaleDigit, formatPhoneNumber} = useLocalize();
const delegateAccountID = useDelegateAccountID();

// Permissions
Expand Down Expand Up @@ -612,6 +612,7 @@
personalDetails,
optimisticChatReportID,
isTrackIntentUser,
formatPhoneNumber,

Check failure on line 615 in src/pages/iou/request/step/confirmation/useExpenseSubmission.ts

View workflow job for this annotation

GitHub Actions / typecheck

Object literal may only specify known properties, and 'formatPhoneNumber' does not exist in type 'PerDiemExpenseInformation'.
});
const targetReportID = backToReport ?? activeReportID;
// When backToReport exists we are creating the expense from chat, not the expense report, so no pending transaction registration needed.
Expand Down Expand Up @@ -874,7 +875,8 @@
participantsPolicyTags,
shouldHandleNavigation,
shouldDeferForSearch: shouldDeferSplitForSearch,
formatPhoneNumber,
delegateAccountID,

Check failure on line 879 in src/pages/iou/request/step/confirmation/useExpenseSubmission.ts

View workflow job for this annotation

GitHub Actions / typecheck

Object literal may only specify known properties, and 'delegateAccountID' does not exist in type 'StartSplitBilActionParams'.
});
}
}
Expand Down Expand Up @@ -917,6 +919,7 @@
shouldDeferForSearch: shouldDeferSplitForSearch,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
});
}
markSubmitExpenseEnd();
Expand Down Expand Up @@ -956,6 +959,7 @@
shouldDeferForSearch: shouldDeferSplitForSearch,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
});
}
markSubmitExpenseEnd();
Expand All @@ -980,6 +984,7 @@
isFromGlobalCreate: getIsFromGlobalCreate(transaction),
policyRecentlyUsedTags,
senderPolicyTags: senderWorkspacePolicyTags ?? {},
formatPhoneNumber,

Check failure on line 987 in src/pages/iou/request/step/confirmation/useExpenseSubmission.ts

View workflow job for this annotation

GitHub Actions / typecheck

Object literal may only specify known properties, and 'formatPhoneNumber' does not exist in type 'SendInvoiceOptions'.
});
if (shouldHandleNavigation) {
cleanupAndNavigateAfterExpenseCreate({
Expand Down
2 changes: 2 additions & 0 deletions tests/actions/IOU/SplitReportTotalsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ describe('actions/IOU', () => {
participantsPolicyTags: overrides.participantsPolicyTags ?? {},
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

it('returns valid splitData with chatReportID, transactionID, and reportActionID', () => {
Expand Down Expand Up @@ -772,6 +773,7 @@ describe('actions/IOU', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
...overrides,
};
}
Expand Down
6 changes: 6 additions & 0 deletions tests/actions/IOUTest/SplitSelfDMTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -311,6 +312,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -422,6 +424,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -518,6 +521,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -580,6 +584,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -673,6 +678,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => {
isOffline: false,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber: (n: string) => n,
});

await waitForBatchedUpdates();
Expand Down
Loading
Loading