Added skeleton layout

This commit is contained in:
Daniel Cojocea committed 2024-08-08 17:15:39 -04:00
1 parent e914a39d0b
commit 8b351871c6
1 file changed
+212 -153
+212 -153
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { Box, Modal, Stack, Typography } from "@mui/material"; import { Box, Modal, Skeleton, Stack, Typography } from "@mui/material";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { useNavigate, useParams } from "react-router"; import { useNavigate, useParams } from "react-router";
import { import {
@@ -21,6 +21,53 @@ import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
import "./index.css"; import "./index.css";
/**
* Renders a skeleton layout.
*
* @returns {JSX.Element}
*/
const SkeletonLayout = () => {
const theme = useTheme();
return (
<>
<Skeleton variant="rounded" width="15%" height={34} />
<Stack gap={theme.gap.xl} mt={theme.gap.medium} maxWidth="1000px">
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
<Skeleton
variant="circular"
style={{ minWidth: 24, minHeight: 24 }}
/>
<Box width="80%">
<Skeleton
variant="rounded"
width="50%"
height={24}
sx={{ mb: theme.gap.small }}
/>
<Skeleton variant="rounded" width="50%" height={18} />
</Box>
<Stack
direction="row"
gap={theme.gap.medium}
sx={{
ml: "auto",
alignSelf: "flex-end",
}}
>
<Skeleton variant="rounded" width={100} height={34} />
<Skeleton variant="rounded" width={100} height={34} />
</Stack>
</Stack>
<Skeleton variant="rounded" width="100%" height={500} />
<Stack direction="row" justifyContent="flex-end">
<Skeleton variant="rounded" width="15%" height={34} />
</Stack>
</Stack>
</>
);
};
const PageSpeedConfigure = () => { const PageSpeedConfigure = () => {
const theme = useTheme(); const theme = useTheme();
const navigate = useNavigate(); const navigate = useNavigate();
@@ -55,7 +102,7 @@ const PageSpeedConfigure = () => {
const handleChange = (event, id) => { const handleChange = (event, id) => {
let { value } = event.target; let { value } = event.target;
if ((id = "interval")) { if (id === "interval") {
value = value * MS_PER_MINUTE; value = value * MS_PER_MINUTE;
} }
setMonitor((prev) => ({ ...prev, [id]: value })); setMonitor((prev) => ({ ...prev, [id]: value }));
@@ -97,162 +144,174 @@ const PageSpeedConfigure = () => {
} }
}; };
let loading = Object.keys(monitor).length === 0;
return ( return (
<Box className="configure-pagespeed"> <Box className="configure-pagespeed">
<Button {loading ? (
level="tertiary" <SkeletonLayout />
label="Back" ) : (
animate="slideLeft" <>
img={<WestRoundedIcon />} <Button
onClick={() => navigate(-1)} level="tertiary"
sx={{ label="Back"
backgroundColor: theme.palette.otherColors.fillGray, animate="slideLeft"
mb: theme.gap.large, img={<WestRoundedIcon />}
px: theme.gap.ml, onClick={() => navigate(-1)}
"& svg.MuiSvgIcon-root": { sx={{
mr: theme.gap.small, backgroundColor: theme.palette.otherColors.fillGray,
fill: theme.palette.otherColors.slateGray, mb: theme.gap.large,
}, px: theme.gap.ml,
}} "& svg.MuiSvgIcon-root": {
/> mr: theme.gap.small,
<form fill: theme.palette.otherColors.slateGray,
noValidate },
spellCheck="false" }}
onSubmit={handleSave} />
style={{ <form
display: "flex", noValidate
flexDirection: "column", spellCheck="false"
gap: theme.gap.large, onSubmit={handleSave}
maxWidth: "1000px", style={{
}} display: "flex",
> flexDirection: "column",
<Stack direction="row" gap={theme.gap.small}> gap: theme.gap.large,
{monitor?.status ? <GreenCheck /> : <RedCheck />} maxWidth: "1000px",
<Box> }}
<Typography component="h1" mb={theme.gap.xs} sx={{ lineHeight: 1 }}> >
{monitor?.url} <Stack direction="row" gap={theme.gap.small}>
</Typography> {monitor?.status ? <GreenCheck /> : <RedCheck />}
<Typography <Box>
component="span" <Typography
sx={{ component="h1"
color: monitor?.status mb={theme.gap.xs}
? "var(--env-var-color-17)" sx={{ lineHeight: 1 }}
: "var(--env-var-color-24)", >
}} {monitor?.url}
> </Typography>
Your pagespeed monitor is {monitor?.status ? "live" : "down"}. <Typography
</Typography> component="span"
</Box> sx={{
<Box alignSelf="flex-end" ml="auto"> color: monitor?.status
<Button ? "var(--env-var-color-17)"
level="tertiary" : "var(--env-var-color-24)",
label="Pause" }}
animate="rotate180" >
img={<PauseCircleOutlineIcon />} Your pagespeed monitor is {monitor?.status ? "live" : "down"}.
sx={{
backgroundColor: theme.palette.otherColors.fillGray,
pl: theme.gap.small,
pr: theme.gap.medium,
"& svg": {
mr: theme.gap.xs,
},
}}
/>
<Button
level="error"
label="Remove"
sx={{
boxShadow: "none",
px: theme.gap.ml,
ml: theme.gap.medium,
}}
onClick={() => setIsOpen(true)}
/>
</Box>
</Stack>
<Stack gap={theme.gap.xl}>
<Stack direction="row">
<Typography component="h3">Monitor friendly name</Typography>
<Field
type="text"
id="monitor-name"
placeholder="Example monitor"
value={monitor?.name || ""}
onChange={(event) => handleChange(event, "name")}
error={errors.name}
/>
</Stack>
<Stack direction="row">
<Typography component="h3">URL</Typography>
<Field
type="url"
id="monitor-url"
placeholder="random.website.com"
value={monitor?.url?.replace("http://", "") || ""}
onChange={(event) => handleChange(event, "url")}
error={errors.url}
disabled={true}
/>
</Stack>
<Stack direction="row">
<Typography component="h3">Check frequency</Typography>
<Select
id="monitor-frequency"
items={frequencies}
value={monitor?.interval / MS_PER_MINUTE || 3}
onChange={(event) => handleChange(event, "interval")}
/>
</Stack>
<Stack direction="row">
<Typography component="h3">
Incidents notifications{" "}
<Typography component="span">(coming soon)</Typography>
</Typography>
<Stack className="section-disabled">
<Typography mb={theme.gap.small}>
When there is a new incident,
</Typography>
<Checkbox
id="notify-sms"
label="Notify via SMS (coming soon)"
isChecked={false}
isDisabled={true}
/>
<Checkbox
id="notify-email"
label="Notify via email (to gorkem.cetin@bluewavelabs.ca)"
isChecked={false}
/>
<Checkbox
id="notify-emails"
label="Notify via email to following emails"
isChecked={false}
/>
<Box mx={`calc(${theme.gap.ml} * 2)`}>
<Field
id="notify-emails-list"
placeholder="notifications@gmail.com"
value=""
onChange={() => console.log("disabled")}
error=""
/>
<Typography mt={theme.gap.small}>
You can separate multiple emails with a comma
</Typography> </Typography>
</Box> </Box>
<Box alignSelf="flex-end" ml="auto">
<Button
level="tertiary"
label="Pause"
animate="rotate180"
img={<PauseCircleOutlineIcon />}
sx={{
backgroundColor: theme.palette.otherColors.fillGray,
pl: theme.gap.small,
pr: theme.gap.medium,
"& svg": {
mr: theme.gap.xs,
},
}}
/>
<Button
level="error"
label="Remove"
sx={{
boxShadow: "none",
px: theme.gap.ml,
ml: theme.gap.medium,
}}
onClick={() => setIsOpen(true)}
/>
</Box>
</Stack> </Stack>
</Stack> <Stack gap={theme.gap.xl}>
</Stack> <Stack direction="row">
<Stack direction="row" justifyContent="flex-end"> <Typography component="h3">Monitor friendly name</Typography>
<Button <Field
type="submit" type="text"
level="primary" id="monitor-name"
label="Save" placeholder="Example monitor"
onClick={handleSave} value={monitor?.name || ""}
sx={{ px: theme.gap.large, mt: theme.gap.large }} onChange={(event) => handleChange(event, "name")}
/> error={errors.name}
</Stack> />
</form> </Stack>
<Stack direction="row">
<Typography component="h3">URL</Typography>
<Field
type="url"
id="monitor-url"
placeholder="random.website.com"
value={monitor?.url?.replace("http://", "") || ""}
onChange={(event) => handleChange(event, "url")}
error={errors.url}
disabled={true}
/>
</Stack>
<Stack direction="row">
<Typography component="h3">Check frequency</Typography>
<Select
id="monitor-frequency"
items={frequencies}
value={monitor?.interval / MS_PER_MINUTE || 3}
onChange={(event) => handleChange(event, "interval")}
/>
</Stack>
<Stack direction="row">
<Typography component="h3">
Incidents notifications{" "}
<Typography component="span">(coming soon)</Typography>
</Typography>
<Stack className="section-disabled">
<Typography mb={theme.gap.small}>
When there is a new incident,
</Typography>
<Checkbox
id="notify-sms"
label="Notify via SMS (coming soon)"
isChecked={false}
isDisabled={true}
/>
<Checkbox
id="notify-email"
label="Notify via email (to gorkem.cetin@bluewavelabs.ca)"
isChecked={false}
/>
<Checkbox
id="notify-emails"
label="Notify via email to following emails"
isChecked={false}
/>
<Box mx={`calc(${theme.gap.ml} * 2)`}>
<Field
id="notify-emails-list"
placeholder="notifications@gmail.com"
value=""
onChange={() => console.log("disabled")}
error=""
/>
<Typography mt={theme.gap.small}>
You can separate multiple emails with a comma
</Typography>
</Box>
</Stack>
</Stack>
</Stack>
<Stack direction="row" justifyContent="flex-end">
<Button
type="submit"
level="primary"
label="Save"
onClick={handleSave}
sx={{ px: theme.gap.large, mt: theme.gap.large }}
/>
</Stack>
</form>
</>
)}
<Modal <Modal
aria-labelledby="modal-delete-pagespeed-monitor" aria-labelledby="modal-delete-pagespeed-monitor"
aria-describedby="delete-pagespeed-monitor-confirmation" aria-describedby="delete-pagespeed-monitor-confirmation"