Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type {LocaleContextProps} from '@components/LocaleContextProvider';

import * as API from '@libs/API';
import type {SendInvoiceParams} 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 {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Log from '@libs/Log';
import {getReportActionHtml, getReportActionText} from '@libs/ReportActionsUtils';
import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction} from '@libs/ReportUtils';
Expand Down Expand Up @@ -85,6 +86,7 @@ type SendInvoiceOptions = {
policyRecentlyUsedTags?: OnyxEntry<OnyxTypes.RecentlyUsedTags>;
isFromGlobalCreate?: boolean;
senderPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
// TODO: delegateAccountID will be made required in PR 12 when all callers pass the value (https://github.com/Expensify/App/issues/66425)
delegateAccountID?: number | undefined;
};
Expand Down Expand Up @@ -590,6 +592,7 @@ function getSendInvoiceInformation({
policyRecentlyUsedCategories,
policyRecentlyUsedTags,
senderPolicyTags,
formatPhoneNumber,
delegateAccountID,
}: SendInvoiceOptions): SendInvoiceInformation {
const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, taxValue, billable, comment, participants} = transaction ?? {};
Expand Down Expand Up @@ -739,6 +742,7 @@ function sendInvoice({
policyRecentlyUsedTags,
isFromGlobalCreate = false,
senderPolicyTags,
formatPhoneNumber,
delegateAccountID,
}: SendInvoiceOptions) {
const parsedComment = getParsedComment(transaction?.comment?.comment?.trim() ?? '');
Expand Down Expand Up @@ -774,6 +778,7 @@ function sendInvoice({
policyRecentlyUsedCategories,
policyRecentlyUsedTags,
senderPolicyTags: senderPolicyTags ?? {},
formatPhoneNumber,
delegateAccountID,
});

Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/request/step/IOURequestStepCompanyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function IOURequestStepCompanyInfo({route, report, transaction}: IOURequestStepC
const {backTo, reportID} = route.params;

const styles = useThemeStyles();
const {translate} = useLocalize();
const {translate, formatPhoneNumber} = useLocalize();
const {convertToDisplayString} = useCurrencyListActions();
const {inputCallbackRef} = useAutoFocusInput();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
Expand Down Expand Up @@ -120,6 +120,7 @@ function IOURequestStepCompanyInfo({route, report, transaction}: IOURequestStepC
policyRecentlyUsedTags,
isFromGlobalCreate,
senderPolicyTags: policyTags ?? {},
formatPhoneNumber,
});
cleanupAndNavigateAfterExpenseCreate({
report: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
} = params;

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

// Permissions
Expand Down Expand Up @@ -1019,6 +1019,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
isFromGlobalCreate: getIsFromGlobalCreate(transaction),
policyRecentlyUsedTags,
senderPolicyTags: senderWorkspacePolicyTags ?? {},
formatPhoneNumber,
});
if (shouldHandleNavigation) {
cleanupAndNavigateAfterExpenseCreate({
Expand Down
17 changes: 16 additions & 1 deletion tests/actions/IOUTest/SendInvoiceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import createRandomPolicy from '../../utils/collections/policies';
import createRandomTransaction from '../../utils/collections/transaction';
import getOnyxValue from '../../utils/getOnyxValue';
import initCurrencyListContext from '../../utils/initCurrencyListContext';
import {getGlobalFetchMock} from '../../utils/TestHelper';
import {formatPhoneNumber, getGlobalFetchMock} from '../../utils/TestHelper';
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';

const topMostReportID = '23423423';
Expand Down Expand Up @@ -172,6 +172,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: undefined,
policyRecentlyUsedCategories: existingRecentlyUsedCategories,
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

// Then: Verify optimistic data is generated when policyRecentlyUsedCategories are provided
Expand All @@ -197,6 +198,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: undefined,
policyRecentlyUsedCategories: undefined,
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

expect(result.onyxData.optimisticData).toBeDefined();
Expand Down Expand Up @@ -248,6 +250,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: 'https://testcompany.com',
policyRecentlyUsedCategories: ['Services', 'Consulting'],
senderPolicyTags: mockPolicyTagList as PolicyTagLists,
formatPhoneNumber,
});

// Then: Verify the result structure and key values
Expand Down Expand Up @@ -325,6 +328,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: 'https://clientcompany.com',
policyRecentlyUsedCategories: [],
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

// Then: Verify the result uses existing chat report
Expand Down Expand Up @@ -361,6 +365,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: undefined,
policyRecentlyUsedCategories: [],
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

// Then: Verify receipt handling
Expand Down Expand Up @@ -410,6 +415,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: undefined,
policyRecentlyUsedCategories: [],
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

// Then: Verify function handles missing data gracefully
Expand Down Expand Up @@ -440,6 +446,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: undefined,
policyRecentlyUsedCategories: [],
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

expect(result.invoiceRoom).toBeDefined();
Expand Down Expand Up @@ -492,6 +499,7 @@ describe('actions/SendInvoice', () => {
companyWebsite: undefined,
policyRecentlyUsedCategories: [],
senderPolicyTags: baseSenderPolicyTags,
formatPhoneNumber,
});

expect(result.invoiceRoom).toBeDefined();
Expand Down Expand Up @@ -545,6 +553,7 @@ describe('actions/SendInvoice', () => {
policyRecentlyUsedCurrencies: [],
policyRecentlyUsedTags,
senderPolicyTags: senderPolicyTags ?? {},
formatPhoneNumber,
});

// Then: optimisticData should contain a POLICY_RECENTLY_USED_TAGS update with the transaction tag prepended
Expand Down Expand Up @@ -592,6 +601,7 @@ describe('actions/SendInvoice', () => {
currentUserAccountID: 123,
policyRecentlyUsedCurrencies: [],
senderPolicyTags: senderPolicyTags ?? {},
formatPhoneNumber,
});

// Then: No POLICY_RECENTLY_USED_TAGS update should be in optimisticData
Expand Down Expand Up @@ -624,6 +634,7 @@ describe('actions/SendInvoice', () => {
companyName,
companyWebsite,
senderPolicyTags: undefined,
formatPhoneNumber,
});

// Then a new invoice chat is created instead of incorrectly using the invoice chat which has been converted from individual to business
Expand Down Expand Up @@ -652,6 +663,7 @@ describe('actions/SendInvoice', () => {
transaction,
policyRecentlyUsedCurrencies: initialCurrencies,
senderPolicyTags: undefined,
formatPhoneNumber,
});

mockFetch?.fail?.();
Expand Down Expand Up @@ -692,6 +704,7 @@ describe('actions/SendInvoice', () => {
policyRecentlyUsedCurrencies: [],
policyRecentlyUsedCategories,
senderPolicyTags: undefined,
formatPhoneNumber,
});

// Then onyxData should be passed to API.write
Expand Down Expand Up @@ -733,6 +746,7 @@ describe('actions/SendInvoice', () => {
orderWeight: 0,
},
},
formatPhoneNumber,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -768,6 +782,7 @@ describe('actions/SendInvoice', () => {
policyRecentlyUsedCurrencies: [],
invoiceChatReportID: preGeneratedReportID,
senderPolicyTags: undefined,
formatPhoneNumber,
});

expect(writeSpy).toHaveBeenCalledWith(
Expand Down
Loading