From 03cf3b8e742795c419ebe147ae8a5b51806bb2c6 Mon Sep 17 00:00:00 2001 From: Aditya Choudhari Date: Mon, 21 Oct 2024 22:55:56 -0700 Subject: [PATCH] fix: Refresh then push for system create --- .../_components/CreateSystem.tsx | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/CreateSystem.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/CreateSystem.tsx index 02fddbde..4a285161 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/CreateSystem.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/CreateSystem.tsx @@ -56,22 +56,16 @@ export const CreateSystemDialog: React.FC<{ setValue("slug", slugify(data.name ?? "", { lower: true })); }); - const onSubmit = handleSubmit(async (system) => { - const systemSlug = system.slug; - await createSystem + const errMsg = "System with this slug already exists"; + const onSubmit = handleSubmit((system) => + createSystem .mutateAsync({ workspaceId: workspace.id, ...system }) - .then(() => { - router.push(`/${workspace.slug}/systems/${systemSlug}`); - router.refresh(); - setOpen(false); - onSuccess?.(); - }) - .catch(() => { - setError("root", { - message: "System with this slug already exists", - }); - }); - }); + .then(() => router.refresh()) + .then(() => router.push(`/${workspace.slug}/systems/${system.slug}`)) + .then(() => onSuccess?.()) + .then(() => setOpen(false)) + .catch(() => setError("root", { message: errMsg })), + ); return (