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

{title}

{description}

); }; export default forwardRef(ErrorModal);