From f8cb9f84f459c5092f38b3b384f1af9e3973aded Mon Sep 17 00:00:00 2001 From: Bartosz Gotowski Date: Tue, 30 Apr 2024 15:35:28 +0200 Subject: [PATCH 01/33] fix(projects): automatically move to new project --- components/dashboard/projects/add.tsx | 21 ++++++++++++--------- server/api/routers/project.ts | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/components/dashboard/projects/add.tsx b/components/dashboard/projects/add.tsx index d2b91ce16..a2797539b 100644 --- a/components/dashboard/projects/add.tsx +++ b/components/dashboard/projects/add.tsx @@ -21,7 +21,8 @@ import { Textarea } from "@/components/ui/textarea"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { AlertTriangle, PlusIcon } from "lucide-react"; -import { useEffect } from "react"; +import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; @@ -37,10 +38,9 @@ type AddProject = z.infer; export const AddProject = () => { const utils = api.useUtils(); - - const { mutateAsync, isLoading, error, isError } = - api.project.create.useMutation(); - + const [isOpen, setIsOpen] = useState(false); + const { mutateAsync, error, isError } = api.project.create.useMutation(); + const router = useRouter(); const form = useForm({ defaultValues: { description: "", @@ -61,16 +61,19 @@ export const AddProject = () => { name: data.name, description: data.description, }) - .then(async () => { - toast.success("Project Created"); + .then(async (data) => { await utils.project.all.invalidate(); + toast.success("Project Created"); + setIsOpen(false); + router.push(`/dashboard/project/${data.projectId}`); }) .catch(() => { toast.error("Error to create a project"); }); }; + return ( - +