import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { ContrastIcon, FileText, Inbox, Layers } from "lucide-react"; import { DiceIcon, ToggleSwitch } from "@plane/ui"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // services import { MiscellaneousEventType, TrackEventService } from "services/track_event.service"; // hooks import useToast from "hooks/use-toast"; // types import { IProject } from "types"; type Props = {}; const PROJECT_FEATURES_LIST = [ { 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 trackEventService = new TrackEventService(); export const ProjectFeaturesList: React.FC = observer((props) => { const {} = props; const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { project: projectStore, user: userStore } = useMobxStore(); const projectDetails = projectId ? projectStore.project_details[projectId.toString()] : undefined; const user = userStore.currentUser ?? undefined; const isAdmin = userStore.projectMemberInfo?.role === 20; const { setToastAlert } = useToast(); const handleSubmit = async (formData: Partial) => { if (!workspaceSlug || !projectId || !projectDetails) return; setToastAlert({ type: "success", title: "Success!", message: "Project feature updated successfully.", }); projectStore.updateProject(workspaceSlug.toString(), projectId.toString(), formData); }; return ( {PROJECT_FEATURES_LIST.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 ); handleSubmit({ [feature.property]: !projectDetails?.[feature.property as keyof IProject], }); }} disabled={!isAdmin} size="sm" /> ))} ); });
{feature.description}