import { FC, Fragment, useCallback, useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { Dialog, Transition } from "@headlessui/react"; import { Briefcase, Globe2, Plus, X } from "lucide-react"; // hooks import { useViewDetail, useProject } from "hooks/store"; // components import { ViewAppliedFiltersRoot, ViewFiltersDropdown } from "../"; // ui import { Input, Button } from "@plane/ui"; // types import { TViewTypes } from "@plane/types"; import { TViewOperations } from "../types"; // constants import { EViewPageType } from "constants/view"; type TViewCreateEditForm = { workspaceSlug: string; projectId: string | undefined; viewId: string; viewType: TViewTypes; viewPageType: EViewPageType; viewOperations: TViewOperations; }; export const ViewCreateEditForm: FC = observer((props) => { const { workspaceSlug, projectId, viewId, viewType, viewPageType, viewOperations } = props; // hooks const viewDetailStore = useViewDetail(workspaceSlug, projectId, viewId, viewType); const { getProjectById } = useProject(); // states const [modalToggle, setModalToggle] = useState(false); const [loader, setLoader] = useState(false); const modalOpen = useCallback(() => setModalToggle(true), [setModalToggle]); const modalClose = useCallback(() => { setModalToggle(false); setTimeout(() => { viewOperations.localViewCreateEditClear(viewId); }, 200); }, [viewId, setModalToggle, viewOperations]); useEffect(() => { if (viewId) modalOpen(); }, [viewId, modalOpen, modalClose]); const onContinue = async () => { setLoader(true); if (viewDetailStore?.is_create) { const payload = viewDetailStore?.filtersToUpdate; await viewOperations.create(payload); modalClose(); } else { const payload = viewDetailStore?.filtersToUpdate; if (!payload) return; await viewOperations.update(); modalClose(); } setLoader(false); }; const projectDetails = projectId ? getProjectById(projectId) : undefined; if (!viewDetailStore) return <>; return (
{projectId && projectDetails ? (
{projectDetails?.identifier || "Project"}
) : (
Workspace
)}
Save View
{ viewDetailStore?.setName(e.target.value); }} placeholder="What do you want to call this view?" className="h-[46px] w-full border border-onboarding-border-100 pr-12 placeholder:text-onboarding-text-400" autoFocus />
Filters
{viewDetailStore?.isFiltersApplied && (
{ viewDetailStore.setFilters(undefined, "clear_all"); }} >
Clear all filters
)}
); });