import { useEffect } from "react"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; // ui import { Button, Input, TextArea } from "@plane/ui"; // components import { AppliedFiltersList, FilterSelection, FiltersDropdown } from "components/issues"; // constants import { ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue"; // hooks import { useLabel, useMember } from "hooks/store"; // types import { IIssueFilterOptions, IWorkspaceView } from "@plane/types"; type Props = { handleFormSubmit: (values: Partial) => Promise; handleClose: () => void; data?: IWorkspaceView; preLoadedData?: Partial; }; const defaultValues: Partial = { name: "", description: "", }; export const WorkspaceViewForm: React.FC = observer((props) => { const { handleFormSubmit, handleClose, data, preLoadedData } = props; // store hooks const { workspaceLabels } = useLabel(); const { workspace: { workspaceMemberIds }, } = useMember(); const { formState: { errors, isSubmitting }, handleSubmit, control, reset, setValue, watch, } = useForm({ defaultValues, }); const handleCreateUpdateView = async (formData: Partial) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...preLoadedData, ...data, }); }, [data, preLoadedData, reset]); const selectedFilters: IIssueFilterOptions = watch("filters"); // filters whose value not null or empty array let appliedFilters: IIssueFilterOptions | undefined = undefined; Object.entries(selectedFilters ?? {}).forEach(([key, value]) => { if (!value) return; if (Array.isArray(value) && value.length === 0) return; if (!appliedFilters) appliedFilters = {}; appliedFilters[key as keyof IIssueFilterOptions] = value; }); const handleRemoveFilter = (key: keyof IIssueFilterOptions, value: string | null) => { // To clear all filters of any particular filter key. if (!value) { setValue("filters", { ...selectedFilters, [key]: [], }); return; } let newValues = selectedFilters?.[key] ?? []; newValues = newValues.filter((val) => val !== value); setValue("filters", { ...selectedFilters, [key]: newValues, }); }; const clearAllFilters = () => { if (!selectedFilters) return; setValue("filters", {}); }; return (

{data ? "Update" : "Create"} View

( )} />
(