From d6cd5f86b8dd6625ec71a1a8377398b625d31815 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Fri, 20 Mar 2026 14:06:55 +0100 Subject: [PATCH] feat: add note column to servizio_annunci table and implement AnnuncioNote component for admin annotations --- .../39_servizio_annuncio_note.up.sql | 2 + .../src/components/servizio/annuncio_card.tsx | 93 +++++++++++++++++-- .../src/schemas/public/ServizioAnnunci.ts | 2 + 3 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 apps/db/migrations/39_servizio_annuncio_note.up.sql diff --git a/apps/db/migrations/39_servizio_annuncio_note.up.sql b/apps/db/migrations/39_servizio_annuncio_note.up.sql new file mode 100644 index 0000000..73db9ee --- /dev/null +++ b/apps/db/migrations/39_servizio_annuncio_note.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS public.servizio_annunci +ADD COLUMN IF NOT EXISTS note TEXT; \ No newline at end of file diff --git a/apps/infoalloggi/src/components/servizio/annuncio_card.tsx b/apps/infoalloggi/src/components/servizio/annuncio_card.tsx index c7781c7..fb7ccbc 100644 --- a/apps/infoalloggi/src/components/servizio/annuncio_card.tsx +++ b/apps/infoalloggi/src/components/servizio/annuncio_card.tsx @@ -1,16 +1,22 @@ -import { Toolbox } from "lucide-react"; +import { NotebookPen, Toolbox } from "lucide-react"; import Image from "next/image"; +import { useState } from "react"; +import toast from "react-hot-toast"; +import LoadingButton from "~/components/custom_ui/loading-button"; +import { Textarea } from "~/components/custom_ui/textarea"; import { AdminActions, UserActions, } from "~/components/servizio/annuncio_actions"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; +import { useMediaQuery } from "~/hooks/use-media-query"; import { handleConsegna } from "~/lib/annuncio_details"; import { getStorageUrl } from "~/lib/storage_utils"; import { cn, formatCurrency } from "~/lib/utils"; import { useTranslation } from "~/providers/I18nProvider"; import { useServizio, useServizioAnnuncio } from "~/providers/ServizioProvider"; import type { AnnuncioRicerca } from "~/server/controllers/annunci.controller"; +import { api } from "~/utils/api"; import { Button } from "../ui/button"; import { Collapsible, @@ -67,10 +73,11 @@ export const BasicAnnuncioCard = ({ className?: string; data: AnnuncioRicerca; }) => { + const { isAdmin } = useServizio(); return ( @@ -79,17 +86,87 @@ export const BasicAnnuncioCard = ({
- -
{interactions}
+
+ + +
{interactions}
+
+ {isAdmin && }
); }; +const AnnuncioNote = () => { + const { servizioId } = useServizio(); + const { data } = useServizioAnnuncio(); + + const [newNote, setNewNote] = useState(data.note || ""); + const utils = api.useUtils(); + const { mutate, isPending } = api.servizio.updateServizioAnnunci.useMutation({ + onSuccess: async () => { + toast.success("Note aggiornate"); + await utils.servizio.invalidate(); + }, + onError: () => { + toast.error("Errore nell'aggiornamento note"); + }, + }); + const isDesktop = useMediaQuery("(min-width: 40rem)"); + + return ( + + + + + +
+