-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathErrorModal.jsx
More file actions
75 lines (66 loc) · 2.08 KB
/
Copy pathErrorModal.jsx
File metadata and controls
75 lines (66 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from "react";
import Modal from "react-modal";
import { useDispatch, useSelector } from "react-redux";
import { useTranslation } from "react-i18next";
import PropTypes from "prop-types";
import Button from "../Button/Button";
import { closeErrorModal, setError } from "../../redux/EditorSlice";
import "../../assets/stylesheets/Modal.scss";
const ErrorModal = ({ errorType, additionalOnClose }) => {
const dispatch = useDispatch();
const { t } = useTranslation();
const error = useSelector((state) => state.editor.error);
const isModalOpen = useSelector((state) => state.editor.errorModalShowing);
const closeModal = () => {
dispatch(closeErrorModal());
if (additionalOnClose) {
additionalOnClose();
}
dispatch(setError(null));
};
return (
<>
<Modal
isOpen={isModalOpen}
onRequestClose={closeModal}
className="modal-content"
overlayClassName="modal-overlay"
contentLabel={t("modal.error.error")}
parentSelector={() =>
document.querySelector("#app") ||
document.querySelector("editor-wc").shadowRoot.querySelector("#wc")
}
appElement={
document.querySelector("editor-wc") ||
document.getElementById("app") ||
undefined
}
>
<div className="modal-content__header">
<h2 className="modal-content__heading">{t("modal.error.heading")}</h2>
</div>
{t(`modal.error.${errorType || error}.message`, {
defaultValue: null,
}) && (
<div className="modal-content__body">
<p className="modal-content__text">
{t(`modal.error.${errorType || error}.message`)}
</p>
</div>
)}
<div className="modal-content__buttons">
<Button
className="btn--primary"
buttonText={t("modal.close")}
onClickHandler={closeModal}
/>
</div>
</Modal>
</>
);
};
ErrorModal.propTypes = {
errorType: PropTypes.string,
closeModal: PropTypes.func,
};
export default ErrorModal;