// Components import { Stack, Typography, Button, Box } from "@mui/material"; import ConfigBox from "../../../Components/ConfigBox"; import Checkbox from "../../../Components/Inputs/Checkbox"; import TextInput from "../../../Components/Inputs/TextInput"; import VisuallyHiddenInput from "./Components/VisuallyHiddenInput"; import Image from "../../../Components/Image"; import LogoPlaceholder from "../../../assets/Images/logo_placeholder.svg"; import Breadcrumbs from "../../../Components/Breadcrumbs"; // Utils import { useTheme } from "@emotion/react"; import { useState } from "react"; import { useParams } from "react-router-dom"; import { useCreateStatusPage } from "../../StatusPage/Create/Hooks/useCreateStatusPage"; import { useLocation } from "react-router-dom"; import { statusPageValidation } from "../../../Validation/validation"; import { buildErrors } from "../../../Validation/error"; import { createToast } from "../../../Utils/toastUtils"; import { useNavigate } from "react-router-dom"; const CreateStatus = () => { const theme = useTheme(); const { monitorId } = useParams(); const navigate = useNavigate(); const location = useLocation(); const isCreate = location.pathname.startsWith("/distributed-uptime/status/create"); const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate); const BREADCRUMBS = [ { name: "distributed uptime", path: "/distributed-uptime" }, { name: "details", path: `/distributed-uptime/${monitorId}` }, { name: "create status page", path: `` }, ]; // Local state const [form, setForm] = useState({ isPublished: false, url: Math.floor(Math.random() * 1000000).toFixed(0), logo: undefined, companyName: "", monitors: [monitorId], }); const [errors, setErrors] = useState({}); const handleFormChange = (e) => { const { name, value, checked, type } = e.target; // Check for errors const { error } = statusPageValidation.validate( { [name]: value }, { abortEarly: false } ); setErrors((prev) => buildErrors(prev, name, error)); if (type === "checkbox") { setForm({ ...form, [name]: checked }); return; } setForm({ ...form, [name]: value }); }; const handleImageUpload = (e) => { const img = e.target?.files?.[0]; setForm((prev) => ({ ...prev, logo: img, })); }; const handleSubmit = async () => { let logoToSubmit = undefined; // Handle image if (typeof form.logo !== "undefined") { logoToSubmit = { src: URL.createObjectURL(form.logo), name: form.logo.name, type: form.logo.type, size: form.logo.size, }; } const formToSubmit = { ...form }; if (typeof logoToSubmit !== "undefined") { formToSubmit.logo = logoToSubmit; } // Validate const { error } = statusPageValidation.validate(formToSubmit, { abortEarly: false }); if (typeof error === "undefined") { const success = await createStatusPage({ form: formToSubmit }); if (success) { createToast({ body: "Status page created successfully" }); navigate(`/distributed-uptime/status/${form.url}`); } return; } const newErrors = {}; error?.details?.forEach((err) => { newErrors[err.path[0]] = err.message; }); setErrors((prev) => ({ ...prev, ...newErrors })); }; return ( Create your{" "} status page 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. Logo Upload a logo for your status page Logo ); }; export default CreateStatus;