Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix workspace name showing previous name #45820

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1094,23 +1105,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,
Expand Down
Loading