ErrorDialog.tsx 664 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React, { useState } from "react";
  2. import { t } from "../i18n";
  3. import { Dialog } from "./Dialog";
  4. export const ErrorDialog = ({
  5. message,
  6. onClose,
  7. }: {
  8. message: string;
  9. onClose?: () => void;
  10. }) => {
  11. const [modalIsShown, setModalIsShown] = useState(!!message);
  12. const handleClose = React.useCallback(() => {
  13. setModalIsShown(false);
  14. if (onClose) {
  15. onClose();
  16. }
  17. }, [onClose]);
  18. return (
  19. <>
  20. {modalIsShown && (
  21. <Dialog
  22. maxWidth={500}
  23. onCloseRequest={handleClose}
  24. title={t("errorDialog.title")}
  25. >
  26. <div>{message}</div>
  27. </Dialog>
  28. )}
  29. </>
  30. );
  31. };