Skip to content

Commit

Permalink
Merge pull request #50571 from rezkiy37/feature/45176-invoicing-detai…
Browse files Browse the repository at this point in the history
…ls-section

Invoicing details section
  • Loading branch information
madmax330 authored Oct 29, 2024
2 parents d78be88 + dc79c38 commit 7848d60
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/libs/API/parameters/UpdateInvoiceCompanyNameParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type UpdateInvoiceCompanyNameParams = {
authToken: string;
policyID: string;
companyName: string;
};

export default UpdateInvoiceCompanyNameParams;
7 changes: 7 additions & 0 deletions src/libs/API/parameters/UpdateInvoiceCompanyWebsiteParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type UpdateInvoiceCompanyWebsiteParams = {
authToken: string;
policyID: string;
companyWebsite: string;
};

export default UpdateInvoiceCompanyWebsiteParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 5 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof WRITE_COMMANDS>;
Expand Down Expand Up @@ -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 = {
Expand Down
128 changes: 128 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import type {
SetWorkspaceAutoReportingMonthlyOffsetParams,
SetWorkspacePayerParams,
SetWorkspaceReimbursementParams,
UpdateInvoiceCompanyNameParams,
UpdateInvoiceCompanyWebsiteParams,
UpdatePolicyAddressParams,
UpdateWorkspaceAvatarParams,
UpdateWorkspaceDescriptionParams,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -4479,6 +4605,8 @@ export {
disableWorkspaceBillableExpenses,
setWorkspaceEReceiptsEnabled,
verifySetupIntentAndRequestPolicyOwnerChange,
updateInvoiceCompanyName,
updateInvoiceCompanyWebsite,
};

export type {NewCustomUnit};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,7 +32,7 @@ function WorkspaceInvoicingDetailsName({route}: WorkspaceInvoicingDetailsNamePro

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const submit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_INVOICES_COMPANY_NAME_FORM>) => {
// TODO: implement UpdateInvoiceCompanyName API call when it's supported
Policy.updateInvoiceCompanyName(policyID, values[INPUT_IDS.COMPANY_NAME]);
Navigation.goBack();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,7 +34,7 @@ function WorkspaceInvoicingDetailsWebsite({route}: WorkspaceInvoicingDetailsWebs

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const submit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_INVOICES_COMPANY_WEBSITE_FORM>) => {
// TODO: implement UpdateInvoiceCompanyWebsite API call when it's supported
Policy.updateInvoiceCompanyWebsite(policyID, values[INPUT_IDS.COMPANY_WEBSITE]);
Navigation.goBack();
};

Expand Down

0 comments on commit 7848d60

Please sign in to comment.