Add loading button while the url is getting resolved
This commit is contained in:
1 parent
9de2dfe514
commit
6c40500153
2 files changed
+12
-15
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
||||||
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createUptimeMonitor } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { createUptimeMonitor } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
@@ -20,7 +21,7 @@ import "./index.css";
|
|||||||
const CreateMonitor = () => {
|
const CreateMonitor = () => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const { monitors } = useSelector((state) => state.uptimeMonitors);
|
const { monitors, isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -43,7 +44,6 @@ const CreateMonitor = () => {
|
|||||||
});
|
});
|
||||||
const [https, setHttps] = useState(true);
|
const [https, setHttps] = useState(true);
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const [isCheckingEndpoint, setIsCheckingEndpoint] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
@@ -126,7 +126,6 @@ const CreateMonitor = () => {
|
|||||||
|
|
||||||
const handleCreateMonitor = async (event) => {
|
const handleCreateMonitor = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setIsCheckingEndpoint(true);
|
|
||||||
//obj to submit
|
//obj to submit
|
||||||
let form = {
|
let form = {
|
||||||
url:
|
url:
|
||||||
@@ -158,10 +157,8 @@ const CreateMonitor = () => {
|
|||||||
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
||||||
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
||||||
setErrors({ url: "The entered URL is not reachable." });
|
setErrors({ url: "The entered URL is not reachable." });
|
||||||
setIsCheckingEndpoint(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsCheckingEndpoint(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
@@ -385,14 +382,15 @@ const CreateMonitor = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
<Stack direction="row" justifyContent="flex-end">
|
<Stack direction="row" justifyContent="flex-end">
|
||||||
<Button
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={handleCreateMonitor}
|
onClick={handleCreateMonitor}
|
||||||
disabled={Object.keys(errors).length !== 0 && true}
|
disabled={Object.keys(errors).length !== 0 && true}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
{ isCheckingEndpoint ? "Checking endpoint" : "Create monitor" }
|
Create monitor
|
||||||
</Button>
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
||||||
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
@@ -19,6 +20,7 @@ import "./index.css";
|
|||||||
const CreatePageSpeed = () => {
|
const CreatePageSpeed = () => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
|
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -40,7 +42,6 @@ const CreatePageSpeed = () => {
|
|||||||
});
|
});
|
||||||
const [https, setHttps] = useState(true);
|
const [https, setHttps] = useState(true);
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const [isCheckingEndpoint, setIsCheckingEndpoint] = useState(false);
|
|
||||||
|
|
||||||
const handleChange = (event, name) => {
|
const handleChange = (event, name) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
@@ -93,7 +94,6 @@ const CreatePageSpeed = () => {
|
|||||||
|
|
||||||
const handleCreateMonitor = async (event) => {
|
const handleCreateMonitor = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setIsCheckingEndpoint(true);
|
|
||||||
//obj to submit
|
//obj to submit
|
||||||
let form = {
|
let form = {
|
||||||
url: `http${https ? "s" : ""}://` + monitor.url,
|
url: `http${https ? "s" : ""}://` + monitor.url,
|
||||||
@@ -120,10 +120,8 @@ const CreatePageSpeed = () => {
|
|||||||
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
||||||
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
||||||
setErrors({ url: "The entered URL is not reachable." });
|
setErrors({ url: "The entered URL is not reachable." });
|
||||||
setIsCheckingEndpoint(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsCheckingEndpoint(false);
|
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
...form,
|
...form,
|
||||||
@@ -341,14 +339,15 @@ const CreatePageSpeed = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
<Stack direction="row" justifyContent="flex-end">
|
<Stack direction="row" justifyContent="flex-end">
|
||||||
<Button
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={handleCreateMonitor}
|
onClick={handleCreateMonitor}
|
||||||
disabled={Object.keys(errors).length !== 0 && true}
|
disabled={Object.keys(errors).length !== 0 && true}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
{ isCheckingEndpoint ? "Checking endpoint" : "Create monitor" }
|
Create monitor
|
||||||
</Button>
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in new issue
Block a user