Skip to content

Commit 42a0980

Browse files
chore: code refactoring
1 parent 373b67a commit 42a0980

File tree

1 file changed

+22
-17
lines changed
  • apps/web/core/components/issues/issue-modal

1 file changed

+22
-17
lines changed

apps/web/core/components/issues/issue-modal/base.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,13 @@ export const CreateUpdateIssueModalBase = observer(function CreateUpdateIssueMod
267267
// - cycle_id is the same as the current cycle id
268268
if (!("cycle_id" in payload) || isEqual(data?.cycle_id, payload.cycle_id)) return;
269269

270+
const slug = workspaceSlug.toString();
271+
270272
// Removing the cycle
271273
const currentCycleId = data?.cycle_id;
272274
if (currentCycleId && payload.cycle_id === null) {
273-
await issues.removeIssueFromCycle(workspaceSlug, data.project_id, currentCycleId, data.id);
274-
fetchCycleDetails(workspaceSlug, data.project_id, currentCycleId).catch((error) => {
275+
await issues.removeIssueFromCycle(slug, data.project_id, currentCycleId, data.id);
276+
fetchCycleDetails(slug, data.project_id, currentCycleId).catch((error) => {
275277
console.error(error);
276278
});
277279
}
@@ -309,7 +311,13 @@ export const CreateUpdateIssueModalBase = observer(function CreateUpdateIssueMod
309311
}
310312
// update modules if there are modules to add or remove
311313
if (modulesToAdd.length > 0 || modulesToRemove.length > 0) {
312-
await issues.changeModulesInIssue(workspaceSlug, data.project_id, data.id, modulesToAdd, modulesToRemove);
314+
await issues.changeModulesInIssue(
315+
workspaceSlug.toString(),
316+
data.project_id,
317+
data.id,
318+
modulesToAdd,
319+
modulesToRemove
320+
);
313321
}
314322
};
315323

@@ -320,20 +328,17 @@ export const CreateUpdateIssueModalBase = observer(function CreateUpdateIssueMod
320328
if (isDraft) await draftIssues.updateIssue(workspaceSlug.toString(), data.id, payload);
321329
else if (updateIssue) await updateIssue(payload.project_id, data.id, payload);
322330

323-
await Promise.all([
324-
// handle cycle change
325-
handleCycleChange(data, payload),
326-
// handle module change
327-
handleModuleChange(data, payload),
328-
// handle other property values
329-
handleCreateUpdatePropertyValues({
330-
issueId: data.id,
331-
issueTypeId: payload.type_id,
332-
projectId: payload.project_id,
333-
workspaceSlug: workspaceSlug?.toString(),
334-
isDraft: isDraft,
335-
}),
336-
]);
331+
// Run cycle, module, and property changes sequentially to avoid
332+
// optimistic store writes from racing against each other.
333+
await handleCycleChange(data, payload);
334+
await handleModuleChange(data, payload);
335+
await handleCreateUpdatePropertyValues({
336+
issueId: data.id,
337+
issueTypeId: payload.type_id,
338+
projectId: payload.project_id,
339+
workspaceSlug: workspaceSlug?.toString(),
340+
isDraft: isDraft,
341+
});
337342

338343
setToast({
339344
type: TOAST_TYPE.SUCCESS,

0 commit comments

Comments
 (0)