From d08565677402023f8c153adf81d37bbd5532a696 Mon Sep 17 00:00:00 2001 From: Pau Matas Date: Wed, 27 Mar 2024 18:09:16 +0100 Subject: [PATCH 1/2] style: form style refactor --- src/components/Combobox.tsx | 6 +- src/components/Form.tsx | 310 +++++++++++++++------------ src/components/MultiFileDropzone.tsx | 6 +- 3 files changed, 177 insertions(+), 145 deletions(-) diff --git a/src/components/Combobox.tsx b/src/components/Combobox.tsx index 8ae33d1..53538b9 100644 --- a/src/components/Combobox.tsx +++ b/src/components/Combobox.tsx @@ -24,10 +24,12 @@ export function Combobox({ options, value, setValue, + width = 80, }: { options: Option[] value: string setValue: Function + width?: number | string }) { const [open, setOpen] = React.useState(false) return ( @@ -38,7 +40,7 @@ export function Combobox({ variant="outline" role="combobox" aria-expanded={open} - className="w-80 justify-between" + className={`w-${width} justify-between`} > {value ? options.find((option) => option.value === value)?.label @@ -46,7 +48,7 @@ export function Combobox({ - + diff --git a/src/components/Form.tsx b/src/components/Form.tsx index 247dad7..ffb9da2 100644 --- a/src/components/Form.tsx +++ b/src/components/Form.tsx @@ -198,157 +198,187 @@ export function ProfileForm({ : undefined return ( -
- )} - className="space-y-8" - > - { - if (!field.value && default_year) { - field.value = default_year - field.onChange(default_year) - } +
+ + )} + className="space-y-8" + > +
+ ( + + Fitxers PDF + +
+ { + field.onChange(acceptedFiles) + }} + /> +
+
+ + Penja els teus apunts en format PDF. + + +
+ )} + /> +
+ ( + + Títol dels Apunts + + + + + + )} + /> + ( + + + + + + + )} + /> +
+
+
+ {PreselectedSubject === "AllSubjects" && ( + ( + + Assignatura + + + + Tria l'assignatura. + + )} + /> + )} + { + if (!field.value && default_year) { + field.value = default_year + field.onChange(default_year) + } - return ( - - Any - - - - - Any que has cursat l'assignatura. - - - ) - }} - /> - ( - - Fitxers PDF - -
- { - field.onChange(acceptedFiles) - }} - /> -
-
- - Penja els teus apunts en format PDF. - - -
- )} - /> - ( - - Nom dels Apunts - - - - El nom dels teus apunts. - - - )} - /> - {PreselectedSubject === "AllSubjects" && ( + return ( + + Any + + + + + Any que has cursat l'assignatura. + + + ) + }} + /> + ( + + Tipus + + + + Tria el tipus de document. + + )} + /> +
( - - Assignatura + - - Tria l'assignatura. +
+ Penjar com a anònim + + L'AED guarda sempre l'autor dels apunts. + L'opció d'anònim permet que no es mostrin als + altres usuaris. + +
)} /> - )} - - ( - - Tipus - - - - Tria el tipus de document. - - )} - /> - ( - - - - -
- Penjar com a anònim - - L'AED guarda sempre l'autor dels apunts. - L'opció d'anònim permet que no es mostrin als altres - usuaris. - -
-
+ {isAdmin && ( + ( + + Email + + + + + Email de l'autor/a dels apunts + + + + )} + /> )} - /> - {isAdmin && ( - ( - - Email - - - - - Email de l'autor/a dels apunts - - - - )} - /> - )} - - {isVisible && } - - + + {isVisible && } + + +
) } diff --git a/src/components/MultiFileDropzone.tsx b/src/components/MultiFileDropzone.tsx index 9e49f92..4243dee 100644 --- a/src/components/MultiFileDropzone.tsx +++ b/src/components/MultiFileDropzone.tsx @@ -8,7 +8,7 @@ import { DropzoneOptions, useDropzone } from "react-dropzone" import { twMerge } from "tailwind-merge" const variants = { - base: "relative rounded-md p-4 w-96 flex justify-center items-center flex-col cursor-pointer border border-dashed border-zinc-300 transition-colors duration-200 ease-in-out bg-zinc-100", + base: "relative rounded-md p-4 w-full flex justify-center items-center flex-col cursor-pointer border border-dashed border-zinc-300 transition-colors duration-200 ease-in-out bg-zinc-100", active: "border-2", disabled: "bg-gray-700 border-white/20 cursor-default pointer-events-none bg-opacity-30", @@ -120,7 +120,7 @@ const MultiFileDropzone = React.forwardRef(
- drag & drop or click to upload + Arrossega i deixa anar o fes clic per pujar fitxers
@@ -133,7 +133,7 @@ const MultiFileDropzone = React.forwardRef( {value?.map((file, i) => (
From 6a1ebb17615120406604f618306ea6c9e56f5539 Mon Sep 17 00:00:00 2001 From: Pau Matas Date: Wed, 27 Mar 2024 19:13:05 +0100 Subject: [PATCH 2/2] add: Post description (content) --- src/app/api/subject/post/create/route.ts | 13 +++++++++++-- src/components/Form.tsx | 16 +++++++++++++--- src/components/Post.tsx | 6 +++++- src/components/ui/Input.tsx | 4 +++- src/components/ui/Textarea.tsx | 24 ++++++++++++++++++++++++ src/lib/validators/post.ts | 1 + 6 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/components/ui/Textarea.tsx diff --git a/src/app/api/subject/post/create/route.ts b/src/app/api/subject/post/create/route.ts index 728ade6..fd515af 100644 --- a/src/app/api/subject/post/create/route.ts +++ b/src/app/api/subject/post/create/route.ts @@ -14,8 +14,16 @@ export async function POST(req: Request) { const body = await req.json() - const { pdf, title, year, assignatura, tipus, anonim, authorEmail } = - ApuntsPostValidator.parse(body) + const { + pdf, + title, + content, + year, + assignatura, + tipus, + anonim, + authorEmail, + } = ApuntsPostValidator.parse(body) const subject = await db.subject.findFirst({ where: { @@ -72,6 +80,7 @@ export async function POST(req: Request) { } }), ), + content: content, subjectId: subject.id, authorId: authorId, tipus: tipus as TipusType, diff --git a/src/components/Form.tsx b/src/components/Form.tsx index ffb9da2..d784d8a 100644 --- a/src/components/Form.tsx +++ b/src/components/Form.tsx @@ -24,12 +24,20 @@ import { ApuntsPostCreationRequest } from "@/lib/validators/post" import { uploadFiles } from "@/lib/uploadthing" import Fireworks from "react-canvas-confetti/dist/presets/fireworks" import { MultiFileDropzone } from "@/components/MultiFileDropzone" +import { Textarea } from "./ui/Textarea" const formSchema = z.object({ pdf: z.array(z.any()), title: z.string({ required_error: "Selecciona un títol", }), + content: z + .string() + .max(320, { + message: "La descripció ha de tenir com a màxim 320 caràcters.", + }) + .optional() + .default(""), year: z.string({ required_error: "Selecciona un any", }), @@ -65,6 +73,7 @@ export function ProfileForm({ mutationFn: async ({ pdf, title, + content, year, assignatura, tipus, @@ -74,6 +83,7 @@ export function ProfileForm({ const payload: ApuntsPostCreationRequest = { pdf, title, + content, year, assignatura, tipus, @@ -132,6 +142,7 @@ export function ProfileForm({ const payload: ApuntsPostCreationRequest = { pdf: res, title: data.title, + content: data.content, year: Number(data.year), assignatura: data.assignatura, tipus: data.tipus, @@ -252,11 +263,10 @@ export function ProfileForm({ render={({ field }) => ( - diff --git a/src/components/Post.tsx b/src/components/Post.tsx index ca4c3ac..292d32d 100644 --- a/src/components/Post.tsx +++ b/src/components/Post.tsx @@ -83,7 +83,11 @@ const Post: FC = ({ )} ref={pRef} > - {/* TODO: If we add text content for posts it needs to be here */} + {post.content ? ( +
+

{post.content}

+
+ ) : null} {postFiles ? postFiles.map( (url: ClientUploadedFileData, i: number) => ( diff --git a/src/components/ui/Input.tsx b/src/components/ui/Input.tsx index 9900814..213abd2 100644 --- a/src/components/ui/Input.tsx +++ b/src/components/ui/Input.tsx @@ -1,6 +1,7 @@ import * as React from "react" import { cn } from "@/lib/utils" +import { he } from "date-fns/locale" export interface InputProps extends React.InputHTMLAttributes {} @@ -11,7 +12,8 @@ const Input = React.forwardRef( {} + +const Textarea = React.forwardRef( + ({ className, ...props }, ref) => { + return ( +