2023-02-08 04:43:07 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR, { mutate } from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import projectService from "services/project.service";
|
2023-04-22 18:16:19 +00:00
|
|
|
import trackEventServices, { MiscellaneousEventType } from "services/track-event.service";
|
2023-02-08 04:43:07 +00:00
|
|
|
// layouts
|
2023-04-08 08:16:46 +00:00
|
|
|
import { ProjectAuthorizationWrapper } from "layouts/auth-layout";
|
2023-02-08 04:43:07 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
2023-06-06 16:06:00 +00:00
|
|
|
import useUserAuth from "hooks/use-user-auth";
|
2023-05-15 06:05:19 +00:00
|
|
|
// components
|
2023-09-13 17:39:55 +00:00
|
|
|
import { SettingsSidebar } from "components/project";
|
2023-02-08 04:43:07 +00:00
|
|
|
// ui
|
2023-09-13 17:39:55 +00:00
|
|
|
import { ToggleSwitch } from "components/ui";
|
2023-02-08 04:43:07 +00:00
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
2023-03-17 05:10:38 +00:00
|
|
|
// icons
|
2023-09-13 17:39:55 +00:00
|
|
|
import { ModuleIcon } from "components/icons";
|
|
|
|
import { Contrast, FileText, Inbox, Layers } from "lucide-react";
|
2023-02-08 04:43:07 +00:00
|
|
|
// types
|
2023-07-13 14:14:53 +00:00
|
|
|
import { IProject } from "types";
|
2023-04-08 08:16:46 +00:00
|
|
|
import type { NextPage } from "next";
|
2023-02-08 04:43:07 +00:00
|
|
|
// fetch-keys
|
2023-07-13 14:14:53 +00:00
|
|
|
import { PROJECTS_LIST, PROJECT_DETAILS } from "constants/fetch-keys";
|
2023-07-31 11:52:48 +00:00
|
|
|
// helper
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
2023-02-08 04:43:07 +00:00
|
|
|
|
2023-04-22 18:16:19 +00:00
|
|
|
const featuresList = [
|
|
|
|
{
|
|
|
|
title: "Cycles",
|
|
|
|
description:
|
|
|
|
"Cycles are enabled for all the projects in this workspace. Access them from the sidebar.",
|
2023-09-13 17:39:55 +00:00
|
|
|
icon: <Contrast className="h-4 w-4 text-custom-primary-100 flex-shrink-0" />,
|
2023-04-22 18:16:19 +00:00
|
|
|
property: "cycle_view",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Modules",
|
|
|
|
description:
|
|
|
|
"Modules are enabled for all the projects in this workspace. Access it from the sidebar.",
|
2023-09-13 17:39:55 +00:00
|
|
|
icon: <ModuleIcon width={16} height={16} className="flex-shrink-0" />,
|
2023-04-22 18:16:19 +00:00
|
|
|
property: "module_view",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Views",
|
|
|
|
description:
|
|
|
|
"Views are enabled for all the projects in this workspace. Access it from the sidebar.",
|
2023-09-13 17:39:55 +00:00
|
|
|
icon: <Layers className="h-4 w-4 text-cyan-500 flex-shrink-0" />,
|
2023-04-22 18:16:19 +00:00
|
|
|
property: "issue_views_view",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Pages",
|
|
|
|
description:
|
|
|
|
"Pages are enabled for all the projects in this workspace. Access it from the sidebar.",
|
2023-09-13 17:39:55 +00:00
|
|
|
icon: <FileText className="h-4 w-4 text-red-400 flex-shrink-0" />,
|
2023-04-22 18:16:19 +00:00
|
|
|
property: "page_view",
|
|
|
|
},
|
2023-06-16 13:27:17 +00:00
|
|
|
{
|
|
|
|
title: "Inbox",
|
|
|
|
description:
|
|
|
|
"Inbox are enabled for all the projects in this workspace. Access it from the issues views page.",
|
2023-09-13 17:39:55 +00:00
|
|
|
icon: <Inbox className="h-4 w-4 text-cyan-500 flex-shrink-0" />,
|
2023-06-16 13:27:17 +00:00
|
|
|
property: "inbox_view",
|
|
|
|
},
|
2023-04-22 18:16:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const getEventType = (feature: string, toggle: boolean): MiscellaneousEventType => {
|
|
|
|
switch (feature) {
|
|
|
|
case "Cycles":
|
|
|
|
return toggle ? "TOGGLE_CYCLE_ON" : "TOGGLE_CYCLE_OFF";
|
|
|
|
case "Modules":
|
|
|
|
return toggle ? "TOGGLE_MODULE_ON" : "TOGGLE_MODULE_OFF";
|
|
|
|
case "Views":
|
|
|
|
return toggle ? "TOGGLE_VIEW_ON" : "TOGGLE_VIEW_OFF";
|
|
|
|
case "Pages":
|
|
|
|
return toggle ? "TOGGLE_PAGES_ON" : "TOGGLE_PAGES_OFF";
|
2023-06-16 13:27:17 +00:00
|
|
|
case "Inbox":
|
|
|
|
return toggle ? "TOGGLE_INBOX_ON" : "TOGGLE_INBOX_OFF";
|
2023-04-22 18:16:19 +00:00
|
|
|
default:
|
2023-06-16 13:27:17 +00:00
|
|
|
throw new Error("Invalid feature");
|
2023-04-22 18:16:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
const FeaturesSettings: NextPage = () => {
|
2023-02-08 04:43:07 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
const { user } = useUserAuth();
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const { data: projectDetails } = useSWR(
|
|
|
|
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.getProject(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleSubmit = async (formData: Partial<IProject>) => {
|
2023-05-10 20:45:39 +00:00
|
|
|
if (!workspaceSlug || !projectId || !projectDetails) return;
|
2023-02-08 04:43:07 +00:00
|
|
|
|
|
|
|
mutate<IProject[]>(
|
2023-07-13 14:14:53 +00:00
|
|
|
PROJECTS_LIST(workspaceSlug.toString(), {
|
|
|
|
is_favorite: "all",
|
|
|
|
}),
|
2023-07-14 09:38:07 +00:00
|
|
|
(prevData) => prevData?.map((p) => (p.id === projectId ? { ...p, ...formData } : p)),
|
2023-02-08 04:43:07 +00:00
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2023-05-10 20:45:39 +00:00
|
|
|
mutate<IProject>(
|
|
|
|
PROJECT_DETAILS(projectId as string),
|
2023-07-14 09:38:07 +00:00
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return { ...prevData, ...formData };
|
|
|
|
},
|
2023-05-10 20:45:39 +00:00
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Success!",
|
|
|
|
message: "Project feature updated successfully.",
|
|
|
|
});
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
await projectService
|
2023-06-06 16:06:00 +00:00
|
|
|
.updateProject(workspaceSlug as string, projectId as string, formData, user)
|
2023-07-13 14:14:53 +00:00
|
|
|
.catch(() =>
|
2023-05-10 20:45:39 +00:00
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Project feature could not be updated. Please try again.",
|
2023-07-13 14:14:53 +00:00
|
|
|
})
|
|
|
|
);
|
2023-02-08 04:43:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-04-08 08:16:46 +00:00
|
|
|
<ProjectAuthorizationWrapper
|
2023-02-08 04:43:07 +00:00
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem
|
2023-07-31 11:52:48 +00:00
|
|
|
title={`${truncateText(projectDetails?.name ?? "Project", 32)}`}
|
2023-02-08 04:43:07 +00:00
|
|
|
link={`/${workspaceSlug}/projects/${projectDetails?.id}/issues`}
|
2023-07-31 11:52:48 +00:00
|
|
|
linkTruncate
|
2023-02-08 04:43:07 +00:00
|
|
|
/>
|
2023-07-31 11:52:48 +00:00
|
|
|
<BreadcrumbItem title="Features Settings" unshrinkTitle />
|
2023-02-08 04:43:07 +00:00
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
>
|
2023-09-13 17:39:55 +00:00
|
|
|
<div className="flex flex-row gap-2">
|
|
|
|
<div className="w-80 py-8">
|
|
|
|
<SettingsSidebar />
|
|
|
|
</div>
|
|
|
|
<section className="pr-9 py-8 w-full">
|
|
|
|
<div className="flex items-center py-3.5 border-b border-custom-border-200">
|
|
|
|
<h3 className="text-xl font-medium">Features</h3>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-05-05 11:37:29 +00:00
|
|
|
{featuresList.map((feature) => (
|
|
|
|
<div
|
|
|
|
key={feature.property}
|
2023-09-13 17:39:55 +00:00
|
|
|
className="flex items-center justify-between gap-x-8 gap-y-2 border-b border-custom-border-200 bg-custom-background-100 p-4"
|
2023-05-05 11:37:29 +00:00
|
|
|
>
|
|
|
|
<div className="flex items-start gap-3">
|
2023-09-13 17:39:55 +00:00
|
|
|
<div className="flex items-center justify-center p-3 rounded bg-custom-background-90">
|
|
|
|
{feature.icon}
|
|
|
|
</div>
|
2023-07-11 09:48:47 +00:00
|
|
|
<div className="">
|
2023-09-13 17:39:55 +00:00
|
|
|
<h4 className="text-sm font-medium">{feature.title}</h4>
|
|
|
|
<p className="text-sm text-custom-text-200 tracking-tight">
|
|
|
|
{feature.description}
|
|
|
|
</p>
|
2023-05-05 11:37:29 +00:00
|
|
|
</div>
|
2023-04-22 18:16:19 +00:00
|
|
|
</div>
|
2023-05-05 11:37:29 +00:00
|
|
|
<ToggleSwitch
|
|
|
|
value={projectDetails?.[feature.property as keyof IProject]}
|
|
|
|
onChange={() => {
|
|
|
|
trackEventServices.trackMiscellaneousEvent(
|
|
|
|
{
|
|
|
|
workspaceId: (projectDetails?.workspace as any)?.id,
|
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
|
|
|
projectIdentifier: projectDetails?.identifier,
|
|
|
|
projectName: projectDetails?.name,
|
|
|
|
},
|
2023-06-16 13:27:17 +00:00
|
|
|
getEventType(
|
|
|
|
feature.title,
|
|
|
|
!projectDetails?.[feature.property as keyof IProject]
|
|
|
|
),
|
2023-06-06 16:06:00 +00:00
|
|
|
user
|
2023-05-05 11:37:29 +00:00
|
|
|
);
|
|
|
|
handleSubmit({
|
|
|
|
[feature.property]: !projectDetails?.[feature.property as keyof IProject],
|
|
|
|
});
|
|
|
|
}}
|
2023-09-13 17:39:55 +00:00
|
|
|
size="sm"
|
2023-05-05 11:37:29 +00:00
|
|
|
/>
|
2023-03-03 07:59:36 +00:00
|
|
|
</div>
|
2023-05-05 11:37:29 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
2023-04-08 08:16:46 +00:00
|
|
|
</ProjectAuthorizationWrapper>
|
2023-02-08 04:43:07 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FeaturesSettings;
|