// react import React, { useEffect } from "react"; // swr import useSWR, { mutate } from "swr"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // layouts import SettingsLayout from "layouts/settings-layout"; // services import projectService from "lib/services/project.service"; import workspaceService from "lib/services/workspace.service"; // hooks import useToast from "lib/hooks/useToast"; import useUser from "lib/hooks/useUser"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // ui import { BreadcrumbItem, Breadcrumbs, Button } from "ui"; // icons import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline"; // types import { IProject, IWorkspace } from "types"; // fetch-keys import { PROJECTS_LIST, PROJECT_DETAILS, WORKSPACE_MEMBERS } from "constants/fetch-keys"; const ControlSettings = () => { const { activeWorkspace, activeProject } = useUser(); const { setToastAlert } = useToast(); const { data: projectDetails } = useSWR( activeWorkspace && activeProject ? PROJECT_DETAILS(activeProject.id) : null, activeWorkspace && activeProject ? () => projectService.getProject(activeWorkspace.slug, activeProject.id) : null ); const { data: people } = useSWR( activeWorkspace ? WORKSPACE_MEMBERS : null, activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null ); const { handleSubmit, reset, control, formState: { isSubmitting }, } = useForm({}); const onSubmit = async (formData: IProject) => { if (!activeWorkspace || !activeProject) return; const payload: Partial = { name: formData.name, network: formData.network, identifier: formData.identifier, description: formData.description, default_assignee: formData.default_assignee, project_lead: formData.project_lead, icon: formData.icon, }; await projectService .updateProject(activeWorkspace.slug, activeProject.id, payload) .then((res) => { mutate( PROJECT_DETAILS(activeProject.id), (prevData) => ({ ...prevData, ...res }), false ); mutate( PROJECTS_LIST(activeWorkspace.slug), (prevData) => { const newData = prevData?.map((item) => { if (item.id === res.id) { return res; } return item; }); return newData; }, false ); setToastAlert({ title: "Success", type: "success", message: "Project updated successfully", }); }) .catch((err) => { console.log(err); }); }; useEffect(() => { projectDetails && reset({ ...projectDetails, default_assignee: projectDetails.default_assignee?.id, project_lead: projectDetails.project_lead?.id, workspace: (projectDetails.workspace as IWorkspace).id, }); }, [projectDetails, reset]); return ( } >

Control

Set the control for the project.

Project Lead

Select the project leader.

( {({ open }) => ( <>
{people?.find((person) => person.member.id === value)?.member .first_name ?? "Select Lead"} {people?.map((person) => ( `${ active ? "bg-indigo-50" : "" } text-gray-900 cursor-default select-none relative px-3 py-2` } value={person.member.id} > {({ selected, active }) => ( <> {person.member.first_name !== "" ? person.member.first_name : person.member.email} {selected ? ( ) : null} )} ))}
)}
)} />

Default Assignee

Select the default assignee for the project.

( {({ open }) => ( <>
{people?.find((p) => p.member.id === value)?.member.first_name ?? "Select Default Assignee"} {people?.map((person) => ( `${ active ? "bg-indigo-50" : "" } text-gray-900 cursor-default select-none relative px-3 py-2` } value={person.member.id} > {({ selected, active }) => ( <> {person.member.first_name !== "" ? person.member.first_name : person.member.email} {selected ? ( ) : null} )} ))}
)}
)} />
); }; export default ControlSettings;