2025-12-05 16:36:17 +01:00
|
|
|
import Image from "next/image";
|
2026-01-16 15:47:38 +01:00
|
|
|
import {
|
|
|
|
|
AdminActions,
|
|
|
|
|
UserActions,
|
|
|
|
|
} from "~/components/servizio/annuncio_actions";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
|
|
|
|
|
import { handleConsegna } from "~/lib/annuncio_details";
|
2025-11-28 15:11:14 +01:00
|
|
|
import { getStorageUrl } from "~/lib/storage_utils";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { cn, formatCurrency } from "~/lib/utils";
|
|
|
|
|
import { useTranslation } from "~/providers/I18nProvider";
|
2026-01-16 15:47:38 +01:00
|
|
|
import { useServizio, useServizioAnnuncio } from "~/providers/ServizioProvider";
|
2025-11-17 19:01:21 +01:00
|
|
|
import type { AnnuncioRicerca } from "~/server/controllers/annunci.controller";
|
|
|
|
|
import { AnnuncioDettaglio, TipoBadge } from "./annuncio_dettaglio";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-12-18 15:12:25 +01:00
|
|
|
export const AnnuncioCard = ({
|
|
|
|
|
className,
|
|
|
|
|
confirming,
|
|
|
|
|
}: {
|
|
|
|
|
className?: string;
|
|
|
|
|
confirming?: boolean;
|
|
|
|
|
}) => {
|
2026-01-16 15:47:38 +01:00
|
|
|
const { isAdmin } = useServizio();
|
2025-08-28 18:27:07 +02:00
|
|
|
const { data } = useServizioAnnuncio();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<BasicAnnuncioCard
|
2025-08-29 16:18:32 +02:00
|
|
|
className={className}
|
2025-12-18 15:12:25 +01:00
|
|
|
confirming={confirming}
|
2025-10-21 18:42:03 +02:00
|
|
|
data={{
|
|
|
|
|
...data,
|
2025-11-17 19:01:21 +01:00
|
|
|
modificato_il: data.modificato_il ? new Date(data.modificato_il) : null,
|
2025-11-06 13:17:20 +01:00
|
|
|
media_updated_at: data.media_updated_at
|
|
|
|
|
? new Date(data.media_updated_at)
|
|
|
|
|
: null,
|
2025-10-21 18:42:03 +02:00
|
|
|
}}
|
2026-01-16 15:47:38 +01:00
|
|
|
interactions={isAdmin ? <AdminActions /> : <UserActions />}
|
2025-08-28 18:27:07 +02:00
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
2026-01-09 13:13:17 +01:00
|
|
|
|
|
|
|
|
export const AnnuncioDisplay = ({
|
|
|
|
|
data,
|
|
|
|
|
confirming,
|
2026-01-09 14:47:28 +01:00
|
|
|
className,
|
2026-01-09 13:13:17 +01:00
|
|
|
}: {
|
|
|
|
|
data: AnnuncioRicerca;
|
|
|
|
|
confirming?: boolean;
|
2026-01-09 14:47:28 +01:00
|
|
|
className?: string;
|
2026-01-09 13:13:17 +01:00
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"grid @md:grid-cols-[12rem_1fr] grid-cols-[7rem_1fr] gap-x-4 gap-y-2 rounded-md md:max-w-3xl md:border md:border-white md:bg-[#e6e9ec]/50 lg:gap-x-4 xl:gap-x-6 dark:md:border-primary dark:md:bg-card",
|
|
|
|
|
confirming && "xl:w-1/2",
|
2026-01-09 14:47:28 +01:00
|
|
|
className,
|
2026-01-09 13:13:17 +01:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<div className="row-span-1 md:row-span-3">
|
|
|
|
|
<Image
|
|
|
|
|
alt={data.codice}
|
|
|
|
|
className="size-24 rounded-md bg-[#e6e9ec] object-cover md:size-48"
|
|
|
|
|
height={1080}
|
|
|
|
|
priority
|
|
|
|
|
src={
|
|
|
|
|
(data?.images[0] &&
|
|
|
|
|
getStorageUrl({
|
|
|
|
|
storageId: data.images[0].img,
|
|
|
|
|
params: {
|
|
|
|
|
cacheKey: data.media_updated_at?.toISOString(),
|
|
|
|
|
media: "image",
|
|
|
|
|
},
|
|
|
|
|
})) ||
|
|
|
|
|
"/fallback-image.png"
|
|
|
|
|
}
|
|
|
|
|
width={1920}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="col-span-1 flex w-full max-w-xl flex-wrap gap-5 md:col-span-1 md:mt-4 md:pr-8">
|
|
|
|
|
<span className="text-wrap">{data.titolo_it}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="col-span-2 flex w-full max-w-xl items-center justify-between gap-2 md:col-span-1 md:pr-8">
|
|
|
|
|
<TipoBadge mini tipo={data.tipo} />
|
|
|
|
|
<span className="max-w-auto truncate">
|
|
|
|
|
{handleConsegna({
|
|
|
|
|
aggiornamento: t.card.in_aggiornamento,
|
|
|
|
|
consegna: data.consegna,
|
|
|
|
|
consegna_da: t.card.consegna_da,
|
|
|
|
|
mesi: t.parametri.mesi,
|
|
|
|
|
subito: t.card.consegna_subito,
|
|
|
|
|
})}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-semibold">
|
|
|
|
|
{formatCurrency(data.prezzo / 1e2)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="col-span-2 w-full max-w-xl md:col-span-1 md:pr-8">
|
|
|
|
|
<AnnuncioDettaglio data={data} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-04 17:45:44 +02:00
|
|
|
export const BasicAnnuncioCard = ({
|
2025-08-28 18:27:07 +02:00
|
|
|
interactions,
|
|
|
|
|
className,
|
|
|
|
|
data,
|
2025-12-18 15:12:25 +01:00
|
|
|
confirming,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
interactions?: React.ReactNode;
|
|
|
|
|
className?: string;
|
2025-11-17 19:01:21 +01:00
|
|
|
data: AnnuncioRicerca;
|
2025-12-18 15:12:25 +01:00
|
|
|
confirming?: boolean;
|
2025-08-04 17:45:44 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-12-16 12:16:16 +01:00
|
|
|
<Card className={cn("w-full gap-2 border-white py-3", className)}>
|
2025-12-18 15:12:25 +01:00
|
|
|
<CardHeader className="flex flex-row flex-wrap items-center justify-between space-y-0 px-3 pb-2">
|
2025-12-15 18:58:13 +01:00
|
|
|
<CardTitle className="text-2xl">Annuncio {data.codice}</CardTitle>
|
2025-08-28 18:27:07 +02:00
|
|
|
</CardHeader>
|
2025-12-15 18:58:13 +01:00
|
|
|
<CardContent className="px-3">
|
2025-12-18 15:12:25 +01:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"@container flex w-full flex-col gap-4",
|
|
|
|
|
confirming && "xl:flex-row xl:gap-6",
|
|
|
|
|
)}
|
|
|
|
|
id="container"
|
|
|
|
|
>
|
2026-01-09 13:13:17 +01:00
|
|
|
<AnnuncioDisplay confirming={confirming} data={data} />
|
2025-12-18 15:12:25 +01:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex w-full flex-col gap-4",
|
|
|
|
|
confirming && "xl:w-1/2",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{interactions}
|
|
|
|
|
</div>
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|