From 173ed3cc5b3fc8c2325e8c21c77c48591018261b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 27 Nov 2024 16:30:45 -0700 Subject: [PATCH 1/3] play sound when paying on search --- src/libs/API/types.ts | 4 ++-- src/libs/actions/Search.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index d7258f1dd49e..a9e0a7646d57 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -315,7 +315,6 @@ const WRITE_COMMANDS = { 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', @@ -763,7 +762,6 @@ 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; @@ -1025,6 +1023,7 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate', COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding', CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop', + PAY_MONEY_REQUEST_ON_SEARCH: 'PayMoneyRequestOnSearch', } as const; type SideEffectRequestCommand = ValueOf; @@ -1045,6 +1044,7 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.DISCONNECT_AS_DELEGATE]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams; + [SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH]: Parameters.PayMoneyRequestOnSearchParams; }; type ApiRequestCommandParameters = WriteCommandParameters & ReadCommandParameters & SideEffectRequestCommandParameters; diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 44b5bb7f7ce9..0a91c1dfff81 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -6,12 +6,13 @@ import type {PaymentData, SearchQueryJSON} from '@components/Search/types'; import type {ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; import * as API from '@libs/API'; import type {ExportSearchItemsToCSVParams} from '@libs/API/parameters'; -import {WRITE_COMMANDS} from '@libs/API/types'; +import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as ApiUtils from '@libs/ApiUtils'; import fileDownload from '@libs/fileDownload'; import enhanceParameters from '@libs/Network/enhanceParameters'; import * as ReportUtils from '@libs/ReportUtils'; import {isReportListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; +import playSound, {SOUNDS} from '@libs/Sound'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm'; @@ -277,7 +278,15 @@ function payMoneyRequestOnSearch(hash: number, paymentData: PaymentData[], trans const optimisticData: OnyxUpdate[] = createActionLoadingData(true); const finallyData: OnyxUpdate[] = createActionLoadingData(false); - API.write(WRITE_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH, {hash, paymentData: JSON.stringify(paymentData)}, {optimisticData, finallyData}); + // eslint-disable-next-line rulesdir/no-api-side-effects-method + API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH, {hash, paymentData: JSON.stringify(paymentData)}, {optimisticData, finallyData}).then( + (response) => { + if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) { + return; + } + playSound(SOUNDS.SUCCESS); + }, + ); } function unholdMoneyRequestOnSearch(hash: number, transactionIDList: string[]) { From ab1d89ef9cc0cf4c4b0fc0a4d623b90ea67fa6cf Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 3 Dec 2024 13:01:41 -0700 Subject: [PATCH 2/3] add comment --- src/libs/actions/Search.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index bb64fe10db26..39d38db637e2 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -281,6 +281,7 @@ function payMoneyRequestOnSearch(hash: number, paymentData: PaymentData[], trans const optimisticData: OnyxUpdate[] = createActionLoadingData(true); const finallyData: OnyxUpdate[] = createActionLoadingData(false); + // PayMoneyRequestOnSearch only works online (pattern C) and we need to play the success sound only when the request is successful // eslint-disable-next-line rulesdir/no-api-side-effects-method API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH, {hash, paymentData: JSON.stringify(paymentData)}, {optimisticData, finallyData}).then( (response) => { From 79be512e394291c1288ae64c7c60570e36e8ac5b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 3 Dec 2024 13:02:03 -0700 Subject: [PATCH 3/3] move comment --- src/libs/API/types.ts | 2 ++ src/libs/actions/Search.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index d5d24eb205bf..892bad17928e 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -1027,6 +1027,8 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate', COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding', CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop', + + // PayMoneyRequestOnSearch only works online (pattern C) and we need to play the success sound only when the request is successful PAY_MONEY_REQUEST_ON_SEARCH: 'PayMoneyRequestOnSearch', } as const; diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 39d38db637e2..bb64fe10db26 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -281,7 +281,6 @@ function payMoneyRequestOnSearch(hash: number, paymentData: PaymentData[], trans const optimisticData: OnyxUpdate[] = createActionLoadingData(true); const finallyData: OnyxUpdate[] = createActionLoadingData(false); - // PayMoneyRequestOnSearch only works online (pattern C) and we need to play the success sound only when the request is successful // eslint-disable-next-line rulesdir/no-api-side-effects-method API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH, {hash, paymentData: JSON.stringify(paymentData)}, {optimisticData, finallyData}).then( (response) => {