-
Notifications
You must be signed in to change notification settings - Fork 6
/
CaseCreator.js
39 lines (35 loc) · 1.5 KB
/
CaseCreator.js
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
import React from "react";
import "regenerator-runtime/runtime";
import { useEnforceLogin } from "../hooks/useAuth.js";
import CaseCreatorFlow from "./CaseCreatorFlow.jsx";
import CaseImporterFlow from "./CaseImporterFlow.jsx";
import ModalDialog from "./common/ModalDialog.jsx";
import useId from "@mui/utils/useId";
/**
* CaseCreator component that toggles between the CaseCreatorFlow and CaseImporterFlow based on user action.
* It presents a modal dialog which either guides the user through creating a new assurance case
* or importing an existing one. The component ensures that a user is logged in before allowing case creation
* or importation.
*
* @param {Object} props - Component props.
* @param {boolean} props.isOpen - Determines if the modal dialog is open.
* @param {Function} props.onClose - Handler called when the modal dialog is requested to close.
* @param {boolean} props.isImport - Flag determining which flow to show: true for import, false for creation.
* @returns {JSX.Element|null} The rendered component if the user is logged in, otherwise null.
*/
function CaseCreator({ isOpen, onClose, isImport }) {
const titleId = useId();
if (!useEnforceLogin()) {
return null;
}
return (
<ModalDialog aria-labelledby={titleId} open={isOpen} onClose={onClose}>
{isImport ? (
<CaseImporterFlow titleId={titleId} onClose={onClose} />
) : (
<CaseCreatorFlow titleId={titleId} onClose={onClose} />
)}
</ModalDialog>
);
}
export default CaseCreator;