- Link general settings and contens to status page in navigation
This commit is contained in:
1 parent
cc2187d51e
commit
b275bdc8ef
3 files changed
+62
-67
No files matched your search
@@ -169,7 +169,7 @@ const ProgressUpload = ({ icon, label, size, progress = 0, onClick, error }) =>
|
|||||||
|
|
||||||
ProgressUpload.propTypes = {
|
ProgressUpload.propTypes = {
|
||||||
icon: PropTypes.element, // JSX element for the icon (optional)
|
icon: PropTypes.element, // JSX element for the icon (optional)
|
||||||
label: PropTypes.string.isRequired, // Label text for the progress item
|
label: PropTypes.string, // Label text for the progress item
|
||||||
size: PropTypes.string.isRequired, // Size information for the progress item
|
size: PropTypes.string.isRequired, // Size information for the progress item
|
||||||
progress: PropTypes.number.isRequired, // Current progress value (0-100)
|
progress: PropTypes.number.isRequired, // Current progress value (0-100)
|
||||||
onClick: PropTypes.func.isRequired, // Function to handle click events on the remove button
|
onClick: PropTypes.func.isRequired, // Function to handle click events on the remove button
|
||||||
|
|||||||
@@ -7,13 +7,17 @@ import TabPanel from "@mui/lab/TabPanel";
|
|||||||
import TextInput from "../../Inputs/TextInput";
|
import TextInput from "../../Inputs/TextInput";
|
||||||
import ImageField from "../../Inputs/Image";
|
import ImageField from "../../Inputs/Image";
|
||||||
import timezones from "../../../Utils/timezones.json";
|
import timezones from "../../../Utils/timezones.json";
|
||||||
import Select from "../../Inputs/Select"
|
import Select from "../../Inputs/Select";
|
||||||
import { logoImageValidation, publicPageGeneralSettingsValidation } from "../../../Validation/validation"
|
import {
|
||||||
|
logoImageValidation,
|
||||||
|
publicPageGeneralSettingsValidation,
|
||||||
|
} from "../../../Validation/validation";
|
||||||
import { buildErrors } from "../../../Validation/error";
|
import { buildErrors } from "../../../Validation/error";
|
||||||
import { formatBytes } from "../../../Utils/fileUtils";
|
import { formatBytes } from "../../../Utils/fileUtils";
|
||||||
import ProgressUpload from "../../ProgressBars";
|
import ProgressUpload from "../../ProgressBars";
|
||||||
import ImageIcon from "@mui/icons-material/Image";
|
import ImageIcon from "@mui/icons-material/Image";
|
||||||
import { HttpAdornment } from "../../Inputs/TextInput/Adornments";
|
import { HttpAdornment } from "../../Inputs/TextInput/Adornments";
|
||||||
|
import { hasValidationErrors } from "../../../Validation/error";
|
||||||
|
|
||||||
const GeneralSettingsPanel = () => {
|
const GeneralSettingsPanel = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -32,7 +36,6 @@ const GeneralSettingsPanel = () => {
|
|||||||
publish: false,
|
publish: false,
|
||||||
logo: null,
|
logo: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clears specific error from errors state
|
// Clears specific error from errors state
|
||||||
const clearError = (err) => {
|
const clearError = (err) => {
|
||||||
setErrors((prev) => {
|
setErrors((prev) => {
|
||||||
@@ -44,20 +47,15 @@ const GeneralSettingsPanel = () => {
|
|||||||
const removeLogo = () => {
|
const removeLogo = () => {
|
||||||
errors["logo"] && clearError("logo");
|
errors["logo"] && clearError("logo");
|
||||||
setLogo({});
|
setLogo({});
|
||||||
|
setLocalData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
logo: logo?.src,
|
||||||
|
}));
|
||||||
// interrupt interval if image upload is canceled prior to completing the process
|
// interrupt interval if image upload is canceled prior to completing the process
|
||||||
clearInterval(intervalRef.current);
|
clearInterval(intervalRef.current);
|
||||||
setProgress({ value: 0, isLoading: false });
|
setProgress({ value: 0, isLoading: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Updates profile image displayed on UI
|
|
||||||
const handleUpdateLogo = () => {
|
|
||||||
setProgress({ value: 0, isLoading: false });
|
|
||||||
setLocalData((prev) => ({
|
|
||||||
...prev,
|
|
||||||
logo: logo.src,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
@@ -67,7 +65,21 @@ const GeneralSettingsPanel = () => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = () => {};
|
const handleSubmit = () => {
|
||||||
|
//validate rest of the form
|
||||||
|
delete localData.logo;
|
||||||
|
delete localData.publish;
|
||||||
|
if (hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//validate image field
|
||||||
|
let error = validateField(
|
||||||
|
{ type: logo?.type ?? null, size: logo?.size ?? null },
|
||||||
|
logoImageValidation
|
||||||
|
);
|
||||||
|
if (error) return;
|
||||||
|
localData.logo = { ...logo, size: formatBytes(logo?.size) };
|
||||||
|
};
|
||||||
|
|
||||||
const handleBlur = (event) => {
|
const handleBlur = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -96,7 +108,7 @@ const GeneralSettingsPanel = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleLogo = (event) => {
|
const handleLogo = (event) => {
|
||||||
const pic = event.target.files[0];
|
const pic = event.target?.files?.[0];
|
||||||
let error = validateField({ type: pic?.type, size: pic?.size }, logoImageValidation);
|
let error = validateField({ type: pic?.type, size: pic?.size }, logoImageValidation);
|
||||||
if (error) return;
|
if (error) return;
|
||||||
|
|
||||||
@@ -104,9 +116,9 @@ const GeneralSettingsPanel = () => {
|
|||||||
setLogo({
|
setLogo({
|
||||||
src: URL.createObjectURL(pic),
|
src: URL.createObjectURL(pic),
|
||||||
name: pic.name,
|
name: pic.name,
|
||||||
size: formatBytes(pic.size),
|
type: pic.type,
|
||||||
|
size: pic.size,
|
||||||
});
|
});
|
||||||
|
|
||||||
intervalRef.current = setInterval(() => {
|
intervalRef.current = setInterval(() => {
|
||||||
const buffer = 12;
|
const buffer = 12;
|
||||||
setProgress((prev) => {
|
setProgress((prev) => {
|
||||||
@@ -121,7 +133,7 @@ const GeneralSettingsPanel = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<TabPanel
|
<TabPanel
|
||||||
value="general settings"
|
value="General Settings"
|
||||||
sx={{
|
sx={{
|
||||||
"& h1, & p, & input": {
|
"& h1, & p, & input": {
|
||||||
color: theme.palette.text.tertiary,
|
color: theme.palette.text.tertiary,
|
||||||
@@ -131,7 +143,6 @@ const GeneralSettingsPanel = () => {
|
|||||||
<Stack
|
<Stack
|
||||||
component="form"
|
component="form"
|
||||||
className="status-general-settings-form"
|
className="status-general-settings-form"
|
||||||
onSubmit={handleSubmit}
|
|
||||||
noValidate
|
noValidate
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
gap={theme.spacing(12)}
|
gap={theme.spacing(12)}
|
||||||
@@ -167,7 +178,7 @@ const GeneralSettingsPanel = () => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.spacing(6)}>
|
<Stack gap={theme.spacing(18)}>
|
||||||
<TextInput
|
<TextInput
|
||||||
id="companyName"
|
id="companyName"
|
||||||
type="text"
|
type="text"
|
||||||
@@ -175,7 +186,8 @@ const GeneralSettingsPanel = () => {
|
|||||||
value={localData.companyName}
|
value={localData.companyName}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
error={errors["companyName"]}
|
helperText={errors["companyName"]}
|
||||||
|
error={errors["companyName"] ? true : false}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
id="url"
|
id="url"
|
||||||
@@ -186,7 +198,8 @@ const GeneralSettingsPanel = () => {
|
|||||||
//prefix={"http://uptimegenie.com/"}
|
//prefix={"http://uptimegenie.com/"}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
error={errors["url"]}
|
helperText={errors["url"]}
|
||||||
|
error={errors["url"] ? true : false}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
@@ -219,7 +232,7 @@ const GeneralSettingsPanel = () => {
|
|||||||
<ProgressUpload
|
<ProgressUpload
|
||||||
icon={<ImageIcon />}
|
icon={<ImageIcon />}
|
||||||
label={logo?.name}
|
label={logo?.name}
|
||||||
size={logo?.size}
|
size={formatBytes(logo?.size)}
|
||||||
progress={progress.value}
|
progress={progress.value}
|
||||||
onClick={removeLogo}
|
onClick={removeLogo}
|
||||||
error={errors["logo"]}
|
error={errors["logo"]}
|
||||||
@@ -227,35 +240,6 @@ const GeneralSettingsPanel = () => {
|
|||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
{logo?.src && (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
mt={theme.spacing(10)}
|
|
||||||
gap={theme.spacing(5)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={removeLogo}
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
onClick={handleUpdateLogo}
|
|
||||||
disabled={
|
|
||||||
(Object.keys(errors).length !== 0 && errors?.logo) ||
|
|
||||||
progress.value !== 100
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Update
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
<TextInput
|
<TextInput
|
||||||
id="color"
|
id="color"
|
||||||
label="Color"
|
label="Color"
|
||||||
@@ -277,6 +261,18 @@ const GeneralSettingsPanel = () => {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleSubmit}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import { Box, Tab, useTheme } from "@mui/material";
|
|||||||
import TabContext from "@mui/lab/TabContext";
|
import TabContext from "@mui/lab/TabContext";
|
||||||
import TabList from "@mui/lab/TabList";
|
import TabList from "@mui/lab/TabList";
|
||||||
import GeneralSettingsPanel from "../../../Components/TabPanels/Status/GeneralSettingsPanel";
|
import GeneralSettingsPanel from "../../../Components/TabPanels/Status/GeneralSettingsPanel";
|
||||||
import ImageField from "../../../Components/Inputs/Image";
|
import {
|
||||||
import Checkbox from "../../../Components/Inputs/Checkbox";
|
capitalizeFirstLetter,
|
||||||
|
toLowerCaseFirstLetter,
|
||||||
|
} from "../../../Utils/stringUtils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateStatus page renders a page with tabs for general settings and contents.
|
* CreateStatus page renders a page with tabs for general settings and contents.
|
||||||
@@ -14,22 +16,19 @@ import Checkbox from "../../../Components/Inputs/Checkbox";
|
|||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const CreateStatus = ({ open = "general settings" }) => {
|
const CreateStatus = ({ open = "general-settings" }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const tab = open;
|
const tab = open
|
||||||
|
.split("-")
|
||||||
|
.map((a) => capitalizeFirstLetter(a))
|
||||||
|
.join(" ");
|
||||||
const handleTabChange = (event, newTab) => {
|
const handleTabChange = (event, newTab) => {
|
||||||
navigate(`/status/${newTab}`);
|
let toNavString = newTab.split(" ").map((a) => toLowerCaseFirstLetter(a));
|
||||||
|
toNavString = toNavString.join("-");
|
||||||
|
navigate(`/status/${toNavString}`);
|
||||||
};
|
};
|
||||||
let tabList = ["General Settings", "Contents"];
|
let tabList = ["General Settings", "Contents"];
|
||||||
const handlePicture = (event) => {}
|
|
||||||
|
|
||||||
const handleSubmit = () => {};
|
|
||||||
|
|
||||||
const handleChange = () => {};
|
|
||||||
|
|
||||||
const handleBlur = () => {};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className="status"
|
className="status"
|
||||||
@@ -56,7 +55,7 @@ const CreateStatus = ({ open = "general settings" }) => {
|
|||||||
<Tab
|
<Tab
|
||||||
label={label}
|
label={label}
|
||||||
key={index}
|
key={index}
|
||||||
value={label.toLowerCase()}
|
value={label}
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: theme.palette.text.tertiary,
|
color: theme.palette.text.tertiary,
|
||||||
@@ -82,7 +81,7 @@ const CreateStatus = ({ open = "general settings" }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CreateStatus.propTypes = {
|
CreateStatus.propTypes = {
|
||||||
open: PropTypes.oneOf(["general settings", "contents"]),
|
open: PropTypes.oneOf(["general-settings", "contents"]),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CreateStatus;
|
export default CreateStatus;
|
||||||
Reference in new issue
Block a user