feat: enhance AnnunciRichiesti component to support adding announcements to services and update dialog styling
This commit is contained in:
parent
a6a1a4fd4b
commit
366e17185c
3 changed files with 52 additions and 14 deletions
|
|
@ -523,7 +523,7 @@ const AddAnnuncio = ({
|
|||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent
|
||||
className="sm:max-w-106.25"
|
||||
className="sm:max-w-2xl"
|
||||
onInteractOutside={(e) => {
|
||||
if (selectedAnnunci.length !== 0) {
|
||||
e.preventDefault(); // Prevent closing the dialog if there are selected announcements
|
||||
|
|
|
|||
|
|
@ -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 <LoadingPage />;
|
||||
|
||||
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 && (
|
||||
<Button
|
||||
onClick={() => {
|
||||
deleteAnnuncio({ annuncioId: a.id, userId });
|
||||
addToServizio({ annunci: [a.id], servizioId });
|
||||
}}
|
||||
variant="success"
|
||||
>
|
||||
Aggiungi al servizio
|
||||
<Plus className="size-4" />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => {
|
||||
removeIterest({ annuncioId: a.id, userId });
|
||||
}}
|
||||
variant="destructive"
|
||||
>
|
||||
Rimuovi
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
key={a.id}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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<ServizioUserProps> = ({
|
|||
}
|
||||
return (
|
||||
<div className="mx-auto max-w-8xl grow space-y-4">
|
||||
<AnnunciRichiesti servizioId={servizioId} userId={userId} />
|
||||
<Servizio
|
||||
isAdmin={true}
|
||||
key={data.servizio_id}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue