mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
workspace project fixes
This commit is contained in:
parent
6a430ed480
commit
0ebe36bdb3
@ -4,7 +4,7 @@ export * from "./sidebar-list";
|
|||||||
export * from "./settings-sidebar";
|
export * from "./settings-sidebar";
|
||||||
export * from "./single-integration-card";
|
export * from "./single-integration-card";
|
||||||
export * from "./single-project-card";
|
export * from "./single-project-card";
|
||||||
export * from "./single-sidebar-project";
|
export * from "./sidebar-list-item";
|
||||||
export * from "./confirm-project-leave-modal";
|
export * from "./confirm-project-leave-modal";
|
||||||
export * from "./member-select";
|
export * from "./member-select";
|
||||||
export * from "./members-select";
|
export * from "./members-select";
|
||||||
|
@ -45,7 +45,6 @@ type Props = {
|
|||||||
snapshot?: DraggableStateSnapshot;
|
snapshot?: DraggableStateSnapshot;
|
||||||
handleDeleteProject: () => void;
|
handleDeleteProject: () => void;
|
||||||
handleCopyText: () => void;
|
handleCopyText: () => void;
|
||||||
handleProjectLeave: () => void;
|
|
||||||
shortContextMenu?: boolean;
|
shortContextMenu?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ const navigation = (workspaceSlug: string, projectId: string) => [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
export const ProjectSidebarListItem: React.FC<Props> = observer((props) => {
|
||||||
const {
|
const {
|
||||||
project,
|
project,
|
||||||
sidebarCollapse,
|
sidebarCollapse,
|
||||||
@ -90,62 +89,41 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
snapshot,
|
snapshot,
|
||||||
handleDeleteProject,
|
handleDeleteProject,
|
||||||
handleCopyText,
|
handleCopyText,
|
||||||
handleProjectLeave,
|
|
||||||
shortContextMenu = false,
|
shortContextMenu = false,
|
||||||
} = props;
|
} = props;
|
||||||
|
// store
|
||||||
const store: RootStore = useMobxStore();
|
const { projectPublish, project: projectStore }: RootStore = useMobxStore();
|
||||||
const { projectPublish, project: projectStore } = store;
|
// router
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId } = router.query;
|
const { workspaceSlug, projectId } = router.query;
|
||||||
|
// toast
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
const handleAddToFavorites = () => {
|
const handleAddToFavorites = () => {
|
||||||
if (!workspaceSlug) return;
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
mutate<IProject[]>(
|
projectStore.addProjectToFavorites(workspaceSlug.toString(), project.id).catch(() => {
|
||||||
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
|
setToastAlert({
|
||||||
(prevData) =>
|
type: "error",
|
||||||
(prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: true } : p)),
|
title: "Error!",
|
||||||
false
|
message: "Couldn't remove the project from favorites. Please try again.",
|
||||||
);
|
});
|
||||||
|
});
|
||||||
projectService
|
|
||||||
.addProjectToFavorites(workspaceSlug as string, {
|
|
||||||
project: project.id,
|
|
||||||
})
|
|
||||||
.catch(() =>
|
|
||||||
setToastAlert({
|
|
||||||
type: "error",
|
|
||||||
title: "Error!",
|
|
||||||
message: "Couldn't remove the project from favorites. Please try again.",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveFromFavorites = () => {
|
const handleRemoveFromFavorites = () => {
|
||||||
if (!workspaceSlug) return;
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
mutate<IProject[]>(
|
projectStore.removeProjectFromFavorites(workspaceSlug.toString(), project.id).catch(() => {
|
||||||
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
|
|
||||||
(prevData) =>
|
|
||||||
(prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: false } : p)),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
projectService.removeProjectFromFavorites(workspaceSlug as string, project.id).catch(() =>
|
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
message: "Couldn't remove the project from favorites. Please try again.",
|
message: "Couldn't remove the project from favorites. Please try again.",
|
||||||
})
|
});
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -159,11 +137,7 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
>
|
>
|
||||||
{provided && (
|
{provided && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
tooltipContent={
|
tooltipContent={project.sort_order === null ? "Join the project to rearrange" : "Drag to rearrange"}
|
||||||
project.sort_order === null
|
|
||||||
? "Join the project to rearrange"
|
|
||||||
: "Drag to rearrange"
|
|
||||||
}
|
|
||||||
position="top-right"
|
position="top-right"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@ -178,12 +152,7 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
<Tooltip
|
<Tooltip tooltipContent={`${project.name}`} position="right" className="ml-2" disabled={!sidebarCollapse}>
|
||||||
tooltipContent={`${project.name}`}
|
|
||||||
position="right"
|
|
||||||
className="ml-2"
|
|
||||||
disabled={!sidebarCollapse}
|
|
||||||
>
|
|
||||||
<Disclosure.Button
|
<Disclosure.Button
|
||||||
as="div"
|
as="div"
|
||||||
className={`flex items-center flex-grow truncate cursor-pointer select-none text-left text-sm font-medium ${
|
className={`flex items-center flex-grow truncate cursor-pointer select-none text-left text-sm font-medium ${
|
||||||
@ -210,9 +179,7 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{!sidebarCollapse && (
|
{!sidebarCollapse && (
|
||||||
<p className={`truncate ${open ? "" : "text-custom-sidebar-text-200"}`}>
|
<p className={`truncate ${open ? "" : "text-custom-sidebar-text-200"}`}>{project.name}</p>
|
||||||
{project.name}
|
|
||||||
</p>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!sidebarCollapse && (
|
{!sidebarCollapse && (
|
||||||
@ -265,9 +232,7 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
{/* publish project settings */}
|
{/* publish project settings */}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<CustomMenu.MenuItem
|
<CustomMenu.MenuItem onClick={() => projectPublish.handleProjectModal(project?.id)}>
|
||||||
onClick={() => projectPublish.handleProjectModal(project?.id)}
|
|
||||||
>
|
|
||||||
<div className="flex-shrink-0 relative flex items-center justify-start gap-2">
|
<div className="flex-shrink-0 relative flex items-center justify-start gap-2">
|
||||||
<div className="rounded transition-all w-4 h-4 flex justify-center items-center text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 duration-300 cursor-pointer">
|
<div className="rounded transition-all w-4 h-4 flex justify-center items-center text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 duration-300 cursor-pointer">
|
||||||
<Icon iconName="ios_share" className="!text-base" />
|
<Icon iconName="ios_share" className="!text-base" />
|
||||||
@ -279,9 +244,7 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
{project.archive_in > 0 && (
|
{project.archive_in > 0 && (
|
||||||
<CustomMenu.MenuItem
|
<CustomMenu.MenuItem
|
||||||
onClick={() =>
|
onClick={() => router.push(`/${workspaceSlug}/projects/${project?.id}/archived-issues/`)}
|
||||||
router.push(`/${workspaceSlug}/projects/${project?.id}/archived-issues/`)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-start gap-2">
|
<div className="flex items-center justify-start gap-2">
|
||||||
<ArchiveOutlined fontSize="small" />
|
<ArchiveOutlined fontSize="small" />
|
||||||
@ -290,18 +253,14 @@ export const SingleSidebarProject: React.FC<Props> = observer((props) => {
|
|||||||
</CustomMenu.MenuItem>
|
</CustomMenu.MenuItem>
|
||||||
)}
|
)}
|
||||||
<CustomMenu.MenuItem
|
<CustomMenu.MenuItem
|
||||||
onClick={() =>
|
onClick={() => router.push(`/${workspaceSlug}/projects/${project?.id}/draft-issues`)}
|
||||||
router.push(`/${workspaceSlug}/projects/${project?.id}/draft-issues`)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-start gap-2">
|
<div className="flex items-center justify-start gap-2">
|
||||||
<PenSquare className="!text-base !leading-4 w-[14px] h-[14px] text-custom-text-300" />
|
<PenSquare className="!text-base !leading-4 w-[14px] h-[14px] text-custom-text-300" />
|
||||||
<span>Draft Issues</span>
|
<span>Draft Issues</span>
|
||||||
</div>
|
</div>
|
||||||
</CustomMenu.MenuItem>
|
</CustomMenu.MenuItem>
|
||||||
<CustomMenu.MenuItem
|
<CustomMenu.MenuItem onClick={() => router.push(`/${workspaceSlug}/projects/${project?.id}/settings`)}>
|
||||||
onClick={() => router.push(`/${workspaceSlug}/projects/${project?.id}/settings`)}
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-start gap-2">
|
<div className="flex items-center justify-start gap-2">
|
||||||
<Icon iconName="settings" className="!text-base !leading-4" />
|
<Icon iconName="settings" className="!text-base !leading-4" />
|
||||||
<span>Settings</span>
|
<span>Settings</span>
|
@ -1,18 +1,15 @@
|
|||||||
import React, { useState, FC, useRef, useEffect } from "react";
|
import React, { useState, FC, useRef, useEffect } from "react";
|
||||||
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
|
|
||||||
// react-beautiful-dnd
|
|
||||||
import { DragDropContext, Draggable, DropResult, Droppable } from "react-beautiful-dnd";
|
import { DragDropContext, Draggable, DropResult, Droppable } from "react-beautiful-dnd";
|
||||||
// headless ui
|
|
||||||
import { Disclosure, Transition } from "@headlessui/react";
|
import { Disclosure, Transition } from "@headlessui/react";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
// hooks
|
// hooks
|
||||||
import useToast from "hooks/use-toast";
|
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, SingleSidebarProject } from "components/project";
|
import { CreateProjectModal, DeleteProjectModal, ProjectSidebarListItem } from "components/project";
|
||||||
// services
|
// services
|
||||||
import projectService from "services/project.service";
|
import projectService from "services/project.service";
|
||||||
// icons
|
// icons
|
||||||
@ -28,9 +25,17 @@ 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";
|
||||||
|
|
||||||
export const ProjectSidebarList: FC = () => {
|
export const ProjectSidebarList: FC = observer(() => {
|
||||||
const store: any = useMobxStore();
|
const { theme: themeStore, workspace: workspaceStore } = useMobxStore();
|
||||||
|
// router
|
||||||
|
const router = useRouter();
|
||||||
|
const { workspaceSlug } = router.query;
|
||||||
|
// swr
|
||||||
|
useSWR(
|
||||||
|
workspaceSlug ? "PROJECTS_LIST" : null,
|
||||||
|
workspaceSlug ? () => workspaceStore.getWorkspaceProjects(workspaceSlug?.toString()) : null
|
||||||
|
);
|
||||||
|
// states
|
||||||
const [isFavoriteProjectCreate, setIsFavoriteProjectCreate] = useState(false);
|
const [isFavoriteProjectCreate, setIsFavoriteProjectCreate] = useState(false);
|
||||||
const [isProjectModalOpen, setIsProjectModalOpen] = useState(false);
|
const [isProjectModalOpen, setIsProjectModalOpen] = useState(false);
|
||||||
const [deleteProjectModal, setDeleteProjectModal] = useState(false);
|
const [deleteProjectModal, setDeleteProjectModal] = useState(false);
|
||||||
@ -42,16 +47,14 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
const { workspaceSlug } = router.query;
|
|
||||||
|
|
||||||
const { user } = useUserAuth();
|
const { user } = useUserAuth();
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
|
||||||
const { projects: allProjects } = useProjects();
|
const joinedProjects = workspaceSlug && workspaceStore.workspaceJoinedProjects;
|
||||||
|
const favoriteProjects = workspaceSlug && workspaceStore.workspaceFavoriteProjects;
|
||||||
|
|
||||||
const joinedProjects = allProjects?.filter((p) => p.is_member);
|
console.log("workspaceJoinedProjects", workspaceStore.workspaceJoinedProjects);
|
||||||
const favoriteProjects = allProjects?.filter((p) => p.is_favorite);
|
console.log("workspaceFavoriteProjects", workspaceStore.workspaceFavoriteProjects);
|
||||||
|
|
||||||
const orderedJoinedProjects: IProject[] | undefined = joinedProjects
|
const orderedJoinedProjects: IProject[] | undefined = joinedProjects
|
||||||
? orderArrayBy(joinedProjects, "sort_order", "ascending")
|
? orderArrayBy(joinedProjects, "sort_order", "ascending")
|
||||||
@ -67,8 +70,7 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleCopyText = (projectId: string) => {
|
const handleCopyText = (projectId: string) => {
|
||||||
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/${projectId}/issues`).then(() => {
|
copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${projectId}/issues`).then(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "success",
|
type: "success",
|
||||||
@ -86,9 +88,7 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
if (source.index === destination.index) return;
|
if (source.index === destination.index) return;
|
||||||
|
|
||||||
const projectsList =
|
const projectsList =
|
||||||
(destination.droppableId === "joined-projects"
|
(destination.droppableId === "joined-projects" ? orderedJoinedProjects : orderedFavProjects) ?? [];
|
||||||
? orderedJoinedProjects
|
|
||||||
: orderedFavProjects) ?? [];
|
|
||||||
|
|
||||||
let updatedSortOrder = projectsList[source.index].sort_order;
|
let updatedSortOrder = projectsList[source.index].sort_order;
|
||||||
|
|
||||||
@ -109,9 +109,7 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
|
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
|
||||||
(prevData) => {
|
(prevData) => {
|
||||||
if (!prevData) return prevData;
|
if (!prevData) return prevData;
|
||||||
return prevData.map((p) =>
|
return prevData.map((p) => (p.id === draggableId ? { ...p, sort_order: updatedSortOrder } : p));
|
||||||
p.id === draggableId ? { ...p, sort_order: updatedSortOrder } : p
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -176,7 +174,7 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
<Disclosure as="div" className="flex flex-col space-y-2" defaultOpen={true}>
|
<Disclosure as="div" className="flex flex-col space-y-2" defaultOpen={true}>
|
||||||
{({ open }) => (
|
{({ open }) => (
|
||||||
<>
|
<>
|
||||||
{!store?.theme?.sidebarCollapsed && (
|
{!themeStore?.sidebarCollapsed && (
|
||||||
<div className="group flex justify-between items-center text-xs px-1.5 rounded text-custom-sidebar-text-400 hover:bg-custom-sidebar-background-80 w-full">
|
<div className="group flex justify-between items-center text-xs px-1.5 rounded text-custom-sidebar-text-400 hover:bg-custom-sidebar-background-80 w-full">
|
||||||
<Disclosure.Button
|
<Disclosure.Button
|
||||||
as="button"
|
as="button"
|
||||||
@ -210,15 +208,14 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
>
|
>
|
||||||
{(provided, snapshot) => (
|
{(provided, snapshot) => (
|
||||||
<div ref={provided.innerRef} {...provided.draggableProps}>
|
<div ref={provided.innerRef} {...provided.draggableProps}>
|
||||||
<SingleSidebarProject
|
<ProjectSidebarListItem
|
||||||
key={project.id}
|
key={project.id}
|
||||||
project={project}
|
project={project}
|
||||||
sidebarCollapse={store?.theme?.sidebarCollapsed}
|
sidebarCollapse={themeStore?.sidebarCollapsed || false}
|
||||||
provided={provided}
|
provided={provided}
|
||||||
snapshot={snapshot}
|
snapshot={snapshot}
|
||||||
handleDeleteProject={() => handleDeleteProject(project)}
|
handleDeleteProject={() => handleDeleteProject(project)}
|
||||||
handleCopyText={() => handleCopyText(project.id)}
|
handleCopyText={() => handleCopyText(project.id)}
|
||||||
handleProjectLeave={() => setProjectToLeaveId(project.id)}
|
|
||||||
shortContextMenu
|
shortContextMenu
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -243,7 +240,7 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
<Disclosure as="div" className="flex flex-col space-y-2" defaultOpen={true}>
|
<Disclosure as="div" className="flex flex-col space-y-2" defaultOpen={true}>
|
||||||
{({ open }) => (
|
{({ open }) => (
|
||||||
<>
|
<>
|
||||||
{!store?.theme?.sidebarCollapsed && (
|
{!themeStore?.sidebarCollapsed && (
|
||||||
<div className="group flex justify-between items-center text-xs px-1.5 rounded text-custom-sidebar-text-400 hover:bg-custom-sidebar-background-80 w-full">
|
<div className="group flex justify-between items-center text-xs px-1.5 rounded text-custom-sidebar-text-400 hover:bg-custom-sidebar-background-80 w-full">
|
||||||
<Disclosure.Button
|
<Disclosure.Button
|
||||||
as="button"
|
as="button"
|
||||||
@ -280,14 +277,13 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
<Draggable key={project.id} draggableId={project.id} index={index}>
|
<Draggable key={project.id} draggableId={project.id} index={index}>
|
||||||
{(provided, snapshot) => (
|
{(provided, snapshot) => (
|
||||||
<div ref={provided.innerRef} {...provided.draggableProps}>
|
<div ref={provided.innerRef} {...provided.draggableProps}>
|
||||||
<SingleSidebarProject
|
<ProjectSidebarListItem
|
||||||
key={project.id}
|
key={project.id}
|
||||||
project={project}
|
project={project}
|
||||||
sidebarCollapse={store?.theme?.sidebarCollapsed}
|
sidebarCollapse={themeStore?.sidebarCollapsed || false}
|
||||||
provided={provided}
|
provided={provided}
|
||||||
snapshot={snapshot}
|
snapshot={snapshot}
|
||||||
handleDeleteProject={() => handleDeleteProject(project)}
|
handleDeleteProject={() => handleDeleteProject(project)}
|
||||||
handleProjectLeave={() => setProjectToLeaveId(project.id)}
|
|
||||||
handleCopyText={() => handleCopyText(project.id)}
|
handleCopyText={() => handleCopyText(project.id)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -318,10 +314,10 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PlusIcon className="h-5 w-5" />
|
<PlusIcon className="h-5 w-5" />
|
||||||
{!store?.theme?.sidebarCollapsed && "Add Project"}
|
{!themeStore?.sidebarCollapsed && "Add Project"}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
@ -3,19 +3,19 @@ import { useEffect } from "react";
|
|||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
// mobx store
|
// mobx store
|
||||||
import { useMobxStore } from "lib/mobx/store-provider";
|
import { useMobxStore } from "lib/mobx/store-provider";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
const MobxStoreInit = () => {
|
const MobxStoreInit = () => {
|
||||||
const store: any = useMobxStore();
|
const { theme: themeStore, user: userStore, workspace: workspaceStore, project: projectStore } = useMobxStore();
|
||||||
const { setTheme } = useTheme();
|
const { setTheme } = useTheme();
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const { workspaceSlug, projectId } = router.query;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// sidebar collapsed toggle
|
// sidebar collapsed toggle
|
||||||
if (
|
if (localStorage && localStorage.getItem("app_sidebar_collapsed") && themeStore?.sidebarCollapsed === null)
|
||||||
localStorage &&
|
themeStore.setSidebarCollapsed(
|
||||||
localStorage.getItem("app_sidebar_collapsed") &&
|
|
||||||
store?.theme?.sidebarCollapsed === null
|
|
||||||
)
|
|
||||||
store.theme.setSidebarCollapsed(
|
|
||||||
localStorage.getItem("app_sidebar_collapsed")
|
localStorage.getItem("app_sidebar_collapsed")
|
||||||
? localStorage.getItem("app_sidebar_collapsed") === "true"
|
? localStorage.getItem("app_sidebar_collapsed") === "true"
|
||||||
? true
|
? true
|
||||||
@ -24,25 +24,30 @@ const MobxStoreInit = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// theme
|
// theme
|
||||||
if (store.theme.theme === null && store?.user?.currentUserSettings) {
|
if (themeStore.theme === null && userStore?.currentUserSettings) {
|
||||||
let currentTheme = localStorage.getItem("theme");
|
let currentTheme = localStorage.getItem("theme");
|
||||||
currentTheme = currentTheme ? currentTheme : "system";
|
currentTheme = currentTheme ? currentTheme : "system";
|
||||||
|
|
||||||
// validating the theme and applying for initial state
|
// validating the theme and applying for initial state
|
||||||
if (currentTheme) {
|
if (currentTheme) {
|
||||||
setTheme(currentTheme);
|
setTheme(currentTheme);
|
||||||
store.theme.setTheme({ theme: { theme: currentTheme } });
|
themeStore.setTheme({ theme: { theme: currentTheme } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [store?.theme, store?.user, setTheme]);
|
}, [themeStore, userStore, setTheme]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// current user
|
// current user
|
||||||
if (store?.user?.currentUser === null) store.user.setCurrentUser();
|
if (userStore?.currentUser === null) userStore.setCurrentUser();
|
||||||
|
|
||||||
// current user settings
|
// current user settings
|
||||||
if (store?.user?.currentUserSettings === null) store.user.setCurrentUserSettings();
|
if (userStore?.currentUserSettings === null) userStore.setCurrentUserSettings();
|
||||||
}, [store?.user]);
|
}, [userStore]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (workspaceSlug) workspaceStore.setWorkspaceSlug(workspaceSlug.toString());
|
||||||
|
if (projectId) projectStore.setProjectId(projectId.toString());
|
||||||
|
}, [workspaceSlug, projectId, workspaceStore, projectStore]);
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
};
|
};
|
||||||
|
@ -300,13 +300,8 @@ export class ProjectService extends APIService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async addProjectToFavorites(
|
async addProjectToFavorites(workspaceSlug: string, project: string): Promise<any> {
|
||||||
workspaceSlug: string,
|
return this.post(`/api/workspaces/${workspaceSlug}/user-favorite-projects/`, { project })
|
||||||
data: {
|
|
||||||
project: string;
|
|
||||||
}
|
|
||||||
): Promise<any> {
|
|
||||||
return this.post(`/api/workspaces/${workspaceSlug}/user-favorite-projects/`, data)
|
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response?.data;
|
throw error?.response?.data;
|
||||||
|
@ -4,21 +4,24 @@ import { RootStore } from "./root";
|
|||||||
// services
|
// services
|
||||||
import { ProjectService } from "services/project.service";
|
import { ProjectService } from "services/project.service";
|
||||||
import { IssueService } from "services/issue.service";
|
import { IssueService } from "services/issue.service";
|
||||||
|
import { ICycle } from "types";
|
||||||
|
|
||||||
export interface ICycleStore {
|
export interface ICycleStore {
|
||||||
loader: boolean;
|
loader: boolean;
|
||||||
error: any | null;
|
error: any | null;
|
||||||
|
|
||||||
cycleId: string | null;
|
cycles: {
|
||||||
|
[cycle_id: string]: ICycle;
|
||||||
setCycleId: (cycleSlug: string) => void;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class CycleStore implements ICycleStore {
|
class CycleStore implements ICycleStore {
|
||||||
loader: boolean = false;
|
loader: boolean = false;
|
||||||
error: any | null = null;
|
error: any | null = null;
|
||||||
|
|
||||||
cycleId: string | null = null;
|
cycles: {
|
||||||
|
[cycle_id: string]: ICycle;
|
||||||
|
} = {};
|
||||||
|
|
||||||
// root store
|
// root store
|
||||||
rootStore;
|
rootStore;
|
||||||
@ -31,12 +34,11 @@ class CycleStore implements ICycleStore {
|
|||||||
loader: observable,
|
loader: observable,
|
||||||
error: observable.ref,
|
error: observable.ref,
|
||||||
|
|
||||||
cycleId: observable.ref,
|
cycles: observable.ref,
|
||||||
|
|
||||||
// computed
|
// computed
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
setCycleId: action,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.rootStore = _rootStore;
|
this.rootStore = _rootStore;
|
||||||
@ -47,9 +49,6 @@ class CycleStore implements ICycleStore {
|
|||||||
// computed
|
// computed
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
setCycleId = (cycleSlug: string) => {
|
|
||||||
this.cycleId = cycleSlug ?? null;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CycleStore;
|
export default CycleStore;
|
||||||
|
@ -62,7 +62,10 @@ export interface IProjectStore {
|
|||||||
fetchProjectLabels: (workspaceSlug: string, projectSlug: string) => Promise<void>;
|
fetchProjectLabels: (workspaceSlug: string, projectSlug: string) => Promise<void>;
|
||||||
fetchProjectMembers: (workspaceSlug: string, projectSlug: string) => Promise<void>;
|
fetchProjectMembers: (workspaceSlug: string, projectSlug: string) => Promise<void>;
|
||||||
|
|
||||||
handleProjectLeaveModal: (project: IProject | null) => void;
|
addProjectToFavorites: (workspaceSlug: string, projectSlug: string) => Promise<any>;
|
||||||
|
removeProjectFromFavorites: (workspaceSlug: string, projectSlug: string) => Promise<any>;
|
||||||
|
|
||||||
|
handleProjectLeaveModal: (project: any | null) => void;
|
||||||
|
|
||||||
leaveProject: (workspaceSlug: string, projectSlug: string, user: any) => Promise<void>;
|
leaveProject: (workspaceSlug: string, projectSlug: string, user: any) => Promise<void>;
|
||||||
}
|
}
|
||||||
@ -144,6 +147,9 @@ class ProjectStore implements IProjectStore {
|
|||||||
fetchProjectLabels: action,
|
fetchProjectLabels: action,
|
||||||
fetchProjectMembers: action,
|
fetchProjectMembers: action,
|
||||||
|
|
||||||
|
addProjectToFavorites: action,
|
||||||
|
removeProjectFromFavorites: action,
|
||||||
|
|
||||||
handleProjectLeaveModal: action,
|
handleProjectLeaveModal: action,
|
||||||
leaveProject: action,
|
leaveProject: action,
|
||||||
});
|
});
|
||||||
@ -392,6 +398,29 @@ class ProjectStore implements IProjectStore {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
addProjectToFavorites = async (workspaceSlug: string, projectId: string) => {
|
||||||
|
try {
|
||||||
|
const response = await this.projectService.addProjectToFavorites(workspaceSlug, projectId);
|
||||||
|
console.log("res", response);
|
||||||
|
await this.rootStore.workspace.getWorkspaceProjects(workspaceSlug);
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Failed to add project to favorite");
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
removeProjectFromFavorites = async (workspaceSlug: string, projectId: string) => {
|
||||||
|
try {
|
||||||
|
const response = this.projectService.removeProjectFromFavorites(workspaceSlug, projectId);
|
||||||
|
this.rootStore.workspace.getWorkspaceProjects(workspaceSlug);
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Failed to add project to favorite");
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
handleProjectLeaveModal = (project: IProject | null = null) => {
|
handleProjectLeaveModal = (project: IProject | null = null) => {
|
||||||
if (project && project?.id) {
|
if (project && project?.id) {
|
||||||
this.projectLeaveModal = !this.projectLeaveModal;
|
this.projectLeaveModal = !this.projectLeaveModal;
|
||||||
|
@ -28,8 +28,7 @@ class ThemeStore {
|
|||||||
|
|
||||||
setSidebarCollapsed(collapsed: boolean | null = null) {
|
setSidebarCollapsed(collapsed: boolean | null = null) {
|
||||||
if (collapsed === null) {
|
if (collapsed === null) {
|
||||||
let _sidebarCollapsed: string | boolean | null =
|
let _sidebarCollapsed: string | boolean | null = localStorage.getItem("app_sidebar_collapsed");
|
||||||
localStorage.getItem("app_sidebar_collapsed");
|
|
||||||
_sidebarCollapsed = _sidebarCollapsed ? (_sidebarCollapsed === "true" ? true : false) : false;
|
_sidebarCollapsed = _sidebarCollapsed ? (_sidebarCollapsed === "true" ? true : false) : false;
|
||||||
this.sidebarCollapsed = _sidebarCollapsed;
|
this.sidebarCollapsed = _sidebarCollapsed;
|
||||||
} else {
|
} else {
|
||||||
@ -38,7 +37,7 @@ class ThemeStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTheme = async (_theme: { theme: ICurrentUserSettings }) => {
|
setTheme = async (_theme: { theme: any }) => {
|
||||||
try {
|
try {
|
||||||
const currentTheme: string = _theme?.theme?.theme?.toString();
|
const currentTheme: string = _theme?.theme?.theme?.toString();
|
||||||
|
|
||||||
|
@ -17,12 +17,14 @@ export interface IWorkspaceStore {
|
|||||||
workspaceSlug: string | null;
|
workspaceSlug: string | null;
|
||||||
// computed
|
// computed
|
||||||
currentWorkspace: IWorkspace | null;
|
currentWorkspace: IWorkspace | null;
|
||||||
workspaceLabels: IIssueLabels[] | null;
|
workspaceLabels: IIssueLabels[];
|
||||||
|
workspaceJoinedProjects: IProject[];
|
||||||
|
workspaceFavoriteProjects: IProject[];
|
||||||
// actions
|
// actions
|
||||||
setWorkspaceSlug: (workspaceSlug: string) => void;
|
setWorkspaceSlug: (workspaceSlug: string) => void;
|
||||||
getWorkspaceBySlug: (workspaceSlug: string) => IWorkspace | null;
|
getWorkspaceBySlug: (workspaceSlug: string) => IWorkspace | null;
|
||||||
getWorkspaceLabelById: (workspaceSlug: string, labelId: string) => IIssueLabels | null;
|
getWorkspaceLabelById: (workspaceSlug: string, labelId: string) => IIssueLabels | null;
|
||||||
getWorkspaceProjects: (workspaceSlug: string) => IProject[];
|
getWorkspaceProjects: (workspaceSlug: string) => void;
|
||||||
fetchWorkspaces: () => Promise<void>;
|
fetchWorkspaces: () => Promise<void>;
|
||||||
fetchWorkspaceLabels: (workspaceSlug: string) => Promise<void>;
|
fetchWorkspaceLabels: (workspaceSlug: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
@ -44,15 +46,18 @@ class WorkspaceStore implements IWorkspaceStore {
|
|||||||
|
|
||||||
constructor(_rootStore: RootStore) {
|
constructor(_rootStore: RootStore) {
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
loader: observable,
|
loader: observable.ref,
|
||||||
error: observable.ref,
|
error: observable.ref,
|
||||||
// objects
|
// objects
|
||||||
workspaces: observable.ref,
|
workspaces: observable.ref,
|
||||||
labels: observable.ref,
|
labels: observable.ref,
|
||||||
workspaceSlug: observable.ref,
|
workspaceSlug: observable.ref,
|
||||||
|
projects: observable.ref,
|
||||||
// computed
|
// computed
|
||||||
currentWorkspace: computed,
|
currentWorkspace: computed,
|
||||||
workspaceLabels: computed,
|
workspaceLabels: computed,
|
||||||
|
workspaceJoinedProjects: computed,
|
||||||
|
workspaceFavoriteProjects: computed,
|
||||||
// actions
|
// actions
|
||||||
setWorkspaceSlug: action,
|
setWorkspaceSlug: action,
|
||||||
getWorkspaceBySlug: action,
|
getWorkspaceBySlug: action,
|
||||||
@ -82,7 +87,17 @@ class WorkspaceStore implements IWorkspaceStore {
|
|||||||
get workspaceLabels() {
|
get workspaceLabels() {
|
||||||
if (!this.workspaceSlug) return [];
|
if (!this.workspaceSlug) return [];
|
||||||
const _labels = this.labels?.[this.workspaceSlug];
|
const _labels = this.labels?.[this.workspaceSlug];
|
||||||
return _labels && Object.keys(_labels).length > 0 ? _labels : null;
|
return _labels && Object.keys(_labels).length > 0 ? _labels : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get workspaceJoinedProjects() {
|
||||||
|
if (!this.workspaceSlug) return [];
|
||||||
|
return this.projects?.[this.workspaceSlug]?.filter((p) => p.is_member);
|
||||||
|
}
|
||||||
|
|
||||||
|
get workspaceFavoriteProjects() {
|
||||||
|
if (!this.workspaceSlug) return [];
|
||||||
|
return this.projects?.[this.workspaceSlug]?.filter((p) => p.is_favorite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,17 +111,25 @@ class WorkspaceStore implements IWorkspaceStore {
|
|||||||
* fetch workspace info from the array of workspaces in the store.
|
* fetch workspace info from the array of workspaces in the store.
|
||||||
* @param workspaceSlug
|
* @param workspaceSlug
|
||||||
*/
|
*/
|
||||||
getWorkspaceBySlug = (workspaceSlug: string) => {
|
getWorkspaceBySlug = (workspaceSlug: string) => this.workspaces.find((w) => w.slug == workspaceSlug) || null;
|
||||||
return this.workspaces.find((w) => w.slug == workspaceSlug) || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get Workspace projects using workspace slug
|
* get Workspace projects using workspace slug
|
||||||
* @param workspaceSlug
|
* @param workspaceSlug
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getWorkspaceProjects = (workspaceSlug: string) => {
|
getWorkspaceProjects = async (workspaceSlug: string) => {
|
||||||
return this.projects[workspaceSlug];
|
try {
|
||||||
|
const projects = await this.projectService.getProjects(workspaceSlug, { is_favorite: "all" });
|
||||||
|
runInAction(() => {
|
||||||
|
this.projects = {
|
||||||
|
...this.projects,
|
||||||
|
[workspaceSlug]: projects,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Failed to fetch project from workspace store");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,9 +137,8 @@ class WorkspaceStore implements IWorkspaceStore {
|
|||||||
* @param labelId
|
* @param labelId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getWorkspaceLabelById = (workspaceSlug: string, labelId: string) => {
|
getWorkspaceLabelById = (workspaceSlug: string, labelId: string) =>
|
||||||
return this.labels?.[workspaceSlug].find((label) => label.id === labelId) || null;
|
this.labels?.[workspaceSlug].find((label) => label.id === labelId) || null;
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetch user workspaces from API
|
* fetch user workspaces from API
|
||||||
|
Loading…
Reference in New Issue
Block a user