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>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className="sm:max-w-106.25"
|
className="sm:max-w-2xl"
|
||||||
onInteractOutside={(e) => {
|
onInteractOutside={(e) => {
|
||||||
if (selectedAnnunci.length !== 0) {
|
if (selectedAnnunci.length !== 0) {
|
||||||
e.preventDefault(); // Prevent closing the dialog if there are selected announcements
|
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 toast from "react-hot-toast";
|
||||||
import { BasicAnnuncioCard } from "~/components/servizio/annuncio_card";
|
import { BasicAnnuncioCard } from "~/components/servizio/annuncio_card";
|
||||||
import {
|
import {
|
||||||
|
|
@ -8,22 +8,45 @@ import {
|
||||||
AccordionTrigger,
|
AccordionTrigger,
|
||||||
} from "~/components/ui/accordion";
|
} from "~/components/ui/accordion";
|
||||||
import { Button } from "~/components/ui/button";
|
import { Button } from "~/components/ui/button";
|
||||||
|
import type { ServizioServizioId } from "~/schemas/public/Servizio";
|
||||||
import type { UsersId } from "~/schemas/public/Users";
|
import type { UsersId } from "~/schemas/public/Users";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
import { LoadingPage } from "../loading";
|
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({
|
const { data, isLoading } = api.intrests.getUserInterestsAnnunci.useQuery({
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
const { mutate: deleteAnnuncio } = api.intrests.removeIntrest.useMutation({
|
const { mutate: removeIterest } = api.intrests.removeIntrest.useMutation({
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
await utils.intrests.getUserInterestsAnnunci.invalidate({ userId });
|
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 (isLoading) return <LoadingPage />;
|
||||||
|
|
||||||
if (!data || data.length === 0) return null;
|
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"
|
className="w-full border-2 border-pink-500"
|
||||||
data={a}
|
data={a}
|
||||||
interactions={
|
interactions={
|
||||||
|
<>
|
||||||
|
{servizioId && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
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"
|
variant="destructive"
|
||||||
>
|
>
|
||||||
Rimuovi
|
Rimuovi
|
||||||
<Trash2 className="size-4" />
|
<Trash2 className="size-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
key={a.id}
|
key={a.id}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import type { GetServerSideProps } from "next";
|
||||||
import { AreaRiservataLayoutUserView } from "~/components/Layout";
|
import { AreaRiservataLayoutUserView } from "~/components/Layout";
|
||||||
import { LoadingPage } from "~/components/loading";
|
import { LoadingPage } from "~/components/loading";
|
||||||
import { Servizio } from "~/components/servizio/servizio";
|
import { Servizio } from "~/components/servizio/servizio";
|
||||||
|
import { AnnunciRichiesti } from "~/components/servizio/servizio_annunci_accordions";
|
||||||
import { Status500 } from "~/components/status-page";
|
import { Status500 } from "~/components/status-page";
|
||||||
import type { NextPageWithLayout } from "~/pages/_app";
|
import type { NextPageWithLayout } from "~/pages/_app";
|
||||||
import type { ServizioServizioId } from "~/schemas/public/Servizio";
|
import type { ServizioServizioId } from "~/schemas/public/Servizio";
|
||||||
|
|
@ -30,6 +31,7 @@ const ServizioUser: NextPageWithLayout<ServizioUserProps> = ({
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto max-w-8xl grow space-y-4">
|
<div className="mx-auto max-w-8xl grow space-y-4">
|
||||||
|
<AnnunciRichiesti servizioId={servizioId} userId={userId} />
|
||||||
<Servizio
|
<Servizio
|
||||||
isAdmin={true}
|
isAdmin={true}
|
||||||
key={data.servizio_id}
|
key={data.servizio_id}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue