From 6e702d6cc7014b1d96e8417624a5eca42456631a Mon Sep 17 00:00:00 2001 From: sriram veeraghanta Date: Sat, 30 Dec 2023 21:32:18 +0530 Subject: [PATCH] fix: project settings form not loading new data while switching between projects --- web/components/project/form.tsx | 12 +++++++++++- .../projects/[projectId]/settings/index.tsx | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/web/components/project/form.tsx b/web/components/project/form.tsx index 9af8c7831..2911e083b 100644 --- a/web/components/project/form.tsx +++ b/web/components/project/form.tsx @@ -1,4 +1,4 @@ -import { FC } from "react"; +import { FC, useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; // components import EmojiIconPicker from "components/emoji-icon-picker"; @@ -42,6 +42,7 @@ export const ProjectDetailsForm: FC = (props) => { control, setValue, setError, + reset, formState: { errors, isSubmitting }, } = useForm({ defaultValues: { @@ -51,6 +52,15 @@ export const ProjectDetailsForm: FC = (props) => { }, }); + useEffect(() => { + if (!project) return; + reset({ + ...project, + emoji_and_icon: project.emoji ?? project.icon_prop, + workspace: (project.workspace as IWorkspace).id, + }); + }, [project, reset]); + const handleIdentifierChange = (event: React.ChangeEvent) => { const { value } = event.target; diff --git a/web/pages/[workspaceSlug]/projects/[projectId]/settings/index.tsx b/web/pages/[workspaceSlug]/projects/[projectId]/settings/index.tsx index ef815ac82..bdff9bf10 100644 --- a/web/pages/[workspaceSlug]/projects/[projectId]/settings/index.tsx +++ b/web/pages/[workspaceSlug]/projects/[projectId]/settings/index.tsx @@ -29,7 +29,7 @@ const GeneralSettingsPage: NextPageWithLayout = observer(() => { const { workspaceSlug, projectId } = router.query; // api call to fetch project details useSWR( - workspaceSlug && projectId ? "PROJECT_DETAILS" : null, + workspaceSlug && projectId ? `PROJECT_DETAILS_${projectId}` : null, workspaceSlug && projectId ? () => projectStore.fetchProjectDetails(workspaceSlug.toString(), projectId.toString()) : null