From 81c7e014fa3cf10431487e3255ce2a244004f75c Mon Sep 17 00:00:00 2001 From: Huu Le Date: Sat, 20 Jul 2024 14:40:54 +0700 Subject: [PATCH 1/2] fix workspace name showing previous name --- src/libs/actions/Policy/Policy.ts | 33 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index af233a47fa39..7c36782fa707 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -1094,23 +1094,26 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s }; const persistedRequests = PersistedRequests.getAll(); + const createWorkspaceRequestChangedIndex = persistedRequests.findIndex( + (request) => request.data?.policyID === policyID && request.command === WRITE_COMMANDS.CREATE_WORKSPACE && request.data?.policyName !== name, + ); - persistedRequests.forEach((request, index) => { - const {command, data} = request; + const createWorkspaceRequest = persistedRequests[createWorkspaceRequestChangedIndex]; + if (createWorkspaceRequest) { + const workspaceRequest: Request = { + ...createWorkspaceRequest, + data: { + ...createWorkspaceRequest.data, + policyName: name, + }, + }; + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { + name, + }); - if (command === WRITE_COMMANDS.CREATE_WORKSPACE && data?.policyID === policyID) { - if (data.policyName !== name) { - const createWorkspaceRequest = { - ...request, - data: { - ...data, - policyName: name, - }, - }; - PersistedRequests.update(index, createWorkspaceRequest); - } - } - }); + PersistedRequests.update(createWorkspaceRequestChangedIndex, workspaceRequest); + return; + } API.write(WRITE_COMMANDS.UPDATE_WORKSPACE_GENERAL_SETTINGS, params, { optimisticData, From e0581a8c59a3083e0d3e432c8b8f4d199ef1b778 Mon Sep 17 00:00:00 2001 From: Huu Le Date: Sat, 20 Jul 2024 16:18:50 +0700 Subject: [PATCH 2/2] import request type for CreateWorkspace request --- src/libs/actions/Policy/Policy.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 7c36782fa707..53f33c4fd3d7 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -60,7 +60,18 @@ import type {PolicySelector} from '@pages/home/sidebar/SidebarScreen/FloatingAct import * as PersistedRequests from '@userActions/PersistedRequests'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, PolicyCategory, ReimbursementAccount, Report, ReportAction, TaxRatesWithDefault, Transaction} from '@src/types/onyx'; +import type { + InvitedEmailsToAccountIDs, + PersonalDetailsList, + Policy, + PolicyCategory, + ReimbursementAccount, + Report, + ReportAction, + Request, + TaxRatesWithDefault, + Transaction, +} from '@src/types/onyx'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import type {Attributes, CompanyAddress, CustomUnit, Rate, TaxRate, Unit} from '@src/types/onyx/Policy'; import type {OnyxData} from '@src/types/onyx/Request';