diff --git a/src/libs/API/parameters/UpdateInvoiceCompanyNameParams.ts b/src/libs/API/parameters/UpdateInvoiceCompanyNameParams.ts new file mode 100644 index 000000000000..15cc73c12cb1 --- /dev/null +++ b/src/libs/API/parameters/UpdateInvoiceCompanyNameParams.ts @@ -0,0 +1,7 @@ +type UpdateInvoiceCompanyNameParams = { + authToken: string; + policyID: string; + companyName: string; +}; + +export default UpdateInvoiceCompanyNameParams; diff --git a/src/libs/API/parameters/UpdateInvoiceCompanyWebsiteParams.ts b/src/libs/API/parameters/UpdateInvoiceCompanyWebsiteParams.ts new file mode 100644 index 000000000000..68087364d05c --- /dev/null +++ b/src/libs/API/parameters/UpdateInvoiceCompanyWebsiteParams.ts @@ -0,0 +1,7 @@ +type UpdateInvoiceCompanyWebsiteParams = { + authToken: string; + policyID: string; + companyWebsite: string; +}; + +export default UpdateInvoiceCompanyWebsiteParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 4c12a236a43c..c64c7f09dbdc 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -340,5 +340,7 @@ export type {default as SetPersonalDetailsAndShipExpensifyCardsParams} from './S export type {default as RequestFeedSetupParams} from './RequestFeedSetupParams'; export type {default as SetInvoicingTransferBankAccountParams} from './SetInvoicingTransferBankAccountParams'; export type {default as ConnectPolicyToQuickBooksDesktopParams} from './ConnectPolicyToQuickBooksDesktopParams'; +export type {default as UpdateInvoiceCompanyNameParams} from './UpdateInvoiceCompanyNameParams'; +export type {default as UpdateInvoiceCompanyWebsiteParams} from './UpdateInvoiceCompanyWebsiteParams'; export type {default as UpdateQuickbooksDesktopExpensesExportDestinationTypeParams} from './UpdateQuickbooksDesktopExpensesExportDestinationTypeParams'; export type {default as UpdateQuickbooksDesktopCompanyCardExpenseAccountTypeParams} from './UpdateQuickbooksDesktopCompanyCardExpenseAccountTypeParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 22bf33c0c22a..2dff17822681 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -431,6 +431,8 @@ const WRITE_COMMANDS = { SET_CARD_EXPORT_ACCOUNT: 'SetCardExportAccount', SET_PERSONAL_DETAILS_AND_SHIP_EXPENSIFY_CARDS: 'SetPersonalDetailsAndShipExpensifyCards', SET_INVOICING_TRANSFER_BANK_ACCOUNT: 'SetInvoicingTransferBankAccount', + UPDATE_INVOICE_COMPANY_NAME: 'UpdateInvoiceCompanyName', + UPDATE_INVOICE_COMPANY_WEBSITE: 'UpdateInvoiceCompanyWebsite', } as const; type WriteCommand = ValueOf; @@ -871,7 +873,10 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_XERO_SYNC_SYNC_REIMBURSED_REPORTS]: Parameters.UpdateXeroGenericTypeParams; [WRITE_COMMANDS.UPDATE_XERO_SYNC_REIMBURSEMENT_ACCOUNT_ID]: Parameters.UpdateXeroGenericTypeParams; + // Invoice API [WRITE_COMMANDS.SET_INVOICING_TRANSFER_BANK_ACCOUNT]: Parameters.SetInvoicingTransferBankAccountParams; + [WRITE_COMMANDS.UPDATE_INVOICE_COMPANY_NAME]: Parameters.UpdateInvoiceCompanyNameParams; + [WRITE_COMMANDS.UPDATE_INVOICE_COMPANY_WEBSITE]: Parameters.UpdateInvoiceCompanyWebsiteParams; }; const READ_COMMANDS = { diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 7d4e10f08c4e..b419431bbbb3 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -49,6 +49,8 @@ import type { SetWorkspaceAutoReportingMonthlyOffsetParams, SetWorkspacePayerParams, SetWorkspaceReimbursementParams, + UpdateInvoiceCompanyNameParams, + UpdateInvoiceCompanyWebsiteParams, UpdatePolicyAddressParams, UpdateWorkspaceAvatarParams, UpdateWorkspaceDescriptionParams, @@ -4385,6 +4387,130 @@ function clearAllPolicies() { Object.keys(allPolicies).forEach((key) => delete allPolicies[key]); } +function updateInvoiceCompanyName(policyID: string, companyName: string) { + const authToken = NetworkStore.getAuthToken(); + + if (!authToken) { + return; + } + + const policy = getPolicy(policyID); + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + invoice: { + companyName, + pendingFields: { + companyName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + invoice: { + pendingFields: { + companyName: null, + }, + }, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + invoice: { + companyName: policy?.invoice?.companyName, + pendingFields: { + companyName: null, + }, + }, + }, + }, + ]; + + const parameters: UpdateInvoiceCompanyNameParams = { + authToken, + policyID, + companyName, + }; + + API.write(WRITE_COMMANDS.UPDATE_INVOICE_COMPANY_NAME, parameters, {optimisticData, successData, failureData}); +} + +function updateInvoiceCompanyWebsite(policyID: string, companyWebsite: string) { + const authToken = NetworkStore.getAuthToken(); + + if (!authToken) { + return; + } + + const policy = getPolicy(policyID); + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + invoice: { + companyWebsite, + pendingFields: { + companyWebsite: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + invoice: { + pendingFields: { + companyWebsite: null, + }, + }, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + invoice: { + companyWebsite: policy?.invoice?.companyWebsite, + pendingFields: { + companyWebsite: null, + }, + }, + }, + }, + ]; + + const parameters: UpdateInvoiceCompanyWebsiteParams = { + authToken, + policyID, + companyWebsite, + }; + + API.write(WRITE_COMMANDS.UPDATE_INVOICE_COMPANY_WEBSITE, parameters, {optimisticData, successData, failureData}); +} + export { leaveWorkspace, addBillingCardAndRequestPolicyOwnerChange, @@ -4479,6 +4605,8 @@ export { disableWorkspaceBillableExpenses, setWorkspaceEReceiptsEnabled, verifySetupIntentAndRequestPolicyOwnerChange, + updateInvoiceCompanyName, + updateInvoiceCompanyWebsite, }; export type {NewCustomUnit}; diff --git a/src/pages/workspace/invoices/WorkspaceInvoicingDetailsName.tsx b/src/pages/workspace/invoices/WorkspaceInvoicingDetailsName.tsx index 80f323431baa..2b933a4ab695 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoicingDetailsName.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoicingDetailsName.tsx @@ -14,6 +14,7 @@ import * as ValidationUtils from '@libs/ValidationUtils'; import Navigation from '@navigation/Navigation'; import type {SettingsNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; +import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -31,7 +32,7 @@ function WorkspaceInvoicingDetailsName({route}: WorkspaceInvoicingDetailsNamePro // eslint-disable-next-line @typescript-eslint/no-unused-vars const submit = (values: FormOnyxValues) => { - // TODO: implement UpdateInvoiceCompanyName API call when it's supported + Policy.updateInvoiceCompanyName(policyID, values[INPUT_IDS.COMPANY_NAME]); Navigation.goBack(); }; diff --git a/src/pages/workspace/invoices/WorkspaceInvoicingDetailsWebsite.tsx b/src/pages/workspace/invoices/WorkspaceInvoicingDetailsWebsite.tsx index 0427aef81db3..cd2f559da3fa 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoicingDetailsWebsite.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoicingDetailsWebsite.tsx @@ -16,6 +16,7 @@ import * as ValidationUtils from '@libs/ValidationUtils'; import Navigation from '@navigation/Navigation'; import type {SettingsNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; +import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -33,7 +34,7 @@ function WorkspaceInvoicingDetailsWebsite({route}: WorkspaceInvoicingDetailsWebs // eslint-disable-next-line @typescript-eslint/no-unused-vars const submit = (values: FormOnyxValues) => { - // TODO: implement UpdateInvoiceCompanyWebsite API call when it's supported + Policy.updateInvoiceCompanyWebsite(policyID, values[INPUT_IDS.COMPANY_WEBSITE]); Navigation.goBack(); };