form initial commit

This commit is contained in:
Alex Holliday committed 2026-02-02 23:01:35 +00:00
1 parent 1fefb038f0
commit f2363a7a09
6 files changed
+265 -2

No files matched your search

@@ -0,0 +1,164 @@
import { Box, Stack, Typography, IconButton } from "@mui/material";
import { useTheme } from "@mui/material/styles";
import { Upload, X } from "lucide-react";
import { useState, useRef, useCallback } from "react";
import { useTranslation } from "react-i18next";
interface FileObject {
src: string;
name: string;
file: File;
}
interface ImageUploadProps {
src?: string;
onChange?: (file: FileObject | undefined) => void;
maxSize?: number;
accept?: string[];
error?: string;
}
export const ImageUpload = ({
src,
onChange,
maxSize = 3 * 1024 * 1024,
accept = ["jpg", "jpeg", "png"],
error,
}: ImageUploadProps) => {
const theme = useTheme();
const { t } = useTranslation();
const inputRef = useRef<HTMLInputElement>(null);
const [isDragging, setIsDragging] = useState(false);
const [localError, setLocalError] = useState<string | null>(null);
const [preview, setPreview] = useState<FileObject | null>(null);
const handleFile = useCallback(
(file: File | undefined) => {
if (!file) return;
const isValidType = accept.some((type) => file.type.includes(type));
const isValidSize = file.size <= maxSize;
if (!isValidType) {
setLocalError(t("common.errors.invalidFileFormat"));
return;
}
if (!isValidSize) {
setLocalError(t("common.errors.invalidFileSize"));
return;
}
setLocalError(null);
const fileObj: FileObject = {
src: URL.createObjectURL(file),
name: file.name,
file,
};
setPreview(fileObj);
onChange?.(fileObj);
},
[maxSize, accept, onChange, t]
);
const handleClear = () => {
setPreview(null);
setLocalError(null);
onChange?.(undefined);
if (inputRef.current) inputRef.current.value = "";
};
const displaySrc = src || preview?.src;
const displayError = localError || error;
return (
<Stack sx={{ width: "100%", maxWidth: 500 }}>
{displaySrc ? (
<Stack
alignItems="center"
gap={1}
>
<Box
component="img"
src={displaySrc}
alt="Preview"
sx={{ maxWidth: 250, maxHeight: 250, objectFit: "contain", borderRadius: 1 }}
/>
<IconButton
size="small"
onClick={handleClear}
sx={{ color: theme.palette.error.main }}
>
<X size={18} />
</IconButton>
</Stack>
) : (
<Stack
onDragOver={(e) => {
e.preventDefault();
setIsDragging(true);
}}
onDragLeave={() => setIsDragging(false)}
onDrop={(e) => {
e.preventDefault();
setIsDragging(false);
handleFile(e.dataTransfer.files?.[0]);
}}
alignItems="center"
justifyContent="center"
gap={1}
sx={{
position: "relative",
width: "100%",
minHeight: 150,
border: "2px dashed",
borderRadius: 1,
borderColor: isDragging ? theme.palette.primary.main : theme.palette.divider,
backgroundColor: isDragging ? theme.palette.action.hover : "transparent",
transition: "0.2s",
cursor: "pointer",
"&:hover": {
borderColor: theme.palette.primary.main,
backgroundColor: theme.palette.action.hover,
},
}}
>
<input
ref={inputRef}
type="file"
accept={accept.map((ext) => `.${ext}`).join(",")}
onChange={(e) => handleFile(e.target.files?.[0])}
style={{ position: "absolute", inset: 0, opacity: 0, cursor: "pointer" }}
/>
<Upload size={24} />
<Typography
variant="body2"
color="text.secondary"
>
<Typography
component="span"
variant="body2"
color="primary"
fontWeight={500}
>
{t("common.imageUpload.clickToUpload")}
</Typography>{" "}
{t("common.imageUpload.orDragAndDrop")}
</Typography>
<Typography
variant="caption"
color="text.disabled"
>
{accept.join(", ").toUpperCase()} • {t("common.imageUpload.maxSize")}{" "}
{Math.round(maxSize / 1024 / 1024)}MB
</Typography>
</Stack>
)}
{displayError && (
<Typography
variant="caption"
color="error"
sx={{ mt: 1 }}
>
{displayError}
</Typography>
)}
</Stack>
);
};
@@ -12,3 +12,4 @@ export { DialogInput as Dialog } from "./Dialog";
export * from "./Radio";
export * from "./Switch";
export * from "./Slider";
export * from "./ImageUpload";
@@ -0,0 +1,46 @@
import { BasePage, ConfigBox } from "@/Components/v2/design-elements";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import { ImageUpload, SwitchComponent } from "@/Components/v2/inputs";
import { useTheme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
const CreateStatusPage = () => {
const theme = useTheme();
const { t } = useTranslation();
return (
<BasePage>
<ConfigBox
title={t("pages.statusPages.form.access.title")}
subtitle={t("pages.statusPages.form.access.description")}
rightContent={
<Stack
direction="row"
alignItems="center"
spacing={theme.spacing(2)}
>
<SwitchComponent
// checked={field.value ?? false}
// onChange={(e) => field.onChange(e.target.checked)}
/>
<Typography>
{t("pages.statusPages.form.access.option.published.name")}
</Typography>
</Stack>
}
/>
<ConfigBox
title={t("pages.statusPages.form.appearance.title")}
subtitle={t("pages.statusPages.form.appearance.description")}
rightContent={
<Stack alignItems={"center"}>
<ImageUpload />
</Stack>
}
/>
</BasePage>
);
};
export default CreateStatusPage;
+8 -2
View File
@@ -36,7 +36,7 @@ import Checks from "../Pages/Checks/index";
import Incidents from "../Pages/Incidents/";
// Status pages
import CreateStatus from "../Pages/StatusPage/Create/index.jsx";
import CreateStatus from "../Pages/StatusPage/Create/";
import StatusPages from "../Pages/StatusPage/StatusPages";
import Status from "../Pages/StatusPage/Status";
@@ -249,7 +249,13 @@ const Routes = () => {
<Route
path="status/uptime/create"
element={<CreateStatus />}
element={
<>
<ThemeProvider theme={v2theme}>
<CreateStatus />
</ThemeProvider>
</>
}
/>
<Route
+46
View File
@@ -11,6 +11,16 @@
"resolved": "Resolved",
"na": "N/A"
},
"imageUpload": {
"clickToUpload": "Click to upload",
"orDragAndDrop": "or drag and drop",
"maxSize": "Max size",
"supportedFormats": "Supported formats"
},
"errors": {
"invalidFileFormat": "Invalid file format",
"invalidFileSize": "File size exceeds maximum allowed"
},
"buttons": {
"toggleTheme": "Toggles light & dark",
"testNotifications": "Test notifications",
@@ -483,6 +493,42 @@
"monitorsList": {
"chartTypeHeatmap": "Heatmap",
"chartTypeHistogram": "Histogram"
},
"form": {
"access": {
"title": "Access",
"description": "Choose if you want your status page to be public",
"option": {
"published": {
"name": "Published and publicly visible"
}
}
},
"appearance": {
"title": "Appearance",
"description": "Define the default look and feel of your public status page",
"option": {}
}
},
"settings": {
"title": "Status page settings",
"description": "Configure basic settings for your status page.",
"option": {
"name": {
"label": "Status page name",
"placeholder": "e.g. My Company Status Page"
},
"subdomain": {
"label": "Subdomain",
"placeholder": "e.g. my-company"
},
"timezone": {
"label": "Timezone"
},
"published": {
"label": "Published and visible to the public"
}
}
}
}
},