Files
Checkmate/Client/src/Components/Fallback/index.jsx
T

86 lines
2.6 KiB
React
Raw Normal View History

2024-07-22 16:38:43 -04:00
import PropTypes from "prop-types";
2024-07-22 16:35:57 -04:00
import { useTheme } from "@emotion/react";
2024-08-14 17:47:19 -04:00
import { Box, Stack, Typography } from "@mui/material";
2024-07-22 16:35:57 -04:00
import Skeleton from "../../assets/Images/create-placeholder.svg?react";
import SkeletonDark from "../../assets/Images/create-placeholder-dark.svg?react";
import Background from "../../assets/Images/background-grid.svg?react";
2024-07-22 16:35:57 -04:00
import Button from "../Button";
import Check from "../Check/Check";
import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux";
2024-07-22 16:35:57 -04:00
import "./index.css";
2024-07-22 16:38:43 -04:00
/**
* Fallback component to display a fallback UI with a title, a list of checks, and a navigation button.
*
* @param {Object} props - The component props.
* @param {string} props.title - The title to be displayed in the fallback UI.
* @param {Array<string>} props.checks - An array of strings representing the checks to display.
* @param {string} [props.link="/"] - The link to navigate to.
*
* @returns {JSX.Element} The rendered fallback UI.
*/
const Fallback = ({ title, checks, link = "/", isAdmin }) => {
2024-07-22 16:35:57 -04:00
const theme = useTheme();
const navigate = useNavigate();
const mode = useSelector((state) => state.ui.mode);
2024-07-22 16:35:57 -04:00
return (
<Stack
className={`fallback__${title.trim().split(" ")[0]}`}
alignItems="center"
2024-08-27 17:01:28 -04:00
gap={theme.spacing(20)}
2024-07-22 16:35:57 -04:00
>
{mode === "light" ? (
<Skeleton style={{ zIndex: 1 }} />
) : (
<SkeletonDark style={{ zIndex: 1 }} />
)}
2024-08-14 17:47:19 -04:00
<Box
className="background-pattern-svg"
sx={{
"& svg g g:last-of-type path": {
stroke: theme.palette.border.light,
},
}}
>
<Background style={{ width: "100%" }} />
</Box>
2024-08-27 17:01:28 -04:00
<Stack gap={theme.spacing(4)} maxWidth={"275px"} zIndex={1}>
<Typography
component="h1"
marginY={theme.spacing(4)}
color={theme.palette.text.tertiary}
2024-08-27 17:01:28 -04:00
>
2024-08-28 10:28:02 -04:00
A {title} is used to:
2024-07-22 16:35:57 -04:00
</Typography>
{checks.map((check, index) => (
<Check
text={check}
key={`${title.trim().split(" ")[0]}-${index}`}
outlined={true}
/>
))}
</Stack>
2024-08-28 10:28:02 -04:00
{/* TODO - display a different fallback if user is not an admin*/}
{isAdmin && (
<Button
level="primary"
label={`Let's create your ${title}`}
sx={{ alignSelf: "center" }}
onClick={() => navigate(link)}
/>
)}
2024-07-22 16:35:57 -04:00
</Stack>
);
};
2024-07-22 16:38:43 -04:00
Fallback.propTypes = {
title: PropTypes.string.isRequired,
checks: PropTypes.arrayOf(PropTypes.string).isRequired,
link: PropTypes.string,
isAdmin: PropTypes.bool,
2024-07-22 16:38:43 -04:00
};
2024-07-22 16:35:57 -04:00
export default Fallback;