2025-12-04 17:16:49 +01:00
|
|
|
import { CheckCircle } from "lucide-react";
|
2025-11-11 15:41:07 +01:00
|
|
|
import { useState } from "react";
|
2025-11-07 17:03:08 +01:00
|
|
|
import { useServizio } from "~/providers/ServizioProvider";
|
|
|
|
|
import { api } from "~/utils/api";
|
2025-11-17 19:01:21 +01:00
|
|
|
import { CardAnnuncio } from "../annuncio_card";
|
2025-11-07 17:03:08 +01:00
|
|
|
import { InteressatoButtonServizio } from "../annuncio-interactions/annuncio_interactions";
|
|
|
|
|
import { LoadingPage } from "../loading";
|
2025-12-04 17:16:49 +01:00
|
|
|
import { Badge } from "../ui/badge";
|
2025-11-07 17:03:08 +01:00
|
|
|
import { Button } from "../ui/button";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogClose,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogTrigger,
|
|
|
|
|
} from "../ui/dialog";
|
2025-11-11 15:41:07 +01:00
|
|
|
import { Label } from "../ui/label";
|
|
|
|
|
import { Switch } from "../ui/switch";
|
2025-11-17 19:01:21 +01:00
|
|
|
import { AnnuncioDettaglio } from "./annuncio_dettaglio";
|
2025-11-07 17:03:08 +01:00
|
|
|
|
|
|
|
|
export const AnnunciCompatibili = () => {
|
2025-11-11 15:41:07 +01:00
|
|
|
const { servizioId, isAdmin } = useServizio();
|
|
|
|
|
const [adminOverride, setAdminOverride] = useState(false);
|
2025-11-07 17:03:08 +01:00
|
|
|
const { data, isLoading } = api.servizio.getCompatibileAnnunci.useQuery({
|
|
|
|
|
servizioId,
|
2025-11-11 15:41:07 +01:00
|
|
|
adminOverride,
|
2025-11-07 17:03:08 +01:00
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<Dialog>
|
|
|
|
|
<DialogTrigger asChild>
|
2025-11-17 19:01:21 +01:00
|
|
|
<Button className="w-full bg-purple-500 hover:bg-purple-600 sm:w-fit dark:text-white">
|
2025-11-07 17:03:08 +01:00
|
|
|
Esplora Annunci Compatibili
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogTrigger>
|
2025-11-11 15:41:07 +01:00
|
|
|
<DialogContent className="max-w-xl p-2 sm:max-w-5xl sm:p-6 md:max-w-7xl 2xl:max-w-[100rem]">
|
|
|
|
|
<DialogHeader className="flex-row flex-wrap items-center gap-5 pt-6">
|
|
|
|
|
<DialogTitle>
|
2025-12-18 12:11:08 +01:00
|
|
|
Annunci compatibili con i parametri del servizio
|
2025-11-07 17:03:08 +01:00
|
|
|
</DialogTitle>
|
2025-11-11 15:41:07 +01:00
|
|
|
{isAdmin && (
|
|
|
|
|
<div className="flex flex-wrap items-center gap-x-2">
|
|
|
|
|
<Label htmlFor="adminOverride">
|
2025-12-18 12:11:08 +01:00
|
|
|
Ignora limitazioni parametri
|
2025-11-11 15:41:07 +01:00
|
|
|
</Label>
|
|
|
|
|
|
|
|
|
|
<Switch
|
|
|
|
|
checked={adminOverride}
|
|
|
|
|
className="data-[state=checked]:bg-neutral-700"
|
|
|
|
|
id="adminOverride"
|
|
|
|
|
onCheckedChange={setAdminOverride}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-07 17:03:08 +01:00
|
|
|
<DialogDescription className="sr-only"></DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<div className="flex max-h-[80vh] flex-col gap-2 overflow-y-auto p-0.5 sm:p-2">
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<LoadingPage />
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{!data || data.length === 0 ? (
|
2025-11-17 19:01:21 +01:00
|
|
|
<span>
|
|
|
|
|
Nessun annuncio compatibile trovato. Amplia la ricerca per
|
|
|
|
|
trovare annunci compatibili.
|
|
|
|
|
</span>
|
2025-11-07 17:03:08 +01:00
|
|
|
) : (
|
2025-12-04 17:16:49 +01:00
|
|
|
<div className="relative z-0 mx-auto grid max-w-full grid-flow-row grid-cols-1 gap-14 sm:grid-cols-2 sm:gap-6 sm:gap-y-10 lg:grid-cols-3 2xl:grid-cols-4">
|
2025-11-07 17:03:08 +01:00
|
|
|
{data.map((annuncio) => (
|
|
|
|
|
<div
|
|
|
|
|
className="flex flex-col justify-center gap-1"
|
|
|
|
|
key={annuncio.codice}
|
|
|
|
|
>
|
|
|
|
|
<CardAnnuncio
|
|
|
|
|
{...annuncio}
|
|
|
|
|
className="outline outline-neutral-500"
|
|
|
|
|
noLink
|
|
|
|
|
onlyFirstImage
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
<div className="w-full">
|
|
|
|
|
<AnnuncioDettaglio data={annuncio} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-full">
|
2025-12-04 17:16:49 +01:00
|
|
|
{annuncio.alreadyRequested ? (
|
|
|
|
|
<Badge
|
|
|
|
|
className="flex h-9 w-full items-center justify-center gap-2 text-base [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
|
|
|
|
variant="success"
|
|
|
|
|
>
|
|
|
|
|
<span>Richiesta inviata</span>
|
|
|
|
|
<CheckCircle />
|
|
|
|
|
</Badge>
|
|
|
|
|
) : (
|
|
|
|
|
<InteressatoButtonServizio
|
|
|
|
|
annuncioId={annuncio.id}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-11-07 17:03:08 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<DialogClose asChild></DialogClose>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|