fix: leave project fixes

This commit is contained in:
sriramveeraghanta 2023-09-25 20:09:39 +05:30
parent 9831418a11
commit 2b419c02a5
7 changed files with 93 additions and 137 deletions

View File

@ -1,15 +1,7 @@
import React from "react"; import React from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { mutate } from "swr";
// react-hook-form
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
// headless ui
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
// services
import projectService from "services/project.service";
// hooks // hooks
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
// icons // icons
@ -17,16 +9,14 @@ import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
// ui // ui
import { DangerButton, Input, SecondaryButton } from "components/ui"; import { DangerButton, Input, SecondaryButton } from "components/ui";
// types // types
import type { ICurrentUserResponse, IProject } from "types"; import type { IProject } from "types";
// fetch-keys // fetch-keys
import { PROJECTS_LIST } from "constants/fetch-keys"; import { useMobxStore } from "lib/mobx/store-provider";
type TConfirmProjectDeletionProps = { type DeleteProjectModal = {
isOpen: boolean; isOpen: boolean;
project: IProject;
onClose: () => void; onClose: () => void;
onSuccess?: () => void;
data: IProject | null;
user: ICurrentUserResponse | undefined;
}; };
const defaultValues = { const defaultValues = {
@ -34,18 +24,16 @@ const defaultValues = {
confirmDelete: "", confirmDelete: "",
}; };
export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({ export const DeleteProjectModal: React.FC<DeleteProjectModal> = (props) => {
isOpen, const { isOpen, project, onClose } = props;
data, // store
onClose, const { project: projectStore } = useMobxStore();
onSuccess, // router
user,
}) => {
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
// toast
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
// form info
const { const {
control, control,
formState: { isSubmitting }, formState: { isSubmitting },
@ -54,8 +42,7 @@ export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({
watch, watch,
} = useForm({ defaultValues }); } = useForm({ defaultValues });
const canDelete = const canDelete = watch("projectName") === project?.name && watch("confirmDelete") === "delete my project";
watch("projectName") === data?.name && watch("confirmDelete") === "delete my project";
const handleClose = () => { const handleClose = () => {
const timer = setTimeout(() => { const timer = setTimeout(() => {
@ -67,30 +54,20 @@ export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({
}; };
const onSubmit = async () => { const onSubmit = async () => {
if (!data || !workspaceSlug || !canDelete) return; if (!workspaceSlug || !canDelete) return;
await projectService await projectStore
.deleteProject(workspaceSlug.toString(), data.id, user) .deleteProject(workspaceSlug.toString(), project.id)
.then(() => { .then(() => {
handleClose(); handleClose();
mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug.toString(), { is_favorite: "all" }),
(prevData) => prevData?.filter((project: IProject) => project.id !== data.id),
false
);
if (onSuccess) onSuccess();
if (projectId && projectId === data.id) router.push(`/${workspaceSlug}/projects`);
}) })
.catch(() => .catch(() => {
setToastAlert({ setToastAlert({
type: "error", type: "error",
title: "Error!", title: "Error!",
message: "Something went wrong. Please try again later.", message: "Something went wrong. Please try again later.",
}) });
); });
}; };
return ( return (
@ -123,10 +100,7 @@ export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-6 p-6"> <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-6 p-6">
<div className="flex w-full items-center justify-start gap-6"> <div className="flex w-full items-center justify-start gap-6">
<span className="place-items-center rounded-full bg-red-500/20 p-4"> <span className="place-items-center rounded-full bg-red-500/20 p-4">
<ExclamationTriangleIcon <ExclamationTriangleIcon className="h-6 w-6 text-red-600" aria-hidden="true" />
className="h-6 w-6 text-red-600"
aria-hidden="true"
/>
</span> </span>
<span className="flex items-center justify-start"> <span className="flex items-center justify-start">
<h3 className="text-xl font-medium 2xl:text-2xl">Delete Project</h3> <h3 className="text-xl font-medium 2xl:text-2xl">Delete Project</h3>
@ -135,16 +109,14 @@ export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({
<span> <span>
<p className="text-sm leading-7 text-custom-text-200"> <p className="text-sm leading-7 text-custom-text-200">
Are you sure you want to delete project{" "} Are you sure you want to delete project{" "}
<span className="break-words font-semibold">{data?.name}</span>? All of the <span className="break-words font-semibold">{project?.name}</span>? All of the data related to the
data related to the project will be permanently removed. This action cannot be project will be permanently removed. This action cannot be undone
undone
</p> </p>
</span> </span>
<div className="text-custom-text-200"> <div className="text-custom-text-200">
<p className="break-words text-sm "> <p className="break-words text-sm ">
Enter the project name{" "} Enter the project name <span className="font-medium text-custom-text-100">{project?.name}</span>{" "}
<span className="font-medium text-custom-text-100">{data?.name}</span> to to continue:
continue:
</p> </p>
<Controller <Controller
control={control} control={control}
@ -162,8 +134,7 @@ export const DeleteProjectModal: React.FC<TConfirmProjectDeletionProps> = ({
</div> </div>
<div className="text-custom-text-200"> <div className="text-custom-text-200">
<p className="text-sm"> <p className="text-sm">
To confirm, type{" "} To confirm, type <span className="font-medium text-custom-text-100">delete my project</span>{" "}
<span className="font-medium text-custom-text-100">delete my project</span>{" "}
below: below:
</p> </p>
<Controller <Controller

View File

@ -1,4 +1,4 @@
import { FC } from "react"; import { FC, Fragment } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
@ -29,7 +29,14 @@ const defaultValues: FormData = {
confirmLeave: "", confirmLeave: "",
}; };
export const LeaveProjectModal: FC<> = observer(() => { export interface ILeaveProjectModal {
project: IProject;
isOpen: boolean;
onClose: () => void;
}
export const LeaveProjectModal: FC<ILeaveProjectModal> = observer((props) => {
const { project, isOpen, onClose } = props;
// router // router
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query; const { workspaceSlug } = router.query;
@ -50,22 +57,18 @@ export const LeaveProjectModal: FC<> = observer(() => {
} = useForm({ defaultValues }); } = useForm({ defaultValues });
const handleClose = () => { const handleClose = () => {
projectStore.handleProjectLeaveModal(null);
reset({ ...defaultValues }); reset({ ...defaultValues });
}; };
const onSubmit = async (data: any) => { const onSubmit = async (data: any) => {
if (!workspaceSlug) return;
if (data) { if (data) {
if (data.projectName === projectStore?.projectLeaveDetails?.name) { if (data.projectName === project?.name) {
if (data.confirmLeave === "Leave Project") { if (data.confirmLeave === "Leave Project") {
return projectStore return projectStore
.leaveProject( .leaveProject(workspaceSlug.toString(), project.id)
projectStore.projectLeaveDetails.workspaceSlug.toString(),
projectStore.projectLeaveDetails.id.toString(),
user
)
.then((res) => { .then((res) => {
mutateProjects();
handleClose(); handleClose();
router.push(`/${workspaceSlug}/projects`); router.push(`/${workspaceSlug}/projects`);
}) })
@ -100,10 +103,10 @@ export const LeaveProjectModal: FC<> = observer(() => {
}; };
return ( return (
<Transition.Root show={projectStore.projectLeaveModal} as={React.Fragment}> <Transition.Root show={isOpen} as={Fragment}>
<Dialog as="div" className="relative z-20" onClose={handleClose}> <Dialog as="div" className="relative z-20" onClose={handleClose}>
<Transition.Child <Transition.Child
as={React.Fragment} as={Fragment}
enter="ease-out duration-300" enter="ease-out duration-300"
enterFrom="opacity-0" enterFrom="opacity-0"
enterTo="opacity-100" enterTo="opacity-100"
@ -117,7 +120,7 @@ export const LeaveProjectModal: FC<> = observer(() => {
<div className="fixed inset-0 z-20 overflow-y-auto"> <div className="fixed inset-0 z-20 overflow-y-auto">
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0"> <div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<Transition.Child <Transition.Child
as={React.Fragment} as={Fragment}
enter="ease-out duration-300" enter="ease-out duration-300"
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enterTo="opacity-100 translate-y-0 sm:scale-100" enterTo="opacity-100 translate-y-0 sm:scale-100"
@ -139,16 +142,15 @@ export const LeaveProjectModal: FC<> = observer(() => {
<span> <span>
<p className="text-sm leading-7 text-custom-text-200"> <p className="text-sm leading-7 text-custom-text-200">
Are you sure you want to leave the project - Are you sure you want to leave the project -
<span className="font-medium text-custom-text-100">{` "${project?.projectLeaveDetails?.name}" `}</span> <span className="font-medium text-custom-text-100">{` "${project?.name}" `}</span>? All of the
? All of the issues associated with you will become inaccessible. issues associated with you will become inaccessible.
</p> </p>
</span> </span>
<div className="text-custom-text-200"> <div className="text-custom-text-200">
<p className="break-words text-sm "> <p className="break-words text-sm ">
Enter the project name{" "} Enter the project name <span className="font-medium text-custom-text-100">{project?.name}</span>{" "}
<span className="font-medium text-custom-text-100">{project?.projectLeaveDetails?.name}</span> to to continue:
continue:
</p> </p>
<Controller <Controller
control={control} control={control}

View File

@ -1,16 +1,9 @@
import { useState } from "react"; import { useState } from "react";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { mutate } from "swr";
import { DraggableProvided, DraggableStateSnapshot } from "react-beautiful-dnd"; import { DraggableProvided, DraggableStateSnapshot } from "react-beautiful-dnd";
import { Disclosure, Transition } from "@headlessui/react"; import { Disclosure, Transition } from "@headlessui/react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
// services
import projectService from "services/project.service";
// hooks
import useToast from "hooks/use-toast";
// ui
import { CustomMenu, Icon, Tooltip } from "components/ui";
// icons // icons
import { EllipsisVerticalIcon, LinkIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline"; import { EllipsisVerticalIcon, LinkIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline";
import { import {
@ -23,24 +16,26 @@ import {
PhotoFilterOutlined, PhotoFilterOutlined,
SettingsOutlined, SettingsOutlined,
} from "@mui/icons-material"; } from "@mui/icons-material";
// hooks
import useToast from "hooks/use-toast";
// ui
import { CustomMenu, Icon, Tooltip } from "components/ui";
import { PenSquare } from "lucide-react"; import { PenSquare } from "lucide-react";
// helpers // helpers
import { renderEmoji } from "helpers/emoji.helper"; import { renderEmoji } from "helpers/emoji.helper";
// types // types
import { IProject } from "types"; import { IProject } from "types";
// fetch-keys
import { PROJECTS_LIST } from "constants/fetch-keys";
// mobx store // mobx store
import { useMobxStore } from "lib/mobx/store-provider"; import { useMobxStore } from "lib/mobx/store-provider";
import { RootStore } from "store/root"; import { RootStore } from "store/root";
import { LeaveProjectModal } from "./leave-project-modal"; // components
import { LeaveProjectModal, DeleteProjectModal } from "components/project";
type Props = { type Props = {
project: IProject; project: IProject;
sidebarCollapse: boolean; sidebarCollapse: boolean;
provided?: DraggableProvided; provided?: DraggableProvided;
snapshot?: DraggableStateSnapshot; snapshot?: DraggableStateSnapshot;
handleDeleteProject: () => void;
handleCopyText: () => void; handleCopyText: () => void;
shortContextMenu?: boolean; shortContextMenu?: boolean;
}; };
@ -79,15 +74,7 @@ const navigation = (workspaceSlug: string, projectId: string) => [
]; ];
export const ProjectSidebarListItem: React.FC<Props> = observer((props) => { export const ProjectSidebarListItem: React.FC<Props> = observer((props) => {
const { const { project, sidebarCollapse, provided, snapshot, handleCopyText, shortContextMenu = false } = props;
project,
sidebarCollapse,
provided,
snapshot,
handleDeleteProject,
handleCopyText,
shortContextMenu = false,
} = props;
// store // store
const { projectPublish, project: projectStore }: RootStore = useMobxStore(); const { projectPublish, project: projectStore }: RootStore = useMobxStore();
// router // router
@ -97,6 +84,7 @@ export const ProjectSidebarListItem: React.FC<Props> = observer((props) => {
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
// states // states
const [leaveProjectModalOpen, setLeaveProjectModal] = useState(false); const [leaveProjectModalOpen, setLeaveProjectModal] = useState(false);
const [deleteProjectModalOpen, setDeleteProjectModal] = useState(false);
const isAdmin = project.member_role === 20; const isAdmin = project.member_role === 20;
const isViewerOrGuest = project.member_role === 10 || project.member_role === 5; const isViewerOrGuest = project.member_role === 10 || project.member_role === 5;
@ -129,9 +117,23 @@ export const ProjectSidebarListItem: React.FC<Props> = observer((props) => {
setLeaveProjectModal(true); setLeaveProjectModal(true);
}; };
const handleLeaveProjectModalClose = () => {
setLeaveProjectModal(false);
};
const handleDeleteProjectClick = () => {
setDeleteProjectModal(true);
};
const handleDeleteProjectModalClose = () => {
setDeleteProjectModal(false);
router.push(`/${workspaceSlug}/projects`);
};
return ( return (
<> <>
<LeaveProjectModal project={project} isOpen={leaveProjectModalOpen} onClose={} /> <DeleteProjectModal project={project} isOpen={deleteProjectModalOpen} onClose={handleDeleteProjectModalClose} />
<LeaveProjectModal project={project} isOpen={leaveProjectModalOpen} onClose={handleLeaveProjectModalClose} />
<Disclosure key={project.id} defaultOpen={projectId === project.id}> <Disclosure key={project.id} defaultOpen={projectId === project.id}>
{({ open }) => ( {({ open }) => (
<> <>
@ -205,7 +207,7 @@ export const ProjectSidebarListItem: React.FC<Props> = observer((props) => {
ellipsis ellipsis
> >
{!shortContextMenu && isAdmin && ( {!shortContextMenu && isAdmin && (
<CustomMenu.MenuItem onClick={handleDeleteProject}> <CustomMenu.MenuItem onClick={handleDeleteProjectClick}>
<span className="flex items-center justify-start gap-2 "> <span className="flex items-center justify-start gap-2 ">
<TrashIcon className="h-4 w-4" /> <TrashIcon className="h-4 w-4" />
<span>Delete project</span> <span>Delete project</span>

View File

@ -9,7 +9,7 @@ import useToast from "hooks/use-toast";
import useUserAuth from "hooks/use-user-auth"; import useUserAuth from "hooks/use-user-auth";
import useProjects from "hooks/use-projects"; import useProjects from "hooks/use-projects";
// components // components
import { CreateProjectModal, DeleteProjectModal, ProjectSidebarListItem, LeaveProjectModal } from "components/project"; import { CreateProjectModal, ProjectSidebarListItem, LeaveProjectModal } from "components/project";
import { PublishProjectModal } from "components/project/publish-project/modal"; import { PublishProjectModal } from "components/project/publish-project/modal";
// services // services
import projectService from "services/project.service"; import projectService from "services/project.service";
@ -119,14 +119,6 @@ export const ProjectSidebarList: FC = observer(() => {
setToFavorite={isFavoriteProjectCreate} setToFavorite={isFavoriteProjectCreate}
user={user} user={user}
/> />
<DeleteProjectModal
isOpen={deleteProjectModal}
onClose={() => setDeleteProjectModal(false)}
data={projectToDelete}
user={user}
/>
{/* project leave modal */}
<LeaveProjectModal />
{/* publish project modal */} {/* publish project modal */}
<PublishProjectModal /> <PublishProjectModal />
<div <div
@ -183,7 +175,6 @@ export const ProjectSidebarList: FC = observer(() => {
sidebarCollapse={themeStore?.sidebarCollapsed || false} sidebarCollapse={themeStore?.sidebarCollapsed || false}
provided={provided} provided={provided}
snapshot={snapshot} snapshot={snapshot}
handleDeleteProject={() => handleDeleteProject(project)}
handleCopyText={() => handleCopyText(project.id)} handleCopyText={() => handleCopyText(project.id)}
shortContextMenu shortContextMenu
/> />
@ -252,7 +243,6 @@ export const ProjectSidebarList: FC = observer(() => {
sidebarCollapse={themeStore?.sidebarCollapsed || false} sidebarCollapse={themeStore?.sidebarCollapsed || false}
provided={provided} provided={provided}
snapshot={snapshot} snapshot={snapshot}
handleDeleteProject={() => handleDeleteProject(project)}
handleCopyText={() => handleCopyText(project.id)} handleCopyText={() => handleCopyText(project.id)}
/> />
</div> </div>

View File

@ -12,14 +12,7 @@ import useToast from "hooks/use-toast";
// ui // ui
import { CustomMenu, Tooltip } from "components/ui"; import { CustomMenu, Tooltip } from "components/ui";
// icons // icons
import { import { CalendarDaysIcon, LinkIcon, PencilIcon, PlusIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline";
CalendarDaysIcon,
LinkIcon,
PencilIcon,
PlusIcon,
StarIcon,
TrashIcon,
} from "@heroicons/react/24/outline";
// helpers // helpers
import { renderShortDateWithYearFormat } from "helpers/date-time.helper"; import { renderShortDateWithYearFormat } from "helpers/date-time.helper";
import { copyTextToClipboard, truncateText } from "helpers/string.helper"; import { copyTextToClipboard, truncateText } from "helpers/string.helper";
@ -35,11 +28,7 @@ export type ProjectCardProps = {
setDeleteProject: (id: string | null) => void; setDeleteProject: (id: string | null) => void;
}; };
export const SingleProjectCard: React.FC<ProjectCardProps> = ({ export const SingleProjectCard: React.FC<ProjectCardProps> = ({ project, setToJoinProject, setDeleteProject }) => {
project,
setToJoinProject,
setDeleteProject,
}) => {
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query; const { workspaceSlug } = router.query;
@ -53,15 +42,12 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => (prevData) => (prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: true } : p)),
(prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: true } : p)),
false false
); );
projectService projectService
.addProjectToFavorites(workspaceSlug as string, { .addProjectToFavorites(workspaceSlug as string, project.id)
project: project.id,
})
.then(() => { .then(() => {
setToastAlert({ setToastAlert({
type: "success", type: "success",
@ -83,8 +69,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
mutate<IProject[]>( mutate<IProject[]>(
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }), PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
(prevData) => (prevData) => (prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: false } : p)),
(prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: false } : p)),
false false
); );
@ -107,8 +92,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
}; };
const handleCopyText = () => { const handleCopyText = () => {
const originURL = const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${project.id}/issues`).then(() => { copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${project.id}/issues`).then(() => {
setToastAlert({ setToastAlert({
@ -148,9 +132,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
<span>Select to Join</span> <span>Select to Join</span>
</button> </button>
) : ( ) : (
<span className="cursor-default rounded bg-green-600 px-2 py-1 text-xs"> <span className="cursor-default rounded bg-green-600 px-2 py-1 text-xs">Member</span>
Member
</span>
)} )}
{project.is_favorite && ( {project.is_favorite && (
<span className="grid h-6 w-9 cursor-default place-items-center rounded bg-orange-400"> <span className="grid h-6 w-9 cursor-default place-items-center rounded bg-orange-400">
@ -174,9 +156,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
renderEmoji(project.icon_prop) renderEmoji(project.icon_prop)
) : null} ) : null}
</div> </div>
<p className="mt-3.5 mb-7 break-words"> <p className="mt-3.5 mb-7 break-words">{truncateText(project.description ?? "", 100)}</p>
{truncateText(project.description ?? "", 100)}
</p>
</a> </a>
</Link> </Link>
<div className="flex h-full items-end justify-between"> <div className="flex h-full items-end justify-between">

View File

@ -87,7 +87,7 @@ export class ProjectService extends APIService {
}); });
} }
async deleteProject(workspaceSlug: string, projectId: string, user: ICurrentUserResponse | undefined): Promise<any> { async deleteProject(workspaceSlug: string, projectId: string, user: any | undefined): Promise<any> {
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/`) return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/`)
.then((response) => { .then((response) => {
trackEventServices.trackProjectEvent({ projectId }, "DELETE_PROJECT", user); trackEventServices.trackProjectEvent({ projectId }, "DELETE_PROJECT", user);
@ -132,7 +132,7 @@ export class ProjectService extends APIService {
}); });
} }
async leaveProject(workspaceSlug: string, projectId: string, user: ICurrentUserResponse): Promise<any> { async leaveProject(workspaceSlug: string, projectId: string, user: any): Promise<any> {
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/members/leave/`) return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/members/leave/`)
.then((response) => { .then((response) => {
trackEventServices.trackProjectEvent( trackEventServices.trackProjectEvent(

View File

@ -67,7 +67,8 @@ export interface IProjectStore {
handleProjectLeaveModal: (project: any | null) => void; handleProjectLeaveModal: (project: any | null) => void;
leaveProject: (workspaceSlug: string, projectSlug: string, user: any) => Promise<void>; leaveProject: (workspaceSlug: string, projectSlug: string) => Promise<void>;
deleteProject: (workspaceSlug: string, projectSlug: string) => Promise<void>;
} }
class ProjectStore implements IProjectStore { class ProjectStore implements IProjectStore {
@ -484,12 +485,13 @@ class ProjectStore implements IProjectStore {
} }
}; };
leaveProject = async (workspaceSlug: string, projectSlug: string, user: any) => { leaveProject = async (workspaceSlug: string, projectSlug: string) => {
try { try {
this.loader = true; this.loader = true;
this.error = null; this.error = null;
const response = await this.projectService.leaveProject(workspaceSlug, projectSlug, user); const response = await this.projectService.leaveProject(workspaceSlug, projectSlug, this.rootStore.user);
await this.rootStore.workspace.getWorkspaceProjects(workspaceSlug);
runInAction(() => { runInAction(() => {
this.loader = false; this.loader = false;
@ -503,6 +505,15 @@ class ProjectStore implements IProjectStore {
return error; return error;
} }
}; };
deleteProject = async (workspaceSlug: string, projectId: string) => {
try {
await this.projectService.deleteProject(workspaceSlug, projectId, this.rootStore.user.currentUser);
await this.rootStore.workspace.getWorkspaceProjects(workspaceSlug);
} catch (error) {
console.log("Failed to delete project from project store");
}
};
} }
export default ProjectStore; export default ProjectStore;