import React from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import useSWR, { mutate } from "swr"; // services import { ProjectService } from "services/project"; import { TrackEventService, MiscellaneousEventType } from "services/track_event.service"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout-legacy"; // hooks import useToast from "hooks/use-toast"; import useUserAuth from "hooks/use-user-auth"; // components import { SettingsSidebar } from "components/project"; // ui import { BreadcrumbItem, Breadcrumbs, ContrastIcon, DiceIcon, ToggleSwitch } from "@plane/ui"; // icons import { FileText, Inbox, Layers } from "lucide-react"; // types import { IProject, IUser } from "types"; import type { NextPage } from "next"; // fetch-keys import { PROJECTS_LIST, PROJECT_DETAILS, USER_PROJECT_VIEW } from "constants/fetch-keys"; // helper import { truncateText } from "helpers/string.helper"; const featuresList = [ { title: "Cycles", description: "Cycles are enabled for all the projects in this workspace. Access them from the sidebar.", icon: , property: "cycle_view", }, { title: "Modules", description: "Modules are enabled for all the projects in this workspace. Access it from the sidebar.", icon: , property: "module_view", }, { title: "Views", description: "Views are enabled for all the projects in this workspace. Access it from the sidebar.", icon: , property: "issue_views_view", }, { title: "Pages", description: "Pages are enabled for all the projects in this workspace. Access it from the sidebar.", icon: , property: "page_view", }, { title: "Inbox", description: "Inbox are enabled for all the projects in this workspace. Access it from the issues views page.", icon: , property: "inbox_view", }, ]; 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"; case "Inbox": return toggle ? "TOGGLE_INBOX_ON" : "TOGGLE_INBOX_OFF"; default: throw new Error("Invalid feature"); } }; // services const projectService = new ProjectService(); const trackEventService = new TrackEventService(); const FeaturesSettings: NextPage = () => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { user } = useUserAuth(); 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 { data: memberDetails } = useSWR( workspaceSlug && projectId ? USER_PROJECT_VIEW(projectId.toString()) : null, workspaceSlug && projectId ? () => projectService.projectMemberMe(workspaceSlug.toString(), projectId.toString()) : null ); const handleSubmit = async (formData: Partial) => { if (!workspaceSlug || !projectId || !projectDetails) return; mutate( PROJECTS_LIST(workspaceSlug.toString(), { is_favorite: "all", }), (prevData) => prevData?.map((p) => (p.id === projectId ? { ...p, ...formData } : p)), false ); mutate( PROJECT_DETAILS(projectId as string), (prevData) => { if (!prevData) return prevData; return { ...prevData, ...formData }; }, false ); setToastAlert({ type: "success", title: "Success!", message: "Project feature updated successfully.", }); await projectService.updateProject(workspaceSlug as string, projectId as string, formData, user).catch(() => setToastAlert({ type: "error", title: "Error!", message: "Project feature could not be updated. Please try again.", }) ); }; const isAdmin = memberDetails?.role === 20; return ( router.back()}>

{`${truncateText(projectDetails?.name ?? "Project", 32)}`}

} /> } >

Features

{featuresList.map((feature) => (
{feature.icon}

{feature.title}

{feature.description}

{ trackEventService.trackMiscellaneousEvent( { workspaceId: (projectDetails?.workspace as any)?.id, workspaceSlug, projectId, projectIdentifier: projectDetails?.identifier, projectName: projectDetails?.name, }, getEventType(feature.title, !projectDetails?.[feature.property as keyof IProject]), user as IUser ); handleSubmit({ [feature.property]: !projectDetails?.[feature.property as keyof IProject], }); }} disabled={!isAdmin} size="sm" />
))}
); }; export default FeaturesSettings;