diff --git a/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx b/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx
index e8cde8f..8eef78e 100644
--- a/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx
+++ b/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx
@@ -1,10 +1,17 @@
import { format } from "date-fns";
import { it } from "date-fns/locale";
-import { CalendarIcon, Eye, Printer, RotateCw } from "lucide-react";
+import {
+ CalendarIcon,
+ Eye,
+ Printer,
+ RotateCw,
+ TriangleAlert,
+} from "lucide-react";
import Link from "next/link";
import toast from "react-hot-toast";
import z from "zod";
import { CarouselAnnuncio } from "~/components/annuncio_card";
+import { Confirm } from "~/components/confirm";
import {
Form,
FormControl,
@@ -123,6 +130,18 @@ export const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
},
});
+ const { mutateAsync: revalidate } =
+ api.settings.revalidateAnnuncio.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,
+ },
+ );
+ },
+ });
+
const defaultValues: FormValues = {
...data,
email: data.email || undefined,
@@ -223,7 +242,23 @@ export const AnnuncioEditForm = ({ data }: { data: Annunci }) => {
Scheda
-
+
{
+ await revalidate({ cod: data.codice });
+ }}
+ title="Revalidazione Annuncio"
+ >
+
+
+
diff --git a/apps/infoalloggi/src/pages/area-riservata/admin/annunci.tsx b/apps/infoalloggi/src/pages/area-riservata/admin/annunci.tsx
index 10c67ac..432bf19 100644
--- a/apps/infoalloggi/src/pages/area-riservata/admin/annunci.tsx
+++ b/apps/infoalloggi/src/pages/area-riservata/admin/annunci.tsx
@@ -1,13 +1,28 @@
-import { RefreshCcw } from "lucide-react";
+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 ;
if (!data) return ;
return (
@@ -23,6 +38,22 @@ const Admin_Annunci: NextPageWithLayout = () => {
>
+ {
+ await revalidate();
+ }}
+ title="Rivalida tutti gli annunci"
+ >
+
+
diff --git a/apps/infoalloggi/src/server/api/routers/settings.ts b/apps/infoalloggi/src/server/api/routers/settings.ts
index 961b777..1f5db66 100644
--- a/apps/infoalloggi/src/server/api/routers/settings.ts
+++ b/apps/infoalloggi/src/server/api/routers/settings.ts
@@ -1,4 +1,6 @@
+import { TRPCError } from "@trpc/server";
import { z } from "zod/v4";
+import { env } from "~/env.mjs";
import type { BannersIdbanner } from "~/schemas/public/Banners";
import {
adminProcedure,
@@ -248,4 +250,63 @@ export const settingsRouter = createTRPCRouter({
stringaValue: input.stringaValue,
});
}),
+
+ revalidateAllAnnunci: adminProcedure.mutation(async () => {
+ try {
+ const response = await fetch(`${env.BACKENDSERVER_URL}/update`);
+
+ if (!response.ok) {
+ const errorData = await response.text().catch(() => "Unknown error");
+ throw new Error(
+ `Revalidation failed with status ${response.status}: ${errorData}`,
+ );
+ }
+
+ const data = await response.json().catch(() => ({}));
+ return {
+ status: "success",
+ details: data,
+ };
+ } catch (err) {
+ console.error("Revalidation error:", err);
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: err instanceof Error ? err.message : "Revalidation failed",
+ cause: err,
+ });
+ }
+ }),
+ revalidateAnnuncio: adminProcedure
+ .input(
+ z.object({
+ cod: z.string(),
+ }),
+ )
+ .mutation(async ({ input }) => {
+ try {
+ const response = await fetch(
+ `${env.BACKENDSERVER_URL}/update-cod/${input.cod}`,
+ );
+
+ if (!response.ok) {
+ const errorData = await response.text().catch(() => "Unknown error");
+ throw new Error(
+ `Revalidation failed with status ${response.status}: ${errorData}`,
+ );
+ }
+
+ const data = await response.json().catch(() => ({}));
+ return {
+ status: "success",
+ details: data,
+ };
+ } catch (err) {
+ console.error("Revalidation error:", err);
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: err instanceof Error ? err.message : "Revalidation failed",
+ cause: err,
+ });
+ }
+ }),
});