From 756978b8238032163b783c4a90cb064bf8119d7b Mon Sep 17 00:00:00 2001 From: layacat Date: Tue, 3 Dec 2024 16:37:08 +0700 Subject: [PATCH] Refactor delegate action handling by moving optimistic reset action code from connect function to addDelegate function. This change improves the management of validation state during delegate actions, ensuring a consistent user experience. --- src/libs/actions/Delegate.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index 1204064f2565..f7ba61a1e842 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -91,15 +91,6 @@ function connect(email: string) { }, ]; - const optimisticResetActionCode = { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.VALIDATE_ACTION_CODE, - value: { - validateCodeSent: null, - }, - }; - successData.push(optimisticResetActionCode); - failureData.push(optimisticResetActionCode); // We need to access the authToken directly from the response to update the session // eslint-disable-next-line rulesdir/no-api-side-effects-method API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_AS_DELEGATE, {to: email}, {optimisticData, successData, failureData}) @@ -339,6 +330,16 @@ function addDelegate(email: string, role: DelegateRole, validateCode: string) { }, ]; + const optimisticResetActionCode = { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.VALIDATE_ACTION_CODE, + value: { + validateCodeSent: null, + }, + }; + successData.push(optimisticResetActionCode); + failureData.push(optimisticResetActionCode); + const parameters: AddDelegateParams = {delegate: email, validateCode, role}; API.write(WRITE_COMMANDS.ADD_DELEGATE, parameters, {optimisticData, successData, failureData});