Hooked up to state and added validation (#477)
This commit is contained in:
1 parent
f236d3ce4c
commit
480d47d914
3 files changed
+99
-43
No files matched your search
@@ -11,7 +11,8 @@
|
|||||||
}
|
}
|
||||||
.create-page-speed h1.MuiTypography-root,
|
.create-page-speed h1.MuiTypography-root,
|
||||||
.create-page-speed h2.MuiTypography-root,
|
.create-page-speed h2.MuiTypography-root,
|
||||||
.create-page-speed p.MuiTypography-root {
|
.create-page-speed p.MuiTypography-root,
|
||||||
|
.create-page-speed h2.MuiTypography-root > span.MuiTypography-root {
|
||||||
color: var(--env-var-color-5);
|
color: var(--env-var-color-5);
|
||||||
}
|
}
|
||||||
.create-page-speed h1.MuiTypography-root,
|
.create-page-speed h1.MuiTypography-root,
|
||||||
@@ -22,16 +23,29 @@
|
|||||||
font-size: var(--env-var-font-size-medium-plus);
|
font-size: var(--env-var-font-size-medium-plus);
|
||||||
}
|
}
|
||||||
.create-page-speed p.MuiTypography-root,
|
.create-page-speed p.MuiTypography-root,
|
||||||
.create-page-speed button {
|
.create-page-speed button,
|
||||||
|
.create-page-speed h2.MuiTypography-root > span.MuiTypography-root {
|
||||||
font-size: var(--env-var-font-size-medium);
|
font-size: var(--env-var-font-size-medium);
|
||||||
}
|
}
|
||||||
.create-page-speed .MuiBox-root > .field + p.MuiTypography-root {
|
.create-page-speed .MuiBox-root > .field + p.MuiTypography-root {
|
||||||
font-size: var(--env-var-font-size-small-plus);
|
font-size: var(--env-var-font-size-small-plus);
|
||||||
|
}
|
||||||
|
.create-page-speed .MuiBox-root > .field + p.MuiTypography-root,
|
||||||
|
.create-page-speed h2.MuiTypography-root > span.MuiTypography-root {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
.create-page-speed .checkbox-wrapper {
|
.create-page-speed .checkbox-wrapper {
|
||||||
margin-bottom: 1px;
|
margin-bottom: 1px;
|
||||||
}
|
}
|
||||||
|
/* to be removed */
|
||||||
|
.create-page-speed .section-disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
background-color: #f1f1f2;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
user-select: none;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.create-page-speed button:not(.MuiIconButton-root) {
|
.create-page-speed button:not(.MuiIconButton-root) {
|
||||||
height: var(--env-var-height-2);
|
height: var(--env-var-height-2);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import Field from "../../../Components/Inputs/Field";
|
|||||||
import Select from "../../../Components/Inputs/Select";
|
import Select from "../../../Components/Inputs/Select";
|
||||||
import Button from "../../../Components/Button";
|
import Button from "../../../Components/Button";
|
||||||
import Checkbox from "../../../Components/Inputs/Checkbox";
|
import Checkbox from "../../../Components/Inputs/Checkbox";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const CreatePageSpeed = () => {
|
const CreatePageSpeed = () => {
|
||||||
@@ -20,6 +22,34 @@ const CreatePageSpeed = () => {
|
|||||||
{ _id: 5, name: "5 minutes" },
|
{ _id: 5, name: "5 minutes" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
name: "",
|
||||||
|
url: "",
|
||||||
|
interval: 1,
|
||||||
|
type: "pagespeed",
|
||||||
|
});
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
|
const handleChange = (event, id) => {
|
||||||
|
const { value } = event.target;
|
||||||
|
setForm((prev) => ({ ...prev, [id]: value }));
|
||||||
|
|
||||||
|
const validation = monitorValidation.validate(
|
||||||
|
{ [id]: value },
|
||||||
|
{ abortEarly: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
setErrors((prev) => {
|
||||||
|
const updatedErrors = { ...prev };
|
||||||
|
if (validation.error) {
|
||||||
|
updatedErrors[id] = validation.error.details[0].message;
|
||||||
|
} else {
|
||||||
|
delete updatedErrors[id];
|
||||||
|
}
|
||||||
|
return updatedErrors;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="create-page-speed">
|
<Box className="create-page-speed">
|
||||||
<Stack gap={theme.gap.xl}>
|
<Stack gap={theme.gap.xl}>
|
||||||
@@ -41,57 +71,65 @@ const CreatePageSpeed = () => {
|
|||||||
id="monitor-name"
|
id="monitor-name"
|
||||||
label="Monitor friendly name"
|
label="Monitor friendly name"
|
||||||
placeholder="Example monitor"
|
placeholder="Example monitor"
|
||||||
value=""
|
isOptional={true}
|
||||||
onChange={() => console.log("disabled")}
|
value={form.name}
|
||||||
error=""
|
onChange={(event) => handleChange(event, "name")}
|
||||||
|
error={errors.name}
|
||||||
/>
|
/>
|
||||||
<Field
|
<Field
|
||||||
type="url"
|
type="url"
|
||||||
id="monitor-url"
|
id="monitor-url"
|
||||||
label="URL"
|
label="URL"
|
||||||
placeholder="random.website.com"
|
placeholder="random.website.com"
|
||||||
value=""
|
value={form.url}
|
||||||
onChange={() => console.log("disabled")}
|
onChange={(event) => handleChange(event, "url")}
|
||||||
error=""
|
error={errors.url}
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
id="monitor-frequency"
|
id="monitor-frequency"
|
||||||
label="Check frequency"
|
label="Check frequency"
|
||||||
items={frequencies}
|
items={frequencies}
|
||||||
value={1}
|
value={form.interval}
|
||||||
onChange={() => console.log("disabled")}
|
onChange={(event) => handleChange(event, "interval")}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack gap={theme.gap.small}>
|
<Stack gap={theme.gap.small}>
|
||||||
<Typography component="h2">Incidents notifications</Typography>
|
<Typography component="h2">
|
||||||
<Typography>When there is a new incident,</Typography>
|
Incidents notifications{" "}
|
||||||
<Checkbox
|
<Typography component="span">(coming soon)</Typography>
|
||||||
id="notify-sms"
|
</Typography>
|
||||||
label="Notify via SMS (coming soon)"
|
<Box className="section-disabled">
|
||||||
isChecked={false}
|
<Typography mb={theme.gap.small}>
|
||||||
isDisabled={true}
|
When there is a new incident,
|
||||||
/>
|
|
||||||
<Checkbox
|
|
||||||
id="notify-email"
|
|
||||||
label="Notify via email (to gorkem.cetin@bluewavelabs.ca)"
|
|
||||||
isChecked={true}
|
|
||||||
/>
|
|
||||||
<Checkbox
|
|
||||||
id="notify-emails"
|
|
||||||
label="Notify via email to following emails"
|
|
||||||
isChecked={true}
|
|
||||||
/>
|
|
||||||
<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>
|
||||||
|
<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={true}
|
||||||
|
/>
|
||||||
|
<Checkbox
|
||||||
|
id="notify-emails"
|
||||||
|
label="Notify via email to following emails"
|
||||||
|
isChecked={true}
|
||||||
|
/>
|
||||||
|
<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>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack direction="row" justifyContent="flex-end" gap={theme.gap.small}>
|
<Stack direction="row" justifyContent="flex-end" gap={theme.gap.small}>
|
||||||
|
|||||||
@@ -74,18 +74,22 @@ const credentials = joi.object({
|
|||||||
const monitorValidation = joi.object({
|
const monitorValidation = joi.object({
|
||||||
url: joi
|
url: joi
|
||||||
.string()
|
.string()
|
||||||
|
.uri({ allowRelative: true })
|
||||||
.trim()
|
.trim()
|
||||||
.messages({ "string.empty": "*This field is required." }),
|
.messages({
|
||||||
|
"string.empty": "This field is required.",
|
||||||
|
"string.uri": "The URL you provided is not valid.",
|
||||||
|
}),
|
||||||
name: joi.string().trim().max(50).allow("").messages({
|
name: joi.string().trim().max(50).allow("").messages({
|
||||||
"string.max": "*This field should not exceed the 50 characters limit.",
|
"string.max": "This field should not exceed the 50 characters limit.",
|
||||||
}),
|
}),
|
||||||
type: joi
|
type: joi
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.messages({ "string.empty": "*This field is required." }),
|
.messages({ "string.empty": "This field is required." }),
|
||||||
interval: joi.number().messages({
|
interval: joi.number().messages({
|
||||||
"number.base": "*Frequency must be a number.",
|
"number.base": "Frequency must be a number.",
|
||||||
"any.required": "*Frequency is required.",
|
"any.required": "Frequency is required.",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user