2020-04-03 12:50:51 +01:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { t } from "../i18n";
|
|
|
|
|
|
|
|
import { Dialog } from "./Dialog";
|
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const ErrorDialog = ({
|
2020-04-03 12:50:51 +01:00
|
|
|
message,
|
|
|
|
onClose,
|
|
|
|
}: {
|
|
|
|
message: string;
|
|
|
|
onClose?: () => void;
|
2020-05-20 16:21:37 +03:00
|
|
|
}) => {
|
2020-04-03 12:50:51 +01:00
|
|
|
const [modalIsShown, setModalIsShown] = useState(!!message);
|
|
|
|
|
|
|
|
const handleClose = React.useCallback(() => {
|
|
|
|
setModalIsShown(false);
|
|
|
|
|
|
|
|
if (onClose) {
|
|
|
|
onClose();
|
|
|
|
}
|
2021-04-13 01:29:25 +05:30
|
|
|
document.querySelector<HTMLElement>(".excalidraw-container")?.focus();
|
2020-04-03 12:50:51 +01:00
|
|
|
}, [onClose]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{modalIsShown && (
|
|
|
|
<Dialog
|
2020-12-27 17:07:05 -05:00
|
|
|
small
|
2020-04-03 12:50:51 +01:00
|
|
|
onCloseRequest={handleClose}
|
|
|
|
title={t("errorDialog.title")}
|
|
|
|
>
|
2021-04-06 21:27:15 +02:00
|
|
|
<div style={{ whiteSpace: "pre-wrap" }}>{message}</div>
|
2020-04-03 12:50:51 +01:00
|
|
|
</Dialog>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|