Skip to content

Commit

Permalink
Merge pull request #51727 from Expensify/lucien/search-money-request-…
Browse files Browse the repository at this point in the history
…actions

[Search] Handle approving and paying money requests on search
  • Loading branch information
luacmartins authored Oct 30, 2024
2 parents 4224fae + acf8c26 commit 1351038
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libs/API/parameters/ApproveMoneyRequestOnSearchParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type ApproveMoneyRequestOnSearchParams = {
hash: number;
reportIDList: string[];
};

export default ApproveMoneyRequestOnSearchParams;
11 changes: 11 additions & 0 deletions src/libs/API/parameters/PayMoneyRequestOnSearchParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type PayMoneyRequestOnSearchParams = {
hash: number;
paymentType: string;
/**
* Stringified JSON object with type of following structure:
* Array<{reportID: string, amount: number}>
*/
reportsAndAmounts: string;
};

export default PayMoneyRequestOnSearchParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ export type {default as MarkAsExportedParams} from './MarkAsExportedParams';
export type {default as UpgradeToCorporateParams} from './UpgradeToCorporateParams';
export type {default as DeleteMoneyRequestOnSearchParams} from './DeleteMoneyRequestOnSearchParams';
export type {default as HoldMoneyRequestOnSearchParams} from './HoldMoneyRequestOnSearchParams';
export type {default as ApproveMoneyRequestOnSearchParams} from './ApproveMoneyRequestOnSearchParams';
export type {default as PayMoneyRequestOnSearchParams} from './PayMoneyRequestOnSearchParams';
export type {default as UnholdMoneyRequestOnSearchParams} from './UnholdMoneyRequestOnSearchParams';
export type {default as UpdateNetSuiteSubsidiaryParams} from './UpdateNetSuiteSubsidiaryParams';
export type {default as DeletePolicyReportField} from './DeletePolicyReportField';
Expand Down
4 changes: 4 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ const WRITE_COMMANDS = {
UPGRADE_TO_CORPORATE: 'UpgradeToCorporate',
DELETE_MONEY_REQUEST_ON_SEARCH: 'DeleteMoneyRequestOnSearch',
HOLD_MONEY_REQUEST_ON_SEARCH: 'HoldMoneyRequestOnSearch',
APPROVE_MONEY_REQUEST_ON_SEARCH: 'ApproveMoneyRequestOnSearch',
PAY_MONEY_REQUEST_ON_SEARCH: 'PayMoneyRequestOnSearch',
UNHOLD_MONEY_REQUEST_ON_SEARCH: 'UnholdMoneyRequestOnSearch',
REQUEST_REFUND: 'User_RefundPurchase',
UPDATE_NETSUITE_SUBSIDIARY: 'UpdateNetSuiteSubsidiary',
Expand Down Expand Up @@ -760,6 +762,8 @@ type WriteCommandParameters = {

[WRITE_COMMANDS.DELETE_MONEY_REQUEST_ON_SEARCH]: Parameters.DeleteMoneyRequestOnSearchParams;
[WRITE_COMMANDS.HOLD_MONEY_REQUEST_ON_SEARCH]: Parameters.HoldMoneyRequestOnSearchParams;
[WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH]: Parameters.ApproveMoneyRequestOnSearchParams;
[WRITE_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH]: Parameters.PayMoneyRequestOnSearchParams;
[WRITE_COMMANDS.UNHOLD_MONEY_REQUEST_ON_SEARCH]: Parameters.UnholdMoneyRequestOnSearchParams;

[WRITE_COMMANDS.REQUEST_REFUND]: null;
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ function holdMoneyRequestOnSearch(hash: number, transactionIDList: string[], com
API.write(WRITE_COMMANDS.HOLD_MONEY_REQUEST_ON_SEARCH, {hash, transactionIDList, comment}, {optimisticData, finallyData});
}

// this function will be used once https://github.com/Expensify/App/pull/51445 is merged
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function approveMoneyRequestOnSearch(hash: number, reportIDList: string[]) {
const {optimisticData, finallyData} = getOnyxLoadingData(hash);

API.write(WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH, {hash, reportIDList}, {optimisticData, finallyData});
}

// this function will be used once https://github.com/Expensify/App/pull/51445 is merged
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function payMoneyRequestOnSearch(hash: number, paymentType: string, reportsAndAmounts: string) {
const {optimisticData, finallyData} = getOnyxLoadingData(hash);

API.write(WRITE_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH, {hash, paymentType, reportsAndAmounts}, {optimisticData, finallyData});
}

function unholdMoneyRequestOnSearch(hash: number, transactionIDList: string[]) {
const {optimisticData, finallyData} = getOnyxLoadingData(hash);

Expand Down

0 comments on commit 1351038

Please sign in to comment.