Skip to content

Commit

Permalink
fix: Refresh then push for system create
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Oct 22, 2024
1 parent 9c133d9 commit 03cf3b8
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Dialog open={open} onOpenChange={setOpen}>
Expand Down

0 comments on commit 03cf3b8

Please sign in to comment.