Skip to content

Commit

Permalink
fix the logic (#5807)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharma01ketan authored Oct 17, 2024
1 parent 173b49b commit 9530884
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PlusIcon } from "lucide-react";
// types
import { ISearchIssueResponse, TIssue } from "@plane/types";
// ui
import { TOAST_TYPE, setToast, CustomMenu } from "@plane/ui";
import { CustomMenu, setPromiseToast } from "@plane/ui";
// components
import { ExistingIssuesListModal } from "@/components/core";
import { QuickAddIssueRoot } from "@/components/issues";
Expand Down Expand Up @@ -45,22 +45,21 @@ export const CalendarQuickAddIssueActions: FC<TCalendarQuickAddIssueActions> = o
if (!workspaceSlug || !projectId) return;

const issueIds = data.map((i) => i.id);
const addExistingIssuesPromise = Promise.all(
data.map((issue) => updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, prePopulatedData ?? {}))
).then(() => addIssuesToView?.(issueIds));

try {
// To handle all updates in parallel
await Promise.all(
data.map((issue) =>
updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, prePopulatedData ?? {})
)
);
await addIssuesToView?.(issueIds);
} catch (error) {
setToast({
type: TOAST_TYPE.ERROR,
setPromiseToast(addExistingIssuesPromise, {
loading: `Adding ${issueIds.length > 1 ? "issues" : "issue"} to cycle...`,
success: {
title: "Success!",
message: () => `${issueIds.length > 1 ? "Issues" : "Issue"} added to cycle successfully.`,
},
error: {
title: "Error!",
message: "Something went wrong. Please try again.",
});
}
message: (err) => err?.message || "Something went wrong. Please try again.",
},
});
};

const handleNewIssue = () => {
Expand Down Expand Up @@ -130,4 +129,4 @@ export const CalendarQuickAddIssueActions: FC<TCalendarQuickAddIssueActions> = o
/>
</>
);
});
});

0 comments on commit 9530884

Please sign in to comment.