diff --git a/apps/app/components/core/issues-view.tsx b/apps/app/components/core/issues-view.tsx index eb1e379c6..d55731c1e 100644 --- a/apps/app/components/core/issues-view.tsx +++ b/apps/app/components/core/issues-view.tsx @@ -401,7 +401,7 @@ export const IssuesView: React.FC = ({ setCreateViewModal(null)} - preLoadedData={createViewModal} + data={createViewModal} /> >; data: IView | null; - onClose: () => void; - onSuccess?: () => void; }; -export const DeleteViewModal: React.FC = ({ isOpen, data, onClose, onSuccess }) => { +export const DeleteViewModal: React.FC = ({ isOpen, data, setIsOpen }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); @@ -35,14 +34,14 @@ export const DeleteViewModal: React.FC = ({ isOpen, data, onClose, onSucc const { setToastAlert } = useToast(); const handleClose = () => { + setIsOpen(false); setIsDeleteLoading(false); - onClose(); }; const handleDeletion = async () => { setIsDeleteLoading(true); - if (!workspaceSlug || !data || !projectId) return; + await viewsService .deleteView(workspaceSlug as string, projectId as string, data.id) .then(() => { @@ -50,8 +49,6 @@ export const DeleteViewModal: React.FC = ({ isOpen, data, onClose, onSucc views?.filter((view) => view.id !== data.id) ); - if (onSuccess) onSuccess(); - handleClose(); setToastAlert({ @@ -66,6 +63,8 @@ export const DeleteViewModal: React.FC = ({ isOpen, data, onClose, onSucc title: "Error!", message: "View could not be deleted. Please try again.", }); + }) + .finally(() => { setIsDeleteLoading(false); }); }; @@ -111,10 +110,9 @@ export const DeleteViewModal: React.FC = ({ isOpen, data, onClose, onSucc

- Are you sure you want to delete view- {" "} - {data?.name} - ? All of the data related to the view will be permanently removed. - This action cannot be undone. + Are you sure you want to delete view-{" "} + {data?.name}? All of the data related + to the view will be permanently removed. This action cannot be undone.

diff --git a/apps/app/components/views/form.tsx b/apps/app/components/views/form.tsx index fffa7bfcc..891410241 100644 --- a/apps/app/components/views/form.tsx +++ b/apps/app/components/views/form.tsx @@ -1,8 +1,5 @@ import { useEffect } from "react"; -import { useRouter } from "next/router"; - -import useSWR from "swr"; import { useForm } from "react-hook-form"; // ui @@ -11,11 +8,6 @@ import { Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; import { FilterList } from "components/core"; // types import { IView } from "types"; -// constant -import { STATE_LIST } from "constants/fetch-keys"; - -// services -import stateService from "services/state.service"; // components import { SelectFilters } from "components/views"; @@ -23,8 +15,7 @@ type Props = { handleFormSubmit: (values: IView) => Promise; handleClose: () => void; status: boolean; - data?: IView; - preLoadedData?: Partial | null; + data?: IView | null; }; const defaultValues: Partial = { @@ -32,13 +23,7 @@ const defaultValues: Partial = { description: "", }; -export const ViewForm: React.FC = ({ - handleFormSubmit, - handleClose, - status, - data, - preLoadedData, -}) => { +export const ViewForm: React.FC = ({ handleFormSubmit, handleClose, status, data }) => { const { register, formState: { errors, isSubmitting }, @@ -49,6 +34,7 @@ export const ViewForm: React.FC = ({ } = useForm({ defaultValues, }); + const filters = watch("query"); const handleCreateUpdateView = async (formData: IView) => { await handleFormSubmit(formData); @@ -66,13 +52,10 @@ export const ViewForm: React.FC = ({ }, [data, reset]); useEffect(() => { - reset({ - ...defaultValues, - ...preLoadedData, - }); - }, [preLoadedData, reset]); - - const filters = watch("query"); + if (status && data) { + setValue("query", data.query_data); + } + }, [data, status, setValue]); return (
@@ -84,18 +67,19 @@ export const ViewForm: React.FC = ({
@@ -104,8 +88,9 @@ export const ViewForm: React.FC = ({