From 366e17185c3ebd4fd91d246ba12fc5e900d500bb Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Mon, 9 Mar 2026 11:07:35 +0100 Subject: [PATCH] feat: enhance AnnunciRichiesti component to support adding announcements to services and update dialog styling --- .../components/servizio/servizio_actions.tsx | 2 +- .../servizio/servizio_annunci_accordions.tsx | 62 +++++++++++++++---- .../admin/user-view/servizio/[...slug].tsx | 2 + 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/apps/infoalloggi/src/components/servizio/servizio_actions.tsx b/apps/infoalloggi/src/components/servizio/servizio_actions.tsx index 3450e98..7705063 100644 --- a/apps/infoalloggi/src/components/servizio/servizio_actions.tsx +++ b/apps/infoalloggi/src/components/servizio/servizio_actions.tsx @@ -523,7 +523,7 @@ const AddAnnuncio = ({ { if (selectedAnnunci.length !== 0) { e.preventDefault(); // Prevent closing the dialog if there are selected announcements diff --git a/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx b/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx index de2dcc1..76d36ac 100644 --- a/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx +++ b/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx @@ -1,4 +1,4 @@ -import { Trash2 } from "lucide-react"; +import { Plus, Trash2 } from "lucide-react"; import toast from "react-hot-toast"; import { BasicAnnuncioCard } from "~/components/servizio/annuncio_card"; import { @@ -8,22 +8,45 @@ import { AccordionTrigger, } from "~/components/ui/accordion"; import { Button } from "~/components/ui/button"; +import type { ServizioServizioId } from "~/schemas/public/Servizio"; import type { UsersId } from "~/schemas/public/Users"; import { api } from "~/utils/api"; import { LoadingPage } from "../loading"; -export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => { +export const AnnunciRichiesti = ({ + userId, + servizioId, +}: { + userId: UsersId; + servizioId?: ServizioServizioId; +}) => { const { data, isLoading } = api.intrests.getUserInterestsAnnunci.useQuery({ userId, }); const utils = api.useUtils(); - const { mutate: deleteAnnuncio } = api.intrests.removeIntrest.useMutation({ + const { mutate: removeIterest } = api.intrests.removeIntrest.useMutation({ onSuccess: async () => { await utils.intrests.getUserInterestsAnnunci.invalidate({ userId }); - toast.success("Annuncio rimosso con successo"); + toast.success("Interesse rimosso con successo"); + }, + onError: (error) => { + console.error(error); + toast.error("Errore durante la rimozione dell'interesse"); }, }); + const { mutate: addToServizio } = api.servizio.addServizioAnnunci.useMutation( + { + onError: (error) => { + console.error(error); + toast.error("Errore durante l'aggiunta dell'annuncio"); + }, + onSuccess: async () => { + await utils.servizio.invalidate(); + toast.success("Annuncio aggiunto"); + }, + }, + ); if (isLoading) return ; if (!data || data.length === 0) return null; @@ -45,15 +68,28 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => { className="w-full border-2 border-pink-500" data={a} interactions={ - + <> + {servizioId && ( + + )} + + } key={a.id} /> diff --git a/apps/infoalloggi/src/pages/area-riservata/admin/user-view/servizio/[...slug].tsx b/apps/infoalloggi/src/pages/area-riservata/admin/user-view/servizio/[...slug].tsx index 1c6327f..027d6e3 100644 --- a/apps/infoalloggi/src/pages/area-riservata/admin/user-view/servizio/[...slug].tsx +++ b/apps/infoalloggi/src/pages/area-riservata/admin/user-view/servizio/[...slug].tsx @@ -2,6 +2,7 @@ import type { GetServerSideProps } from "next"; import { AreaRiservataLayoutUserView } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { Servizio } from "~/components/servizio/servizio"; +import { AnnunciRichiesti } from "~/components/servizio/servizio_annunci_accordions"; import { Status500 } from "~/components/status-page"; import type { NextPageWithLayout } from "~/pages/_app"; import type { ServizioServizioId } from "~/schemas/public/Servizio"; @@ -30,6 +31,7 @@ const ServizioUser: NextPageWithLayout = ({ } return (
+