2020-04-03 12:50:51 +01:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { t } from "../i18n";
|
|
|
|
|
|
|
|
import { Dialog } from "./Dialog";
|
2021-04-15 20:29:00 +05:30
|
|
|
import { useExcalidrawContainer } from "./App";
|
2020-04-03 12:50:51 +01:00
|
|
|
|
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);
|
2021-06-10 02:46:56 +05:30
|
|
|
const { container: excalidrawContainer } = useExcalidrawContainer();
|
2020-04-03 12:50:51 +01:00
|
|
|
|
|
|
|
const handleClose = React.useCallback(() => {
|
|
|
|
setModalIsShown(false);
|
|
|
|
|
|
|
|
if (onClose) {
|
|
|
|
onClose();
|
|
|
|
}
|
2021-04-15 20:29:00 +05:30
|
|
|
// TODO: Fix the A11y issues so this is never needed since we should always focus on last active element
|
|
|
|
excalidrawContainer?.focus();
|
|
|
|
}, [onClose, excalidrawContainer]);
|
2020-04-03 12:50:51 +01:00
|
|
|
|
|
|
|
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
|
|
|
};
|