@@ -124,6 +128,7 @@ function Footer() {
type="submit"
onClick={handleSubmit}
className="tw-w-full md:tw-w-max"
+ loading={isLoading}
/>
)}
diff --git a/components/mentorDashboard/ListedSessionComponent/AddForm.js b/components/mentorDashboard/ListedSessionComponent/AddForm.js
index 31efd3b1..d4767e06 100644
--- a/components/mentorDashboard/ListedSessionComponent/AddForm.js
+++ b/components/mentorDashboard/ListedSessionComponent/AddForm.js
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import axios from "axios";
import { toast } from "react-toastify";
import { Button } from "../../UI";
@@ -11,16 +11,17 @@ const AddSessionComponent = ({ setSessions, setAddSession }) => {
duration: "",
price: "",
};
+ const [isLoading, setIsLoading] = useState(false);
const [data, setData] = useState(initialData);
// on submit funxtion for add form
const handleSubmit = async (e) => {
e.preventDefault();
try {
+ setIsLoading(true);
const url = `${process.env.NEXT_PUBLIC_BACKEND_URL}/api/mentors/addListedSession`;
const response = await axios.put(url, data, { withCredentials: true });
-
- if (!response.data.session) {
+ if (!response.data.sessions) {
// Handle null session here
toast.error("Session creation failed. Please check your input.");
} else {
@@ -28,7 +29,9 @@ const AddSessionComponent = ({ setSessions, setAddSession }) => {
setAddSession(false);
toast.success("New Session added successfully.");
}
+ setIsLoading(false);
} catch (error) {
+ setIsLoading(false);
if (
error.response &&
error.response.status >= 400 &&
@@ -50,6 +53,8 @@ const AddSessionComponent = ({ setSessions, setAddSession }) => {
}));
};
+ useEffect(()=>{}, [isLoading])
+
return (
<>
@@ -193,7 +198,7 @@ const AddSessionComponent = ({ setSessions, setAddSession }) => {
}}
/>
-
+
diff --git a/components/mentorDashboard/ListedSessionComponent/EditForm.js b/components/mentorDashboard/ListedSessionComponent/EditForm.js
index 1f1f8f75..530f6418 100644
--- a/components/mentorDashboard/ListedSessionComponent/EditForm.js
+++ b/components/mentorDashboard/ListedSessionComponent/EditForm.js
@@ -8,7 +8,7 @@ const EditSessionComponent = ({ sessionID, setSessionID, setSessions }) => {
const [data, setData] = useState(null);
const mentorData = JSON.parse(localStorage.getItem("mentorData"));
const username = mentorData?.mentor_username;
-
+ const [isLoading, setIsLoading] = useState(false);
// fetching session on load
useEffect(() => {
// Fetch session data only if data hasn't been fetched yet
@@ -31,12 +31,15 @@ const EditSessionComponent = ({ sessionID, setSessionID, setSessions }) => {
const handleSubmit = async (e) => {
e.preventDefault();
try {
+ setIsLoading(true);
const url = `${process.env.NEXT_PUBLIC_BACKEND_URL}/api/mentors/updateListedSession`;
const response = await axios.put(url, data, { withCredentials: true });
setSessions(response.data.updatedSessions);
setSessionID(null);
+ setIsLoading(false);
toast.success("Changes saved successfully.");
} catch (error) {
+ setIsLoading(false);
if (
error.response &&
error.response.status >= 400 &&
@@ -206,6 +209,7 @@ const EditSessionComponent = ({ sessionID, setSessionID, setSessions }) => {
text="Save Changes"
type="submit"
onClick={handleSubmit}
+ loading={isLoading}
/>