diff --git a/src/components/Admin/AdminProjects/Projects/editProject.tsx b/src/components/Admin/AdminProjects/Projects/editProject.tsx index a39f634..e64f860 100644 --- a/src/components/Admin/AdminProjects/Projects/editProject.tsx +++ b/src/components/Admin/AdminProjects/Projects/editProject.tsx @@ -1,4 +1,4 @@ -"use client" +"use client"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { api } from "~/trpc/react"; @@ -22,52 +22,44 @@ import { Input } from "~/components/ui/input"; import { Checkbox } from "~/components/ui/checkbox"; import { useState } from "react"; import { useRouter } from "next/navigation"; - - -type projectWithMembers = { - id: string, - name: string; - description: string; - link: string; - logoPublicId: string; - show: boolean - members: - | { - id: string; - name: string; - logoPublicId: string; - role: string; - }[] -; -} | undefined; - +import type { ProjectWithMembers } from "~/server/api/routers/project"; const formSchema = z.object({ - name: z.string({ - required_error: "Nome do projeto é necessário", - invalid_type_error: "O nome do projeto deve ser uma string" - }).min(1, { - message: "O nome do projeto não pode ser vazio" - }), - description: z.string({ - required_error: "A descrição do projeto é necessária", - invalid_type_error: "A descrição do projeto deve ser uma string" - }).min(1, { - message: "A descrição do projeto não pode ser vazia" - }), - link: z.string({ - required_error: "Link do projeto é necessário", - invalid_type_error: "Link do projeto deve ser uma string" - }).min(1, { - message: "O link do projeto não pode ser vazio" - }), + name: z + .string({ + required_error: "Nome do projeto é necessário", + invalid_type_error: "O nome do projeto deve ser uma string", + }) + .min(1, { + message: "O nome do projeto não pode ser vazio", + }), + description: z + .string({ + required_error: "A descrição do projeto é necessária", + invalid_type_error: "A descrição do projeto deve ser uma string", + }) + .min(1, { + message: "A descrição do projeto não pode ser vazia", + }), + link: z + .string({ + required_error: "Link do projeto é necessário", + invalid_type_error: "Link do projeto deve ser uma string", + }) + .min(1, { + message: "O link do projeto não pode ser vazio", + }), logoPublicId: z.string(), - show: z.boolean() + show: z.boolean(), }); type Form = z.infer; -export default function EditProject({projectWithMembers}: {projectWithMembers: projectWithMembers}) { +export default function EditProject({ + projectWithMembers, +}: { + projectWithMembers: ProjectWithMembers; +}) { const router = useRouter(); const [open, setOpen] = useState(false); const updateProject = api.project.updateProject.useMutation({ @@ -88,7 +80,7 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p background: "#F8F8FF", }, }); - } + }, }); const form = useForm
({ resolver: zodResolver(formSchema), @@ -98,7 +90,7 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p logoPublicId: projectWithMembers?.logoPublicId, link: projectWithMembers?.link, show: projectWithMembers?.show, - } + }, }); function onSubmit(values: Form) { if (projectWithMembers) { @@ -106,28 +98,39 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p id: projectWithMembers.id, data: { ...values, - logoPublidID: values.logoPublicId !== ""? values.logoPublicId : undefined - } + logoPublidID: + values.logoPublicId !== "" ? values.logoPublicId : undefined, + }, }; updateProject.mutate(res); } - }; + } return ( Editar Projeto - - Editando dados de {projectWithMembers?.name} + + + Editando dados de{" "} + {projectWithMembers?.name} + - + ( - + @@ -139,7 +142,11 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p render={({ field }) => ( - + @@ -151,7 +158,11 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p render={({ field }) => ( - + @@ -163,23 +174,44 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p render={({ field }) => ( - + )} /> -
- {if (typeof value === "boolean") form.setValue("show", value)}} className="size-6 border-struct-7"/> -

Mostrar?

-
+
+ { + if (typeof value === "boolean") form.setValue("show", value); + }} + className="size-6 border-struct-7" + /> +

Mostrar?

+
- - + +
- ) -} \ No newline at end of file + ); +} diff --git a/src/components/Admin/AdminProjects/Projects/page.tsx b/src/components/Admin/AdminProjects/Projects/page.tsx index bffa399..62d9620 100644 --- a/src/components/Admin/AdminProjects/Projects/page.tsx +++ b/src/components/Admin/AdminProjects/Projects/page.tsx @@ -5,32 +5,15 @@ import RemoveProject from "./removeProject"; import Link from "next/link"; import { CldImage } from "next-cloudinary"; import { Toaster } from "react-hot-toast"; - - -type projectWithMembers = { - id: string, - name: string; - description: string; - link: string; - logoPublicId: string; - show: boolean - members: - | { - id: string; - name: string; - logoPublicId: string; - role: string; - }[] -; -} | undefined; - +import type { ProjectWithMembers } from "~/server/api/routers/project"; +import { permanentRedirect } from "next/navigation"; export default function ProjectsPage({ projectWithMembers, }: { - projectWithMembers: projectWithMembers; + projectWithMembers: ProjectWithMembers | undefined; }) { - + if (!projectWithMembers) permanentRedirect("/"); return (
@@ -77,7 +60,8 @@ export default function ProjectsPage({

{projectWithMembers?.members?.map((member) => { - return ; + if (member) + return ; })}
diff --git a/src/components/Admin/AdminProjects/Projects/removeProject.tsx b/src/components/Admin/AdminProjects/Projects/removeProject.tsx index 72cd3ba..ad3c09b 100644 --- a/src/components/Admin/AdminProjects/Projects/removeProject.tsx +++ b/src/components/Admin/AdminProjects/Projects/removeProject.tsx @@ -1,4 +1,4 @@ -"use client" +"use client"; import { AlertDialog, AlertDialogAction, @@ -13,26 +13,13 @@ import { import toast from "react-hot-toast"; import { api } from "~/trpc/react"; import { useRouter } from "next/navigation"; +import type { ProjectWithMembers } from "~/server/api/routers/project"; -type projectWithMembers = { - id: string, - name: string; - description: string; - link: string; - logoPublicId: string; - show: boolean - members: - | { - id: string; - name: string; - logoPublicId: string; - role: string; - }[] -; -} | undefined; - - -export default function RemoveProject({ projectWithMembers }: { projectWithMembers: projectWithMembers}) { +export default function RemoveProject({ + projectWithMembers, +}: { + projectWithMembers: ProjectWithMembers; +}) { const router = useRouter(); const removeProject = api.project.removeProject.useMutation({ onSuccess: () => { @@ -52,26 +39,36 @@ export default function RemoveProject({ projectWithMembers }: { projectWithMembe background: "#F8F8FF", }, }); - } + }, }); return ( Remover Projeto - + Tem certeza? - Essa ação irá deletar todos os dados deste projeto. - Peça autorização antes de executar esta ação. + Essa ação irá deletar todos os dados deste projeto. Peça autorização + antes de executar esta ação. - Cancelar - {if (projectWithMembers?.id) removeProject.mutate({id: projectWithMembers?.id})}}>Remover Projeto + + Cancelar + + { + if (projectWithMembers?.id) + removeProject.mutate({ id: projectWithMembers?.id }); + }} + > + Remover Projeto + - ) -} \ No newline at end of file + ); +} diff --git a/src/components/Projects/page.tsx b/src/components/Projects/page.tsx index 08e8521..006dc35 100644 --- a/src/components/Projects/page.tsx +++ b/src/components/Projects/page.tsx @@ -51,7 +51,8 @@ export default function ProjectsPage({

{projectWithMembers.members?.map((member) => { - return ; + if (member) + return ; })}
diff --git a/src/server/api/routers/project.ts b/src/server/api/routers/project.ts index 2fba836..f9ee80e 100644 --- a/src/server/api/routers/project.ts +++ b/src/server/api/routers/project.ts @@ -180,7 +180,7 @@ type ProjectWithMembers = { link: string; logoPublicId: string; show: boolean; - members: Member[]; + members: (Member | undefined)[]; }; type MutatedProject = {