2025-11-06 17:03:42 +01:00
|
|
|
import { FileBadge, FileText, PackageCheck, Pointer } from "lucide-react";
|
2025-08-04 17:45:44 +02:00
|
|
|
import Link from "next/link";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { useRouter } from "next/router";
|
2025-08-04 17:45:44 +02:00
|
|
|
import toast from "react-hot-toast";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { Button, type ButtonConfigs } from "~/components/ui/button";
|
2025-08-04 17:45:44 +02:00
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipProvider,
|
|
|
|
|
TooltipTrigger,
|
2025-08-04 17:45:44 +02:00
|
|
|
} from "~/components/ui/tooltip";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { cn } from "~/lib/utils";
|
|
|
|
|
import { useServizio, useServizioAnnuncio } from "~/providers/ServizioProvider";
|
2025-08-04 17:45:44 +02:00
|
|
|
import type { AnnunciId } from "~/schemas/public/Annunci";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { api } from "~/utils/api";
|
2025-11-06 17:03:42 +01:00
|
|
|
import { ConfermaAnnuncioModal, ConfermaInLavorazioneModal } from "./conferma";
|
2025-10-29 09:39:06 +01:00
|
|
|
import { ContattiProprietarioModal } from "./modale_contatti";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-06 17:03:42 +01:00
|
|
|
const SezioneConferma = () => {
|
|
|
|
|
const { servizioId } = useServizio();
|
|
|
|
|
const { data, annuncioId } = useServizioAnnuncio();
|
|
|
|
|
|
|
|
|
|
const ContattiSbloccati = data.open_contatti_at !== null;
|
|
|
|
|
const ConfermaUtente = data.user_confirmed_at !== null;
|
|
|
|
|
const ConfermaLavorata = data.doc_conferma_added && data.hasConfermaAdmin;
|
|
|
|
|
const AccettatoConferma = data.accettato_conferma_at !== null;
|
|
|
|
|
|
|
|
|
|
if (ContattiSbloccati && !ConfermaUtente) {
|
|
|
|
|
return <ConfermaAnnuncioModal />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConfermaUtente && !data.hasConfermaAdmin) {
|
|
|
|
|
return <ConfermaInLavorazioneModal />;
|
|
|
|
|
}
|
|
|
|
|
if (AccettatoConferma) {
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
aria-label="Conferma immobile"
|
|
|
|
|
href={`/servizio/riapri-conferma/${servizioId}/${annuncioId}`}
|
|
|
|
|
>
|
|
|
|
|
<Button className="w-fit" variant="success">
|
|
|
|
|
<Pointer className="size-6" />
|
|
|
|
|
Rivedi la conferma
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (ConfermaLavorata) {
|
|
|
|
|
if (data.doc_conferma_ref) {
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
aria-label="Conferma immobile"
|
|
|
|
|
href={`/servizio/conferma-immobile/${servizioId}/${annuncioId}`}
|
|
|
|
|
>
|
|
|
|
|
<Button className="w-fit" variant="success">
|
|
|
|
|
<Pointer className="size-6" />
|
|
|
|
|
Confermato - Procedi ora
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<TooltipProvider delayDuration={0}>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
className="w-fit cursor-not-allowed opacity-50"
|
|
|
|
|
variant="success"
|
|
|
|
|
>
|
|
|
|
|
<Pointer className="size-6" />
|
|
|
|
|
Confermato - Procedi ora
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
<p>Il documento non è più disponibile</p>
|
|
|
|
|
<p>Se hai bisogno di una copia, contattaci via email o chat.</p>
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const PostConfermaSection = () => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { servizio, servizioId } = useServizio();
|
|
|
|
|
const { data, annuncioId } = useServizioAnnuncio();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-06 17:03:42 +01:00
|
|
|
const saldoPaid = servizio.isOkSaldo;
|
|
|
|
|
const consulenzaPaid = servizio.isOkConsulenza;
|
|
|
|
|
|
|
|
|
|
if (!saldoPaid) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
<h3 className="font-semibold">
|
|
|
|
|
Questo annuncio è stato confermato, procedi al saldo:
|
|
|
|
|
</h3>
|
|
|
|
|
<SaldoButton annuncioId={annuncioId} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (!data.doc_contratto_added) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
<h3 className="font-semibold text-green-500">
|
|
|
|
|
Ci siamo quasi! Stiamo preparando il contratto per te.
|
|
|
|
|
</h3>
|
|
|
|
|
<h3 className="font-semibold">
|
|
|
|
|
Una volta pronto, riceverai una notifica via email.
|
|
|
|
|
</h3>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-11-06 17:03:42 +01:00
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
<h3 className="font-semibold">
|
|
|
|
|
{consulenzaPaid
|
|
|
|
|
? "Il contratto è pronto, puoi visualizzarlo:"
|
|
|
|
|
: "Il contratto è pronto, puoi visualizzarlo e procedere al saldo:"}
|
|
|
|
|
</h3>
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
{data.doc_contratto_ref ? (
|
|
|
|
|
<Link
|
|
|
|
|
aria-label="Visualizza contratto"
|
|
|
|
|
href={`/servizio/contratto/${servizioId}/${annuncioId}`}
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
<Button className="w-fit">
|
|
|
|
|
<FileText className="size-6" />
|
|
|
|
|
Visualizza il contratto
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
) : (
|
|
|
|
|
<TooltipProvider delayDuration={0}>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button className="w-fit cursor-not-allowed opacity-50">
|
|
|
|
|
<FileText className="size-6" />
|
|
|
|
|
Visualizza il contratto
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
<p>Il documento non è più disponibile</p>
|
|
|
|
|
<p>Se hai bisogno di una copia, contattaci via email o chat.</p>
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
2025-08-28 18:27:07 +02:00
|
|
|
)}
|
2025-11-06 17:03:42 +01:00
|
|
|
|
|
|
|
|
{!consulenzaPaid && data.contratto_tipo && <SaldoConsulenzaButton />}
|
|
|
|
|
|
|
|
|
|
{data.doc_registrazione_added &&
|
|
|
|
|
(data.doc_registrazione_ref ? (
|
2025-08-28 18:27:07 +02:00
|
|
|
<Link
|
2025-11-06 17:03:42 +01:00
|
|
|
aria-label="Visualizza registrazione"
|
|
|
|
|
href={`/servizio/contratto-registrazione/${servizioId}/${annuncioId}`}
|
|
|
|
|
target="_blank"
|
2025-08-28 18:27:07 +02:00
|
|
|
>
|
2025-11-06 17:03:42 +01:00
|
|
|
<Button className="w-fit">
|
|
|
|
|
<FileBadge className="size-6" />
|
|
|
|
|
Visualizza la registrazione
|
2025-08-28 18:27:07 +02:00
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
) : (
|
|
|
|
|
<TooltipProvider delayDuration={0}>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
2025-11-06 17:03:42 +01:00
|
|
|
<Button className="w-fit cursor-not-allowed opacity-50">
|
|
|
|
|
<FileBadge className="size-6" />
|
|
|
|
|
Visualizza la registrazione
|
2025-08-28 18:27:07 +02:00
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
<p>Il documento non è più disponibile</p>
|
|
|
|
|
<p>
|
|
|
|
|
Se hai bisogno di una copia, contattaci via email o chat.
|
|
|
|
|
</p>
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2025-11-06 17:03:42 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
2025-08-11 15:29:25 +02:00
|
|
|
|
2025-11-06 17:03:42 +01:00
|
|
|
export const Interactions = () => {
|
|
|
|
|
const { data } = useServizioAnnuncio();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-06 17:03:42 +01:00
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
|
<ContattiProprietarioModal />
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-06 17:03:42 +01:00
|
|
|
<SezioneConferma />
|
|
|
|
|
|
|
|
|
|
{data.accettato_conferma_at != null && <PostConfermaSection />}
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const SaldoButton = ({
|
2025-08-28 18:27:07 +02:00
|
|
|
annuncioId,
|
|
|
|
|
variant = "info",
|
|
|
|
|
className,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
annuncioId: AnnunciId;
|
|
|
|
|
variant?: ButtonConfigs["variant"];
|
|
|
|
|
className?: string;
|
2025-08-04 17:45:44 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { servizioId } = useServizio();
|
|
|
|
|
const router = useRouter();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
const { mutate } = api.servizio.setupSaldoServizio.useMutation({
|
|
|
|
|
onMutate: () => {
|
|
|
|
|
toast.loading("Caricamento ...", { id: "preparazioneSaldo" });
|
|
|
|
|
},
|
|
|
|
|
onSuccess: async (data) => {
|
|
|
|
|
toast.success("Pagamento saldo preparato", {
|
|
|
|
|
id: "preparazioneSaldo",
|
|
|
|
|
});
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
await router.push(`/servizio/pagamento/${data}`);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
aria-label="Procedi al saldo"
|
2025-11-03 10:59:45 +01:00
|
|
|
className={cn("w-fit", className)}
|
2025-08-28 18:27:07 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
mutate({
|
|
|
|
|
annuncioId,
|
2025-08-29 16:18:32 +02:00
|
|
|
servizioId,
|
2025-08-28 18:27:07 +02:00
|
|
|
});
|
|
|
|
|
}}
|
2025-08-29 16:18:32 +02:00
|
|
|
variant={variant}
|
2025-08-28 18:27:07 +02:00
|
|
|
>
|
|
|
|
|
<PackageCheck className="size-6" />
|
|
|
|
|
Procedi al saldo
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const SaldoConsulenzaButton = ({
|
2025-08-28 18:27:07 +02:00
|
|
|
variant = "info",
|
|
|
|
|
className,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
variant?: ButtonConfigs["variant"];
|
|
|
|
|
className?: string;
|
2025-08-04 17:45:44 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { annuncioId } = useServizioAnnuncio();
|
|
|
|
|
const { servizioId } = useServizio();
|
|
|
|
|
const router = useRouter();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
const { mutate } = api.servizio.setupSaldoConsulenzaServizio.useMutation({
|
|
|
|
|
onMutate: () => {
|
|
|
|
|
toast.loading("Caricamento ...", { id: "preparazioneSaldo" });
|
|
|
|
|
},
|
|
|
|
|
onSuccess: async (data) => {
|
|
|
|
|
toast.success("Pagamento saldo preparato", {
|
|
|
|
|
id: "preparazioneSaldo",
|
|
|
|
|
});
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
await router.push(`/servizio/pagamento/${data}`);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
aria-label="Procedi al saldo consulenza"
|
2025-11-03 10:59:45 +01:00
|
|
|
className={cn("w-fit", className)}
|
2025-08-28 18:27:07 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
mutate({
|
|
|
|
|
annuncioId,
|
2025-08-29 16:18:32 +02:00
|
|
|
servizioId,
|
2025-08-28 18:27:07 +02:00
|
|
|
});
|
|
|
|
|
}}
|
2025-08-29 16:18:32 +02:00
|
|
|
variant={variant}
|
2025-08-28 18:27:07 +02:00
|
|
|
>
|
|
|
|
|
<PackageCheck className="size-6" />
|
|
|
|
|
Procedi al saldo della consulenza
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|