import { forwardRef, Fragment, Ref, useEffect, useImperativeHandle, useState } from "react"; import { Dialog, Transition } from "@headlessui/react"; import clsx from "clsx"; import { useApp } from "../../../hooks"; export interface RefSuccessModal { show: (title?: string, description?: string) => void; } interface Props { className?: string; onClosed?: () => void; } const SuccessModal = ({ className, onClosed }: Props, ref: Ref) => { const { t } = useApp(); const [open, setOpen] = useState(false); const [title, setTitle] = useState(); const [description, setDescription] = useState(); const [closeText, setCloseText] = useState(); useEffect(() => { setTitle(t("shared.success").toString()); setCloseText(t("shared.close")); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); function close() { setOpen(false); if (onClosed) { onClosed(); } } useImperativeHandle(ref, () => ({ show })); function show(_title?: string, _description?: string) { if (_title) { setTitle(_title); } if (_description) { setDescription(_description); } setOpen(true); } return (
{/* This element is to trick the browser into centering the modal contents. */}
{title}

{description}

); }; export default forwardRef(SuccessModal);