69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { RefreshCcw, TriangleAlert } from "lucide-react";
|
|
import toast from "react-hot-toast";
|
|
import { Confirm } from "~/components/confirm";
|
|
import { AreaRiservataLayout } from "~/components/Layout";
|
|
import { LoadingPage } from "~/components/loading";
|
|
import { Status500 } from "~/components/status-page";
|
|
import { AnnunciTable } from "~/components/tables/annunci-tables";
|
|
import { Button } from "~/components/ui/button";
|
|
import type { NextPageWithLayout } from "~/pages/_app";
|
|
import { api } from "~/utils/api";
|
|
|
|
const Admin_Annunci: NextPageWithLayout = () => {
|
|
const { data, isLoading, refetch } = api.annunci.getAnnunciList.useQuery();
|
|
|
|
const { mutateAsync: revalidate } =
|
|
api.settings.revalidateAllAnnunci.useMutation({
|
|
onSettled: async () => {
|
|
toast.success(
|
|
"La revalidazione dell'annuncio è stata richiesta con successo,\n potrebbero volerci alcuni minuti prima che le modifiche siano visibili.",
|
|
{
|
|
duration: 5000,
|
|
},
|
|
);
|
|
},
|
|
});
|
|
if (isLoading) return <LoadingPage />;
|
|
if (!data) return <Status500 />;
|
|
return (
|
|
<div className="mx-1 flex-1 overflow-auto">
|
|
<div className="mx-auto pt-4">
|
|
<div className="mx-3 items-start justify-between md:flex">
|
|
<div className="flex max-w-lg items-center gap-3">
|
|
<h3 className="font-bold text-2xl">Annunci</h3>
|
|
<button
|
|
className="cursor-pointer"
|
|
onClick={async () => await refetch()}
|
|
type="button"
|
|
>
|
|
<RefreshCcw className="size-6" />
|
|
</button>
|
|
<Confirm
|
|
description="Sei sicuro di voler richiedere la revalidazione gli annunci? Questa operazione potrebbe richiedere alcuni minuti prima che le modifiche siano visibili e resetterà eventuali modifiche effettuate dopo la sincronizzazione giornaliera."
|
|
onConfirm={async () => {
|
|
await revalidate();
|
|
}}
|
|
title="Rivalida tutti gli annunci"
|
|
>
|
|
<Button
|
|
className="flex items-center gap-2"
|
|
size="sm"
|
|
type="button"
|
|
variant="warning"
|
|
>
|
|
<TriangleAlert /> Rivalida tutti gli annunci
|
|
</Button>
|
|
</Confirm>
|
|
</div>
|
|
</div>
|
|
<AnnunciTable data={data} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Admin_Annunci;
|
|
|
|
Admin_Annunci.getLayout = function getLayout(page) {
|
|
return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
|
|
};
|