import { CodeSquare, RefreshCcw, TriangleAlert } from "lucide-react"; import Head from "next/head"; 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 { Popover, PopoverContent, PopoverTrigger, } from "~/components/ui/popover"; import type { NextPageWithLayout } from "~/pages/_app"; import { generateSSGHelper } from "~/server/utils/ssgHelper"; import { api } from "~/utils/api"; /** * Pagina di gestione annunci per admin: /area-riservata/admin/annunci */ const Admin_Annunci: NextPageWithLayout = () => { const { data, isLoading, refetch } = api.annunci.getAnnunciList.useQuery(); const utils = api.useUtils(); const { mutateAsync: update } = api.revalidation.updateAllAnnunci.useMutation( { onMutate: () => { toast.loading( "Richiesta di aggiornamento inviata, attendere prego...", { id: "update-annuncio-all", }, ); }, onSettled: async () => { await utils.annunci.getAnnunciList.invalidate(); toast.success("Aggiornamento completato", { id: "update-annuncio-all", }); }, onError: async (err) => { toast.error( "Si è verificato un errore durante l'aggiornamento degli annunci: " + (err instanceof Error ? err.message : "Errore sconosciuto"), { id: "update-annuncio-all", }, ); }, }, ); const { mutateAsync: revalidate } = api.revalidation.revalidateAllAnnunci.useMutation({ onSettled: async () => { await utils.annunci.getAnnunciList.invalidate(); toast.success("Revalidazione completata"); }, }); if (isLoading) return ; if (!data) return ; return ( <> Annunci - Infoalloggi.it

Annunci

{ await update(); }} title="Aggiornamento Annunci" >
); }; export async function getServerSideProps() { const helpers = generateSSGHelper(); await helpers.annunci.getAnnunciList.prefetch(); return { props: { trpcState: helpers.dehydrate(), }, }; } export default Admin_Annunci; Admin_Annunci.getLayout = function getLayout(page) { return {page}; };