fix error bug, update page to use url
This commit is contained in:
1 parent
9a67348a83
commit
6e0bed589d
1 file changed
+16
-5
@@ -14,6 +14,7 @@ import { createToast } from "../../../Utils/toastUtils";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import { useStatusPageFetch } from "../Status/Hooks/useStatusPageFetch";
|
import { useStatusPageFetch } from "../Status/Hooks/useStatusPageFetch";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
//Constants
|
//Constants
|
||||||
const TAB_LIST = ["General settings", "Contents"];
|
const TAB_LIST = ["General settings", "Contents"];
|
||||||
@@ -24,16 +25,18 @@ const ERROR_TAB_MAPPING = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const CreateStatusPage = () => {
|
const CreateStatusPage = () => {
|
||||||
|
const { url } = useParams();
|
||||||
//Local state
|
//Local state
|
||||||
const [tab, setTab] = useState(0);
|
const [tab, setTab] = useState(0);
|
||||||
const [progress, setProgress] = useState({ value: 0, isLoading: false });
|
const [progress, setProgress] = useState({ value: 0, isLoading: false });
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
isPublished: false,
|
isPublished: false,
|
||||||
companyName: "",
|
companyName: "",
|
||||||
url: "/status/public",
|
url: url ?? Math.floor(Math.random() * 1000000).toFixed(0),
|
||||||
logo: undefined,
|
logo: undefined,
|
||||||
timezone: "America/Toronto",
|
timezone: "America/Toronto",
|
||||||
color: "#4169E1",
|
color: "#4169E1",
|
||||||
|
type: "uptime",
|
||||||
monitors: [],
|
monitors: [],
|
||||||
showCharts: true,
|
showCharts: true,
|
||||||
showUptimePercentage: true,
|
showUptimePercentage: true,
|
||||||
@@ -45,7 +48,7 @@ const CreateStatusPage = () => {
|
|||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isCreate = location.pathname === "/status/create";
|
const isCreate = location.pathname === "/status/uptime/create";
|
||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -53,8 +56,9 @@ const CreateStatusPage = () => {
|
|||||||
const [createStatusPage, createStatusIsLoading, createStatusPageNetworkError] =
|
const [createStatusPage, createStatusIsLoading, createStatusPageNetworkError] =
|
||||||
useCreateStatusPage(isCreate);
|
useCreateStatusPage(isCreate);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [statusPage, statusPageMonitors, statusPageIsLoading, statusPageNetworkError] =
|
const [statusPage, statusPageMonitors, statusPageIsLoading, statusPageNetworkError] =
|
||||||
useStatusPageFetch(isCreate);
|
useStatusPageFetch(isCreate, url);
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
const handleFormChange = (e) => {
|
const handleFormChange = (e) => {
|
||||||
@@ -131,7 +135,7 @@ const CreateStatusPage = () => {
|
|||||||
const success = await createStatusPage({ form });
|
const success = await createStatusPage({ form });
|
||||||
if (success) {
|
if (success) {
|
||||||
createToast({ body: "Status page created successfully" });
|
createToast({ body: "Status page created successfully" });
|
||||||
navigate("/status");
|
navigate(`/status/uptime/${form.url}`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -141,7 +145,6 @@ const CreateStatusPage = () => {
|
|||||||
newErrors[err.path[0]] = err.message;
|
newErrors[err.path[0]] = err.message;
|
||||||
});
|
});
|
||||||
setErrors((prev) => ({ ...prev, ...newErrors }));
|
setErrors((prev) => ({ ...prev, ...newErrors }));
|
||||||
|
|
||||||
const errorTabs = Object.keys(newErrors).map((err) => {
|
const errorTabs = Object.keys(newErrors).map((err) => {
|
||||||
return ERROR_TAB_MAPPING.findIndex((tab) => tab.includes(err));
|
return ERROR_TAB_MAPPING.findIndex((tab) => tab.includes(err));
|
||||||
});
|
});
|
||||||
@@ -150,6 +153,13 @@ const CreateStatusPage = () => {
|
|||||||
if (errorTabs.some((errorTab) => errorTab === tab)) {
|
if (errorTabs.some((errorTab) => errorTab === tab)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we get -1, there's an unknown error
|
||||||
|
if (errorTabs[0] === -1) {
|
||||||
|
createToast({ body: "Unknown error" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise go to tab with error
|
// Otherwise go to tab with error
|
||||||
setTab(errorTabs[0]);
|
setTab(errorTabs[0]);
|
||||||
};
|
};
|
||||||
@@ -218,6 +228,7 @@ const CreateStatusPage = () => {
|
|||||||
tab={tab}
|
tab={tab}
|
||||||
setTab={setTab}
|
setTab={setTab}
|
||||||
TAB_LIST={TAB_LIST}
|
TAB_LIST={TAB_LIST}
|
||||||
|
isCreate={isCreate}
|
||||||
/>
|
/>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
|||||||
Reference in new issue
Block a user