46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { useEffect } from "react";
|
|
import { createPortal } from "react-dom";
|
|
|
|
interface SuccessModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
title?: string;
|
|
message?: string;
|
|
duration?: number;
|
|
}
|
|
|
|
export default function SuccessModal({
|
|
isOpen,
|
|
onClose,
|
|
title = "Votre demande a bien été envoyé !",
|
|
message = "Nous reviendrons vers vous prochainement au sujet de votre demande.",
|
|
duration = 4000,
|
|
}: Readonly<SuccessModalProps>) {
|
|
useEffect(() => {
|
|
if (!isOpen) return;
|
|
|
|
const timer = setTimeout(onClose, duration);
|
|
return () => {
|
|
clearTimeout(timer);
|
|
};
|
|
}, [isOpen, duration, onClose]);
|
|
|
|
if (!isOpen || typeof document === "undefined") return null;
|
|
|
|
return createPortal(
|
|
<div className="fixed inset-0 z-[999] flex items-center justify-center bg-black/40 p-6">
|
|
<div
|
|
className="drop-shadow-card animate-fade-in-scale flex w-full max-w-[625px] flex-col items-center gap-4 rounded-[20px] bg-[#F5E1D1] px-6 py-12"
|
|
style={{ transform: "rotate(-2.74deg)" }}
|
|
>
|
|
<h2 className="text-center font-lato-black text-h2 text-bleu">
|
|
{title}
|
|
</h2>
|
|
<p className="max-w-[433px] text-center font-poppins-regular text-body text-bleu">
|
|
{message}
|
|
</p>
|
|
</div>
|
|
</div>,
|
|
document.body,
|
|
);
|
|
}
|