import { useState, useRef } from "react"; import { Button, Box, Stack, Typography } from "@mui/material"; import { ConfigBox } from "../../../Pages/Settings/styled"; import Checkbox from "../../Inputs/Checkbox"; import { useTheme } from "@emotion/react"; import TabPanel from "@mui/lab/TabPanel"; import TextInput from "../../Inputs/TextInput"; import ImageField from "../../Inputs/Image"; import timezones from "../../../Utils/timezones.json"; import Select from "../../Inputs/Select" import { logoImageValidation, publicPageGeneralSettingsValidation } from "../../../Validation/validation" import { buildErrors } from "../../../Validation/error"; import { formatBytes } from "../../../Utils/fileUtils"; import ProgressUpload from "../../ProgressBars"; import ImageIcon from "@mui/icons-material/Image"; import { HttpAdornment } from "../../Inputs/TextInput/Adornments"; const GeneralSettingsPanel = () => { const theme = useTheme(); const [errors, setErrors] = useState({}); const [logo, setLogo] = useState(); const [progress, setProgress] = useState({ value: 0, isLoading: false }); const intervalRef = useRef(null); // Local state for form data, errors, and file handling const [localData, setLocalData] = useState({ companyName: "", url: "", timezone: "America/Toronto", color: "#4169E1", theme: "light", //which fields matching below? publish: false, logo: null, }); // Clears specific error from errors state const clearError = (err) => { setErrors((prev) => { const updatedErrors = { ...prev }; if (updatedErrors[err]) delete updatedErrors[err]; return updatedErrors; }); }; const removeLogo = () => { errors["logo"] && clearError("logo"); setLogo({}); // interrupt interval if image upload is canceled prior to completing the process clearInterval(intervalRef.current); 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) => { event.preventDefault(); const { value, id } = event.target; setLocalData((prev) => ({ ...prev, [id]: value, })); }; const handleSubmit = () => {}; const handleBlur = (event) => { event.preventDefault(); const { value, id } = event.target; const { error } = publicPageGeneralSettingsValidation.validate( { [id]: value }, { abortEarly: false, } ); setErrors((prev) => { return buildErrors(prev, id, error); }); }; const validateField = (toValidate, schema, name = "logo") => { const { error } = schema.validate(toValidate, { abortEarly: false }); setErrors((prev) => { let prevErrors = { ...prev }; if (error) prevErrors[name] = error?.details[0].message; else delete prevErrors[name]; return prevErrors; }); if (error) return true; }; const handleLogo = (event) => { const pic = event.target.files[0]; let error = validateField({ type: pic?.type, size: pic?.size }, logoImageValidation); if (error) return; setProgress((prev) => ({ ...prev, isLoading: true })); setLogo({ src: URL.createObjectURL(pic), name: pic.name, size: formatBytes(pic.size), }); intervalRef.current = setInterval(() => { const buffer = 12; setProgress((prev) => { if (prev.value + buffer >= 100) { clearInterval(intervalRef.current); return { value: 100, isLoading: false }; } return { ...prev, value: prev.value + buffer }; }); }, 120); }; return ( Access If your status page is ready, you can mark it as published. Basic Information Define company name and the subdomain that your status page points to. } //prefix={"http://uptimegenie.com/"} onChange={handleChange} onBlur={handleBlur} error={errors["url"]} /> Appearance Define the default look and feel of your public status page. ); }; export default GeneralSettingsPanel;