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: resolve module and cycle mutation issues in peek overview, issue sidebar and empty state #3466

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
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: 34 additions & 12 deletions web/components/issues/issue-detail/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,23 @@ export const IssueDetailRoot: FC<TIssueDetailRoot> = (props) => {
},
addIssueToCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => {
try {
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
})
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the cycle. Please try again.",
});
});
} catch (error) {
setToastAlert({
title: "Cycle add to issue failed",
Expand All @@ -152,12 +163,23 @@ export const IssueDetailRoot: FC<TIssueDetailRoot> = (props) => {
},
addIssueToModule: async (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) => {
try {
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
})
.catch(() =>
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the module. Please try again.",
})
);
} catch (error) {
setToastAlert({
title: "Module add to issue failed",
Expand Down
21 changes: 14 additions & 7 deletions web/components/issues/issue-layouts/empty-states/cycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from "react";
import { observer } from "mobx-react-lite";
import { PlusIcon } from "lucide-react";
// hooks
import { useApplication, useIssues, useUser } from "hooks/store";
import { useApplication, useIssueDetail, useIssues, useUser } from "hooks/store";
import useToast from "hooks/use-toast";
// components
import { EmptyState } from "components/common";
Expand All @@ -29,6 +29,7 @@ export const CycleEmptyState: React.FC<Props> = observer((props) => {
const [cycleIssuesListModal, setCycleIssuesListModal] = useState(false);
// store hooks
const { issues } = useIssues(EIssuesStoreType.CYCLE);
const { updateIssue, fetchIssue } = useIssueDetail();
const {
commandPalette: { toggleCreateIssueModal },
eventTracker: { setTrackElement },
Expand All @@ -44,13 +45,19 @@ export const CycleEmptyState: React.FC<Props> = observer((props) => {

const issueIds = data.map((i) => i.id);

await issues.addIssueToCycle(workspaceSlug.toString(), projectId, cycleId.toString(), issueIds).catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the cycle. Please try again.",
await issues
.addIssueToCycle(workspaceSlug.toString(), projectId, cycleId.toString(), issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
})
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the cycle. Please try again.",
});
});
});
};

const isEditingAllowed = !!userRole && userRole >= EUserProjectRoles.MEMBER;
Expand Down
9 changes: 7 additions & 2 deletions web/components/issues/issue-layouts/empty-states/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from "react";
import { observer } from "mobx-react-lite";
import { PlusIcon } from "lucide-react";
// hooks
import { useApplication, useIssues, useUser } from "hooks/store";
import { useApplication, useIssueDetail, useIssues, useUser } from "hooks/store";
import useToast from "hooks/use-toast";
// components
import { EmptyState } from "components/common";
Expand All @@ -29,6 +29,8 @@ export const ModuleEmptyState: React.FC<Props> = observer((props) => {
const [moduleIssuesListModal, setModuleIssuesListModal] = useState(false);
// store hooks
const { issues } = useIssues(EIssuesStoreType.MODULE);
const { updateIssue, fetchIssue } = useIssueDetail();

const {
commandPalette: { toggleCreateIssueModal },
eventTracker: { setTrackElement },
Expand All @@ -43,9 +45,12 @@ export const ModuleEmptyState: React.FC<Props> = observer((props) => {
if (!workspaceSlug || !projectId || !moduleId) return;

const issueIds = data.map((i) => i.id);

await issues
.addIssueToModule(workspaceSlug.toString(), projectId?.toString(), moduleId.toString(), issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
})
.catch(() =>
setToastAlert({
type: "error",
Expand Down
46 changes: 34 additions & 12 deletions web/components/issues/peek-overview/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,23 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
addIssueToCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => {
try {
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Cycle added to issue successfully",
type: "success",
message: "Issue added to issue successfully",
});
})
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the cycle. Please try again.",
});
});
} catch (error) {
setToastAlert({
title: "Cycle add to issue failed",
Expand All @@ -145,12 +156,23 @@ export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
},
addIssueToModule: async (workspaceSlug: string, projectId: string, moduleId: string, issueIds: string[]) => {
try {
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
await addIssueToModule(workspaceSlug, projectId, moduleId, issueIds)
.then((res) => {
updateIssue(workspaceSlug, projectId, res.id, res);
fetchIssue(workspaceSlug, projectId, res.id);
setToastAlert({
title: "Module added to issue successfully",
type: "success",
message: "Module added to issue successfully",
});
})
.catch(() =>
setToastAlert({
type: "error",
title: "Error!",
message: "Selected issues could not be added to the module. Please try again.",
})
);
} catch (error) {
setToastAlert({
title: "Module add to issue failed",
Expand Down
Loading