2025-11-06 17:03:42 +01:00
|
|
|
import { FolderKanban, ShieldUser, Trash2, Wrench } from "lucide-react";
|
2025-08-28 18:27:07 +02:00
|
|
|
import Link from "next/link";
|
|
|
|
|
import toast from "react-hot-toast";
|
|
|
|
|
import { Confirm } from "~/components/confirm";
|
2025-11-06 17:03:42 +01:00
|
|
|
import { Button } from "~/components/ui/button";
|
2025-08-28 18:27:07 +02:00
|
|
|
import {
|
|
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
} from "~/components/ui/popover";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { useServizio, useServizioAnnuncio } from "~/providers/ServizioProvider";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { api } from "~/utils/api";
|
2025-11-06 17:03:42 +01:00
|
|
|
import { AdminLavoraConferma } from "./admin_conferma";
|
|
|
|
|
import { AdminContratto } from "./admin_contratto";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
export const AnnuncioActions = () => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { servizioId, userId, isAdmin } = useServizio();
|
|
|
|
|
const { data, annuncioId } = useServizioAnnuncio();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
const utils = api.useUtils();
|
|
|
|
|
const { mutate } = api.servizio.removeAnnuncioServizio.useMutation({
|
2025-08-29 16:18:32 +02:00
|
|
|
onError: (error) => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
toast.error("Errore durante la rimozione dell'annuncio");
|
|
|
|
|
},
|
2025-08-28 18:27:07 +02:00
|
|
|
onSuccess: async () => {
|
|
|
|
|
await utils.servizio.getAllServizioAnnunci.invalidate({ userId });
|
|
|
|
|
await utils.servizio.getCompatibileAnnunci.invalidate({
|
|
|
|
|
servizioId,
|
|
|
|
|
});
|
|
|
|
|
toast.success("Annuncio rimosso");
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
if ((!isAdmin && data.open_contatti_at == null) || isAdmin) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex w-full max-w-fit flex-wrap justify-start gap-3 sm:justify-end">
|
|
|
|
|
{isAdmin && data.user_confirmed_at != null && <AdminLavoraConferma />}
|
|
|
|
|
{isAdmin && data.accettato_conferma_at != null && (
|
|
|
|
|
<>
|
|
|
|
|
<AdminContratto />
|
|
|
|
|
{data.gestionale_id && (
|
|
|
|
|
<Link
|
|
|
|
|
aria-label="Open Gestionale"
|
|
|
|
|
href={`https://win-jk822fggr6b:480/id/${data.gestionale_id}`}
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
2025-11-03 10:59:45 +01:00
|
|
|
<Button>
|
2025-08-28 18:27:07 +02:00
|
|
|
<FolderKanban className="size-5" /> Gestionale
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{isAdmin && (
|
2025-11-03 10:59:45 +01:00
|
|
|
<Popover>
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
<Button>
|
|
|
|
|
<ShieldUser />
|
|
|
|
|
<span>Admin</span>
|
2025-08-28 18:27:07 +02:00
|
|
|
</Button>
|
2025-11-03 10:59:45 +01:00
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent
|
|
|
|
|
align="end"
|
2025-11-04 19:18:13 +01:00
|
|
|
className="flex w-fit flex-col items-center gap-4"
|
2025-08-28 18:27:07 +02:00
|
|
|
>
|
2025-11-03 10:59:45 +01:00
|
|
|
<Link
|
|
|
|
|
href={`/area-riservata/admin/edit-annuncio/${annuncioId}`}
|
|
|
|
|
target="_blank"
|
2025-08-28 18:27:07 +02:00
|
|
|
>
|
2025-11-03 10:59:45 +01:00
|
|
|
<Button
|
|
|
|
|
aria-label="Edit Annuncio"
|
|
|
|
|
className="w-full"
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="secondary"
|
|
|
|
|
>
|
|
|
|
|
<Wrench />
|
|
|
|
|
<span>Modifica Annuncio</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
|
|
<Confirm
|
|
|
|
|
description="Sei sicuro di voler eliminare l'annuncio?"
|
|
|
|
|
onConfirm={() => {
|
|
|
|
|
mutate({
|
|
|
|
|
annuncioId,
|
|
|
|
|
servizioId,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
title="Elimina annuncio"
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
aria-label="Delete Annuncio"
|
|
|
|
|
className="w-full"
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="destructive"
|
|
|
|
|
>
|
|
|
|
|
<Trash2 />
|
2025-12-16 12:16:16 +01:00
|
|
|
<span>Elimina</span>
|
2025-11-03 10:59:45 +01:00
|
|
|
</Button>
|
|
|
|
|
</Confirm>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
2025-08-28 18:27:07 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|