Update Button to show Checking endpoint during the endpoint checking process in Create Monitor as well as PageSpeed

This commit is contained in:
om-3004
2024-10-17 13:00:11 +05:30
parent aee7e02587
commit 8819b0ab78
2 changed files with 10 additions and 2 deletions
@@ -43,6 +43,7 @@ const CreateMonitor = () => {
});
const [https, setHttps] = useState(true);
const [errors, setErrors] = useState({});
const [isCheckingEndpoint, setIsCheckingEndpoint] = useState(false);
useEffect(() => {
const fetchMonitor = async () => {
@@ -125,6 +126,7 @@ const CreateMonitor = () => {
const handleCreateMonitor = async (event) => {
event.preventDefault();
setIsCheckingEndpoint(true);
//obj to submit
let form = {
url:
@@ -156,8 +158,10 @@ const CreateMonitor = () => {
if (checkEndpointAction.meta.requestStatus === "rejected") {
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
setErrors({ url: "The entered URL is not reachable." });
setIsCheckingEndpoint(false);
return;
}
setIsCheckingEndpoint(false);
}
form = {
@@ -387,7 +391,7 @@ const CreateMonitor = () => {
onClick={handleCreateMonitor}
disabled={Object.keys(errors).length !== 0 && true}
>
Create monitor
{ isCheckingEndpoint ? "Checking endpoint" : "Create monitor" }
</Button>
</Stack>
</Stack>
@@ -40,6 +40,7 @@ const CreatePageSpeed = () => {
});
const [https, setHttps] = useState(true);
const [errors, setErrors] = useState({});
const [isCheckingEndpoint, setIsCheckingEndpoint] = useState(false);
const handleChange = (event, name) => {
const { value, id } = event.target;
@@ -92,6 +93,7 @@ const CreatePageSpeed = () => {
const handleCreateMonitor = async (event) => {
event.preventDefault();
setIsCheckingEndpoint(true);
//obj to submit
let form = {
url: `http${https ? "s" : ""}://` + monitor.url,
@@ -118,8 +120,10 @@ const CreatePageSpeed = () => {
if (checkEndpointAction.meta.requestStatus === "rejected") {
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
setErrors({ url: "The entered URL is not reachable." });
setIsCheckingEndpoint(false);
return;
}
setIsCheckingEndpoint(false);
form = {
...form,
@@ -343,7 +347,7 @@ const CreatePageSpeed = () => {
onClick={handleCreateMonitor}
disabled={Object.keys(errors).length !== 0 && true}
>
Create monitor
{ isCheckingEndpoint ? "Checking endpoint" : "Create monitor" }
</Button>
</Stack>
</Stack>