2026-03-11 12:07:19 +01:00
|
|
|
import type { ColumnDef } from "@tanstack/react-table";
|
2026-03-25 17:30:33 +01:00
|
|
|
import { format } from "date-fns";
|
|
|
|
|
import {
|
|
|
|
|
CircleCheck,
|
|
|
|
|
CircleCheckBig,
|
|
|
|
|
CircleEllipsis,
|
|
|
|
|
ClockFading,
|
|
|
|
|
ExternalLink,
|
|
|
|
|
SearchX,
|
|
|
|
|
} from "lucide-react";
|
2026-03-11 12:07:19 +01:00
|
|
|
import Link from "next/link";
|
2026-03-25 17:30:33 +01:00
|
|
|
import { AnnuncioCardContent } from "~/components/servizio/annuncio_card";
|
|
|
|
|
import { Badge } from "~/components/ui/badge";
|
2026-03-19 10:24:32 +01:00
|
|
|
import { Button } from "~/components/ui/button";
|
|
|
|
|
import { DataTable } from "~/components/ui/data-table";
|
|
|
|
|
import { DataTableColumnHeader } from "~/components/ui/dataTable-header";
|
2026-03-11 12:07:19 +01:00
|
|
|
import type {
|
|
|
|
|
PinnedFiltro,
|
|
|
|
|
SearchFiltro,
|
2026-03-19 10:24:32 +01:00
|
|
|
} from "~/components/ui/dataTable-toolbar";
|
2026-03-25 17:30:33 +01:00
|
|
|
import {
|
|
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverDescription,
|
|
|
|
|
PopoverHeader,
|
|
|
|
|
PopoverTitle,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
} from "~/components/ui/popover";
|
|
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "~/components/ui/tooltip";
|
|
|
|
|
import { UserAvatar } from "~/components/user_avatar";
|
|
|
|
|
import { cn } from "~/lib/utils";
|
2026-03-11 12:07:19 +01:00
|
|
|
import TipologiaPosizioneEnum from "~/schemas/public/TipologiaPosizioneEnum";
|
|
|
|
|
import type { RichiesteData } from "~/server/controllers/servizio.controller";
|
|
|
|
|
|
|
|
|
|
type RichiesteTableProps = {
|
|
|
|
|
data: RichiesteData[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const RichiesteTable = ({ data }: RichiesteTableProps) => {
|
|
|
|
|
const tabledata = data;
|
|
|
|
|
const columns_titles = {
|
|
|
|
|
id: "ID Ordine",
|
|
|
|
|
username: "Utente",
|
2026-03-25 17:30:33 +01:00
|
|
|
decorrenza: "Decorrenza",
|
2026-03-11 12:07:19 +01:00
|
|
|
status: "Status",
|
2026-03-25 17:30:33 +01:00
|
|
|
tipologia: "Tipo",
|
2026-03-11 12:07:19 +01:00
|
|
|
annunci: "Annunci",
|
|
|
|
|
actions: "Azioni",
|
|
|
|
|
};
|
|
|
|
|
const statusOptions = [
|
|
|
|
|
{ label: "Attesa di attivazione", value: "attesa_attivazione" },
|
|
|
|
|
{ label: "Acconto pagato", value: "acconto_pagato" },
|
|
|
|
|
{ label: "Saldo pagato", value: "saldo_pagato" },
|
|
|
|
|
{ label: "Conferma in corso", value: "conferma" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const type_options = [
|
|
|
|
|
{ label: "Transitorio", value: TipologiaPosizioneEnum.Transitorio },
|
|
|
|
|
{ label: "Stabile", value: TipologiaPosizioneEnum.Stabile },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
type Column = (typeof tabledata)[number];
|
|
|
|
|
|
|
|
|
|
const columns: ColumnDef<Column>[] = [
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "id",
|
|
|
|
|
cell: () => null,
|
|
|
|
|
enableHiding: false,
|
|
|
|
|
header: () => null,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "username",
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
2026-03-25 17:30:33 +01:00
|
|
|
className="flex items-center gap-2"
|
2026-03-11 12:07:19 +01:00
|
|
|
href={`/area-riservata/admin/user-view/ricerca/${row.original.user_id}`}
|
|
|
|
|
>
|
2026-03-25 17:30:33 +01:00
|
|
|
<UserAvatar
|
|
|
|
|
className="size-8"
|
|
|
|
|
userId={row.original.user_id}
|
|
|
|
|
username={row.original.username}
|
|
|
|
|
/>
|
|
|
|
|
<span className="font-semibold text-sm">
|
|
|
|
|
{row.original.username}
|
|
|
|
|
</span>
|
2026-03-11 12:07:19 +01:00
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
enableHiding: false,
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<DataTableColumnHeader
|
|
|
|
|
column={column}
|
|
|
|
|
title={columns_titles.username}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-03-25 17:30:33 +01:00
|
|
|
accessorKey: "decorrenza",
|
2026-03-11 12:07:19 +01:00
|
|
|
cell: ({ row }) => {
|
2026-03-25 17:30:33 +01:00
|
|
|
let decorrenzaColor = "";
|
|
|
|
|
let decorrenzaTooltip = "";
|
|
|
|
|
if (!row.original.isOkAcconto || !row.original.decorrenza) {
|
|
|
|
|
decorrenzaColor = "text-muted-foreground";
|
|
|
|
|
decorrenzaTooltip = "Attesa di attivazione";
|
|
|
|
|
} else if (row.original.isInterrotto) {
|
|
|
|
|
decorrenzaColor = "text-destructive";
|
|
|
|
|
decorrenzaTooltip = "Servizio interrotto";
|
|
|
|
|
} else if (row.original.isOkAcconto && !row.original.isOkSaldo) {
|
|
|
|
|
decorrenzaColor = "text-warning";
|
|
|
|
|
decorrenzaTooltip = "Attesa di saldo";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger className={decorrenzaColor}>
|
|
|
|
|
{row.original.decorrenza
|
|
|
|
|
? format(row.original.decorrenza, "dd/MM")
|
|
|
|
|
: "---"}
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
<p>{decorrenzaTooltip}</p>
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
2026-03-11 12:07:19 +01:00
|
|
|
},
|
|
|
|
|
enableHiding: false,
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<DataTableColumnHeader
|
|
|
|
|
column={column}
|
2026-03-25 17:30:33 +01:00
|
|
|
title={columns_titles.decorrenza}
|
2026-03-11 12:07:19 +01:00
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
sortingFn: "datetime",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "tipologia",
|
|
|
|
|
cell: ({ row }) => {
|
2026-03-25 17:30:33 +01:00
|
|
|
const { tipologia } = row.original;
|
|
|
|
|
return (
|
|
|
|
|
<Badge
|
|
|
|
|
className={cn(
|
|
|
|
|
"px-1.5",
|
|
|
|
|
tipologia === TipologiaPosizioneEnum.Transitorio
|
|
|
|
|
? "border-transitorio bg-transitorio/15"
|
|
|
|
|
: "border-stabile bg-stabile/15",
|
|
|
|
|
)}
|
|
|
|
|
variant="outline"
|
|
|
|
|
>
|
|
|
|
|
{tipologia.toString()}
|
|
|
|
|
</Badge>
|
|
|
|
|
);
|
2026-03-11 12:07:19 +01:00
|
|
|
},
|
|
|
|
|
filterFn: (row, id, value) => {
|
|
|
|
|
return value.includes(row.getValue(id));
|
|
|
|
|
},
|
|
|
|
|
header: ({ column }) => (
|
2026-03-25 17:30:33 +01:00
|
|
|
<DataTableColumnHeader
|
|
|
|
|
column={column}
|
|
|
|
|
title={columns_titles.tipologia}
|
|
|
|
|
/>
|
2026-03-11 12:07:19 +01:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "status",
|
|
|
|
|
cell: ({ row }) => {
|
2026-03-25 17:30:33 +01:00
|
|
|
let badgeClass = "";
|
|
|
|
|
let contents: React.ReactNode;
|
2026-03-11 12:07:19 +01:00
|
|
|
const annunci = row.original.annunci_servizio;
|
|
|
|
|
const awaitingConferma = annunci.some(
|
|
|
|
|
(a) => a.user_confirmed_at !== null && !a.hasConfermaAdmin,
|
|
|
|
|
);
|
2026-03-25 17:30:33 +01:00
|
|
|
const hasConfermaAdmin = annunci.some((a) => a.hasConfermaAdmin);
|
|
|
|
|
if (row.original.isInterrotto) {
|
|
|
|
|
badgeClass = "border-destructive bg-destructive/10 text-destructive";
|
|
|
|
|
contents = (
|
|
|
|
|
<>
|
|
|
|
|
<SearchX className="stroke-red-500 dark:stroke-red-400" />
|
|
|
|
|
Interrotto
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
} else if (!row.original.onboardOk) {
|
|
|
|
|
badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
|
|
|
|
|
contents = (
|
|
|
|
|
<>
|
|
|
|
|
<ClockFading className="stroke-yellow-500 dark:stroke-yellow-400" />
|
|
|
|
|
Attesa attivazione
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
} else if (awaitingConferma) {
|
|
|
|
|
badgeClass = "border-sky-500 bg-sky-500/10 text-sky-500";
|
|
|
|
|
contents = (
|
|
|
|
|
<>
|
|
|
|
|
<CircleEllipsis className="stroke-sky-500 dark:stroke-sky-400" />
|
|
|
|
|
In Conferma
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
} else if (row.original.isOkSaldo && hasConfermaAdmin) {
|
|
|
|
|
badgeClass = "border-blue-500 bg-blue-500/10 text-blue-500";
|
|
|
|
|
contents = (
|
|
|
|
|
<>
|
|
|
|
|
<CircleCheckBig className="stroke-blue-500 dark:stroke-blue-400" />
|
|
|
|
|
Saldo pagato
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
} else if (row.original.isOkAcconto) {
|
|
|
|
|
badgeClass = "border-green-500 bg-green-500/10 text-green-500";
|
|
|
|
|
contents = (
|
|
|
|
|
<>
|
|
|
|
|
<CircleCheck className="stroke-green-500 dark:stroke-green-400" />
|
|
|
|
|
Attivo
|
|
|
|
|
</>
|
|
|
|
|
);
|
2026-03-11 12:07:19 +01:00
|
|
|
}
|
2026-03-25 17:30:33 +01:00
|
|
|
return (
|
|
|
|
|
<Badge
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex items-center px-1.5 text-muted-foreground [&>svg]:size-4",
|
|
|
|
|
badgeClass,
|
|
|
|
|
)}
|
|
|
|
|
variant="outline"
|
|
|
|
|
>
|
|
|
|
|
{contents}
|
|
|
|
|
</Badge>
|
|
|
|
|
);
|
2026-03-11 12:07:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
filterFn: (row, id, value) => {
|
|
|
|
|
return value.includes(row.getValue(id));
|
|
|
|
|
},
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<DataTableColumnHeader column={column} title={columns_titles.status} />
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "annunci_servizio",
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
const annunci = row.original.annunci_servizio;
|
2026-03-25 17:30:33 +01:00
|
|
|
return (
|
|
|
|
|
<Popover>
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
<Button size="sm" variant="outline">
|
|
|
|
|
{annunci.length} Annunci
|
|
|
|
|
</Button>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent align="end" className="w-4xl">
|
|
|
|
|
<PopoverHeader>
|
|
|
|
|
<PopoverTitle>Annunci Inseriti</PopoverTitle>
|
|
|
|
|
<PopoverDescription className="sr-only">
|
|
|
|
|
Desc
|
|
|
|
|
</PopoverDescription>
|
|
|
|
|
</PopoverHeader>
|
|
|
|
|
<div className="flex flex-col gap-4 divide-y">
|
|
|
|
|
{annunci.map((a) => (
|
|
|
|
|
<AnnuncioCardContent
|
|
|
|
|
data={a}
|
|
|
|
|
interactions={
|
|
|
|
|
<div>
|
|
|
|
|
<p>
|
|
|
|
|
Visto contatti:{" "}
|
|
|
|
|
{a.open_contatti_at
|
|
|
|
|
? format(a.open_contatti_at, "dd/MM/yyyy HH:mm")
|
|
|
|
|
: "Non ancora visto"}
|
|
|
|
|
</p>
|
|
|
|
|
{/*TODO CAPIRE COSA AGGIUNGERE */}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
isAdmin
|
|
|
|
|
key={a.annunci_id}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
);
|
2026-03-11 12:07:19 +01:00
|
|
|
},
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<DataTableColumnHeader column={column} title={columns_titles.annunci} />
|
|
|
|
|
),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-03-25 17:30:33 +01:00
|
|
|
cell: ({ row }) => {
|
2026-03-11 12:07:19 +01:00
|
|
|
return (
|
2026-03-25 17:30:33 +01:00
|
|
|
<Link
|
|
|
|
|
href={`/area-riservata/admin/user-view/servizio/${row.original.user_id}/${row.original.servizio_id}`}
|
|
|
|
|
target="_blank"
|
2026-03-11 12:07:19 +01:00
|
|
|
>
|
2026-03-25 17:30:33 +01:00
|
|
|
<Button aria-label="Apri servizio" size="sm" variant="outline">
|
|
|
|
|
<ExternalLink className="size-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
2026-03-11 12:07:19 +01:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
enableHiding: false,
|
|
|
|
|
id: "actions",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const searchFiltro: SearchFiltro = {
|
|
|
|
|
columnName: "id",
|
|
|
|
|
placeholder: "Cerca ordine...",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const pinnedFiltri: PinnedFiltro[] = [
|
|
|
|
|
{
|
|
|
|
|
columnName: "status",
|
|
|
|
|
|
|
|
|
|
options: statusOptions,
|
|
|
|
|
title: "Stato Ordine",
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-03-25 17:30:33 +01:00
|
|
|
columnName: "tipologia",
|
2026-03-11 12:07:19 +01:00
|
|
|
options: type_options,
|
|
|
|
|
title: "Tipo Ordine",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx-auto w-full">
|
|
|
|
|
<DataTable
|
|
|
|
|
columns={columns}
|
|
|
|
|
columns_titles={columns_titles}
|
|
|
|
|
data={tabledata}
|
2026-03-25 17:30:33 +01:00
|
|
|
defaultSort={[{ desc: true, id: "decorrenza" }]}
|
2026-03-11 12:07:19 +01:00
|
|
|
pinnedFiltri={pinnedFiltri}
|
|
|
|
|
searchColumn={searchFiltro}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|