chore: update favorite projects endpoint (#1522)
* chore: upate favorite projects list endpoint * chore: add project button on the sidebar * refactor: sidebar favorite projects workflow
This commit is contained in:
parent
7361657660
commit
c9a5893c3f
14 changed files with 251 additions and 308 deletions
|
|
@ -59,7 +59,7 @@ const ControlSettings: NextPage = () => {
|
|||
} = useForm<IProject>({ defaultValues });
|
||||
|
||||
const onSubmit = async (formData: IProject) => {
|
||||
if (!workspaceSlug || !projectId) return;
|
||||
if (!workspaceSlug || !projectId || !projectDetails) return;
|
||||
|
||||
const payload: Partial<IProject> = {
|
||||
default_assignee: formData.default_assignee,
|
||||
|
|
@ -70,7 +70,19 @@ const ControlSettings: NextPage = () => {
|
|||
.updateProject(workspaceSlug as string, projectId as string, payload, user)
|
||||
.then((res) => {
|
||||
mutate(PROJECT_DETAILS(projectId as string));
|
||||
mutate(PROJECTS_LIST(workspaceSlug as string));
|
||||
|
||||
if (projectDetails.is_favorite)
|
||||
mutate(
|
||||
PROJECTS_LIST(workspaceSlug as string, {
|
||||
is_favorite: true,
|
||||
})
|
||||
);
|
||||
|
||||
mutate(
|
||||
PROJECTS_LIST(workspaceSlug as string, {
|
||||
is_favorite: "all",
|
||||
})
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
title: "Success",
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
|||
import { ContrastIcon, PeopleGroupIcon, ViewListIcon, InboxIcon } from "components/icons";
|
||||
import { DocumentTextIcon } from "@heroicons/react/24/outline";
|
||||
// types
|
||||
import { IFavoriteProject, IProject } from "types";
|
||||
import { IProject } from "types";
|
||||
import type { NextPage } from "next";
|
||||
// fetch-keys
|
||||
import { FAVORITE_PROJECTS_LIST, PROJECTS_LIST, PROJECT_DETAILS } from "constants/fetch-keys";
|
||||
import { PROJECTS_LIST, PROJECT_DETAILS } from "constants/fetch-keys";
|
||||
|
||||
const featuresList = [
|
||||
{
|
||||
|
|
@ -100,17 +100,16 @@ const FeaturesSettings: NextPage = () => {
|
|||
if (!workspaceSlug || !projectId || !projectDetails) return;
|
||||
|
||||
if (projectDetails.is_favorite)
|
||||
mutate<IFavoriteProject[]>(
|
||||
FAVORITE_PROJECTS_LIST(workspaceSlug.toString()),
|
||||
mutate<IProject[]>(
|
||||
PROJECTS_LIST(workspaceSlug.toString(), {
|
||||
is_favorite: true,
|
||||
}),
|
||||
(prevData) =>
|
||||
prevData?.map((p) => {
|
||||
if (p.project === projectId)
|
||||
if (p.id === projectId)
|
||||
return {
|
||||
...p,
|
||||
project_detail: {
|
||||
...p.project_detail,
|
||||
...formData,
|
||||
},
|
||||
...formData,
|
||||
};
|
||||
|
||||
return p;
|
||||
|
|
@ -119,7 +118,9 @@ const FeaturesSettings: NextPage = () => {
|
|||
);
|
||||
|
||||
mutate<IProject[]>(
|
||||
PROJECTS_LIST(workspaceSlug.toString()),
|
||||
PROJECTS_LIST(workspaceSlug.toString(), {
|
||||
is_favorite: "all",
|
||||
}),
|
||||
(prevData) =>
|
||||
prevData?.map((p) => {
|
||||
if (p.id === projectId)
|
||||
|
|
@ -147,21 +148,13 @@ const FeaturesSettings: NextPage = () => {
|
|||
|
||||
await projectService
|
||||
.updateProject(workspaceSlug as string, projectId as string, formData, user)
|
||||
.then(() => {
|
||||
mutate(
|
||||
projectDetails.is_favorite
|
||||
? FAVORITE_PROJECTS_LIST(workspaceSlug.toString())
|
||||
: PROJECTS_LIST(workspaceSlug.toString())
|
||||
);
|
||||
mutate(PROJECT_DETAILS(projectId as string));
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(() =>
|
||||
setToastAlert({
|
||||
type: "error",
|
||||
title: "Error!",
|
||||
message: "Project feature could not be updated. Please try again.",
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -94,7 +94,20 @@ const GeneralSettings: NextPage = () => {
|
|||
(prevData) => ({ ...prevData, ...res }),
|
||||
false
|
||||
);
|
||||
mutate(PROJECTS_LIST(workspaceSlug as string));
|
||||
|
||||
if (projectDetails.is_favorite)
|
||||
mutate(
|
||||
PROJECTS_LIST(workspaceSlug as string, {
|
||||
is_favorite: true,
|
||||
})
|
||||
);
|
||||
|
||||
mutate(
|
||||
PROJECTS_LIST(workspaceSlug as string, {
|
||||
is_favorite: "all",
|
||||
})
|
||||
);
|
||||
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue