Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/StructCE/site-struct-2024 i…
Browse files Browse the repository at this point in the history
…nto production
  • Loading branch information
MatheusNevs committed Oct 27, 2024
2 parents 40406ed + c207db8 commit 9ae0451
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 112 deletions.
152 changes: 92 additions & 60 deletions src/components/Admin/AdminProjects/Projects/editProject.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client"
"use client";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { api } from "~/trpc/react";
Expand All @@ -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<typeof formSchema>;

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({
Expand All @@ -88,7 +80,7 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p
background: "#F8F8FF",
},
});
}
},
});
const form = useForm<Form>({
resolver: zodResolver(formSchema),
Expand All @@ -98,36 +90,47 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p
logoPublicId: projectWithMembers?.logoPublicId,
link: projectWithMembers?.link,
show: projectWithMembers?.show,
}
},
});
function onSubmit(values: Form) {
if (projectWithMembers) {
const res = {
id: projectWithMembers.id,
data: {
...values,
logoPublidID: values.logoPublicId !== ""? values.logoPublicId : undefined
}
logoPublidID:
values.logoPublicId !== "" ? values.logoPublicId : undefined,
},
};
updateProject.mutate(res);
}
};
}
return (
<AlertDialog open={open} onOpenChange={setOpen}>
<AlertDialogTrigger className="h-14 rounded-md border-[3px] border-yellow-300 bg-fundo-0 px-6 font-oxanium text-[24px] font-bold text-struct-7 transition ease-in-out hover:bg-fundo-2">
Editar Projeto
</AlertDialogTrigger>
<AlertDialogContent className="bg-fundo-3 border-none w-[500px] flex flex-col items-center">
<AlertDialogTitle>Editando dados de <span className="text-struct-1"> {projectWithMembers?.name} </span></AlertDialogTitle>
<AlertDialogContent className="flex w-[500px] flex-col items-center border-none bg-fundo-3">
<AlertDialogTitle>
Editando dados de{" "}
<span className="text-struct-1"> {projectWithMembers?.name} </span>
</AlertDialogTitle>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="px-10 w-full h-fit flex flex-col gap-5 items-center justify-start">
<form
onSubmit={form.handleSubmit(onSubmit)}
className="flex h-fit w-full flex-col items-center justify-start gap-5 px-10"
>
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem className="w-full">
<FormControl>
<Input placeholder="Nome" {...field} className="font-nunito text-[20px] text-start bg-fundo-1 border-none"/>
<Input
placeholder="Nome"
{...field}
className="border-none bg-fundo-1 text-start font-nunito text-[20px]"
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -139,7 +142,11 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p
render={({ field }) => (
<FormItem className="w-full">
<FormControl>
<Input placeholder="Descrição" {...field} className="font-nunito text-[20px] text-start bg-fundo-1 border-none"/>
<Input
placeholder="Descrição"
{...field}
className="border-none bg-fundo-1 text-start font-nunito text-[20px]"
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -151,7 +158,11 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p
render={({ field }) => (
<FormItem className="w-full">
<FormControl>
<Input placeholder="Imagem (URL da Cloudinary)" {...field} className="font-nunito text-[20px] text-start bg-fundo-1 border-none"/>
<Input
placeholder="Imagem (URL da Cloudinary)"
{...field}
className="border-none bg-fundo-1 text-start font-nunito text-[20px]"
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -163,23 +174,44 @@ export default function EditProject({projectWithMembers}: {projectWithMembers: p
render={({ field }) => (
<FormItem className="w-full">
<FormControl>
<Input placeholder="Link (url Completa)" {...field} className="font-nunito text-[20px] text-start bg-fundo-1 border-none"/>
<Input
placeholder="Link (url Completa)"
{...field}
className="border-none bg-fundo-1 text-start font-nunito text-[20px]"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="w-full flex items-center justify-start gap-3">
<Checkbox defaultChecked={projectWithMembers?.show} onCheckedChange={(value) => {if (typeof value === "boolean") form.setValue("show", value)}} className="size-6 border-struct-7"/>
<p>Mostrar?</p>
</div>
<div className="flex w-full items-center justify-start gap-3">
<Checkbox
defaultChecked={projectWithMembers?.show}
onCheckedChange={(value) => {
if (typeof value === "boolean") form.setValue("show", value);
}}
className="size-6 border-struct-7"
/>
<p>Mostrar?</p>
</div>
<AlertDialogFooter>
<button type="button" onClick={() => setOpen(false)} className="px-4 py-2 h-10 rounded-md bg-white font-nunito font-bold text-black hover:scale-[1.02]">Cancelar</button>
<button type="submit" className="px-4 py-2 h-10 rounded-md bg-primary font-nunito font-bold hover:scale-[1.02]">Salvar Mudanças</button>
<button
type="button"
onClick={() => setOpen(false)}
className="h-10 rounded-md bg-white px-4 py-2 font-nunito font-bold text-black hover:scale-[1.02]"
>
Cancelar
</button>
<button
type="submit"
className="h-10 rounded-md bg-primary px-4 py-2 font-nunito font-bold hover:scale-[1.02]"
>
Salvar Mudanças
</button>
</AlertDialogFooter>
</form>
</Form>
</AlertDialogContent>
</AlertDialog>
)
}
);
}
28 changes: 6 additions & 22 deletions src/components/Admin/AdminProjects/Projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<section className="flex items-center bg-fundo-0 pt-28">
<Toaster position="bottom-center" reverseOrder={false} />
Expand Down Expand Up @@ -77,7 +60,8 @@ export default function ProjectsPage({
</p>
<div className="flex h-fit w-[1300px] flex-wrap items-center justify-center max-[1440px]:w-[500px] max-[830px]:w-[280px]">
{projectWithMembers?.members?.map((member) => {
return <AdminMemberCard key={member.name} member={member} />;
if (member)
return <AdminMemberCard key={member.name} member={member} />;
})}
</div>
</div>
Expand Down
53 changes: 25 additions & 28 deletions src/components/Admin/AdminProjects/Projects/removeProject.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client"
"use client";
import {
AlertDialog,
AlertDialogAction,
Expand All @@ -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: () => {
Expand All @@ -52,26 +39,36 @@ export default function RemoveProject({ projectWithMembers }: { projectWithMembe
background: "#F8F8FF",
},
});
}
},
});
return (
<AlertDialog>
<AlertDialogTrigger className="h-14 rounded-md border-[3px] border-red-600 bg-fundo-0 px-6 font-oxanium text-[24px] font-bold text-struct-7 transition ease-in-out hover:bg-fundo-2">
Remover Projeto
</AlertDialogTrigger>
<AlertDialogContent className="bg-fundo-3 border-none">
<AlertDialogContent className="border-none bg-fundo-3">
<AlertDialogHeader>
<AlertDialogTitle>Tem certeza?</AlertDialogTitle>
<AlertDialogDescription>
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.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel className="text-black hover:scale-[1.02]">Cancelar</AlertDialogCancel>
<AlertDialogAction className="hover:scale-[1.02]" onClick={() => {if (projectWithMembers?.id) removeProject.mutate({id: projectWithMembers?.id})}}>Remover Projeto</AlertDialogAction>
<AlertDialogCancel className="text-black hover:scale-[1.02]">
Cancelar
</AlertDialogCancel>
<AlertDialogAction
className="hover:scale-[1.02]"
onClick={() => {
if (projectWithMembers?.id)
removeProject.mutate({ id: projectWithMembers?.id });
}}
>
Remover Projeto
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}
);
}
3 changes: 2 additions & 1 deletion src/components/Projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default function ProjectsPage({
</p>
<div className="flex h-fit w-[1300px] flex-wrap items-center justify-center max-[1440px]:w-[500px] max-[830px]:w-[280px]">
{projectWithMembers.members?.map((member) => {
return <MemberContainer key={member.name} member={member} />;
if (member)
return <MemberContainer key={member.name} member={member} />;
})}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/routers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ type ProjectWithMembers = {
link: string;
logoPublicId: string;
show: boolean;
members: Member[];
members: (Member | undefined)[];
};

type MutatedProject = {
Expand Down

0 comments on commit 9ae0451

Please sign in to comment.