2025-12-04 17:16:49 +01:00
|
|
|
import { CircleHelp } from "lucide-react";
|
2025-11-13 11:38:23 +01:00
|
|
|
import dynamic from "next/dynamic";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { AccordionComp } from "~/components/accordionComp";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { LoadingPage } from "~/components/loading";
|
2025-08-05 19:23:55 +02:00
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
2025-08-05 19:23:55 +02:00
|
|
|
} from "~/components/ui/card";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { useTranslation } from "~/providers/I18nProvider";
|
|
|
|
|
import type { UsersId } from "~/schemas/public/Users";
|
|
|
|
|
import { api } from "~/utils/api";
|
2025-12-04 17:16:49 +01:00
|
|
|
import {
|
|
|
|
|
Credenza,
|
|
|
|
|
CredenzaBody,
|
|
|
|
|
CredenzaContent,
|
|
|
|
|
CredenzaDescription,
|
|
|
|
|
CredenzaHeader,
|
|
|
|
|
CredenzaTitle,
|
|
|
|
|
CredenzaTrigger,
|
|
|
|
|
} from "../custom_ui/credenza";
|
2026-02-25 15:30:53 +01:00
|
|
|
import { ServizioList } from "../servizio/servizio";
|
2025-12-04 17:16:49 +01:00
|
|
|
import { Button } from "../ui/button";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-13 11:38:23 +01:00
|
|
|
const TimeserieBarChart = dynamic(
|
|
|
|
|
() => import("~/components/timeserieBarChart").then((mod) => mod.default),
|
|
|
|
|
{
|
|
|
|
|
ssr: false,
|
2026-02-25 15:30:53 +01:00
|
|
|
loading: () => <div className="h-117 animate-pulse bg-gray-100" />,
|
2025-11-13 11:38:23 +01:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const TimeserieBarChartStacked = dynamic(
|
|
|
|
|
() =>
|
|
|
|
|
import("~/components/timeserieBarChartStacked").then((mod) => mod.default),
|
|
|
|
|
{
|
|
|
|
|
ssr: false,
|
2026-02-25 15:30:53 +01:00
|
|
|
loading: () => <div className="h-117 animate-pulse bg-gray-100" />,
|
2025-11-13 11:38:23 +01:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2025-08-04 17:45:44 +02:00
|
|
|
export const AdminDashboard = () => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { data: stats, isLoading } = api.stats.adminDashStats.useQuery();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
if (isLoading) return <LoadingPage />;
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx-1 flex-1 overflow-auto">
|
|
|
|
|
<div className="mx-auto pt-4 pb-8">
|
|
|
|
|
<div className="mx-3 items-start justify-between pb-3 md:flex">
|
|
|
|
|
<div className="flex max-w-lg items-center gap-3">
|
2025-10-10 16:18:43 +02:00
|
|
|
<h3 className="font-bold text-2xl">Admin Dashboard</h3>
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{!stats ? (
|
|
|
|
|
<div className="text-red-500">Errore caricamento statistiche</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="grid grid-cols-1 gap-4 px-2 pt-4 sm:grid-cols-2 sm:px-4">
|
2025-11-03 10:59:45 +01:00
|
|
|
<Card>
|
2025-08-28 18:27:07 +02:00
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Utenti</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Numero totale di utenti registrati
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
2025-08-05 19:23:55 +02:00
|
|
|
|
2025-10-10 16:18:43 +02:00
|
|
|
<CardContent className="flex h-full items-center justify-center font-bold text-6xl">
|
2025-08-28 18:27:07 +02:00
|
|
|
{stats.userCount}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
<TimeserieBarChart
|
|
|
|
|
timeserie={stats.userTimeserie}
|
2025-08-29 16:18:32 +02:00
|
|
|
title="Utenti registrati"
|
2025-08-28 18:27:07 +02:00
|
|
|
/>
|
2025-08-05 19:23:55 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
<TimeserieBarChartStacked
|
2025-08-29 16:18:32 +02:00
|
|
|
timeserie={stats.serviziTimeserie.data}
|
2025-08-28 18:27:07 +02:00
|
|
|
title="Servizi creati"
|
|
|
|
|
valueALabel={stats.serviziTimeserie.valueALabel}
|
|
|
|
|
valueBLabel={stats.serviziTimeserie.valueBLabel}
|
|
|
|
|
/>
|
2025-08-05 19:23:55 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
<TimeserieBarChart
|
|
|
|
|
timeserie={stats.contattiTimeserie}
|
2025-08-29 16:18:32 +02:00
|
|
|
title="Contatti generati"
|
2025-08-28 18:27:07 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const UserDashboard = ({ userId }: { userId: UsersId }) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { t } = useTranslation();
|
2026-02-25 15:30:53 +01:00
|
|
|
const { data, isLoading } = api.servizio.getAllServizioAnnunci.useQuery({
|
|
|
|
|
userId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isLoading) return <LoadingPage />;
|
|
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-12-04 17:16:49 +01:00
|
|
|
<div className="mt-2 flex w-full flex-1 flex-col items-start justify-center gap-4 overflow-auto p-2 md:gap-6">
|
|
|
|
|
<h3 className="font-bold text-2xl">Le tue ricerche</h3>
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-12-04 17:16:49 +01:00
|
|
|
<div className="flex w-full flex-1 grow flex-col space-y-5">
|
2026-02-25 15:30:53 +01:00
|
|
|
<ServizioList isAdmin={false} servizi={data || []} userId={userId} />
|
2025-12-04 17:16:49 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="mx-auto">
|
|
|
|
|
<Credenza>
|
|
|
|
|
<CredenzaTrigger asChild>
|
|
|
|
|
<Button variant="secondary">
|
|
|
|
|
<span>Domande frequenti</span>
|
|
|
|
|
<CircleHelp />
|
|
|
|
|
</Button>
|
|
|
|
|
</CredenzaTrigger>
|
2025-12-15 17:07:08 +01:00
|
|
|
<CredenzaContent className="max-h-[90vh] w-full md:max-w-3xl">
|
2025-12-04 17:16:49 +01:00
|
|
|
<CredenzaHeader>
|
|
|
|
|
<CredenzaTitle className="text-center font-semibold text-2xl">
|
|
|
|
|
Domande frequenti
|
|
|
|
|
</CredenzaTitle>
|
|
|
|
|
<CredenzaDescription className="sr-only">
|
|
|
|
|
Domande frequenti
|
|
|
|
|
</CredenzaDescription>
|
|
|
|
|
</CredenzaHeader>
|
|
|
|
|
<CredenzaBody className="max-h-[80vh] overflow-auto pb-5">
|
|
|
|
|
<AccordionComp
|
|
|
|
|
className="w-full max-w-full"
|
|
|
|
|
texts={t.area_riservata.dash_accordion_minifaq}
|
|
|
|
|
/>
|
|
|
|
|
</CredenzaBody>
|
|
|
|
|
</CredenzaContent>
|
|
|
|
|
</Credenza>
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|