diff --git a/src/components/Coach.jsx b/src/components/Coach.jsx index d9a7650..c5eaed5 100644 --- a/src/components/Coach.jsx +++ b/src/components/Coach.jsx @@ -8,11 +8,16 @@ const Coach = () => { const [message, setMessage] = useState(""); const [editingId, setEditingId] = useState(null); + const API_BASE_URL = import.meta.env.VITE_API_BASE_URL + + const DEBUG = false; + // Fetch coaches const fetchCoaches = async () => { try { - const response = await fetch("http://localhost:9999/api/coach"); + const response = await fetch(API_BASE_URL+"/coach"); const data = await response.json(); + DEBUG && console.log(`fetchCoaches.response`,response); if (response.ok) { setCoaches(data.data); } else { @@ -35,7 +40,7 @@ const Coach = () => { } try { - const response = await fetch("http://localhost:9999/api/coach", { + const response = await fetch(`${API_BASE_URL}/coach`, { method: "POST", headers: { "Content-Type": "application/json", @@ -66,11 +71,11 @@ const Coach = () => { } try { const response = await fetch( - `http://localhost:9999/api/coach/${editingId}`, + `${API_BASE_URL}/coach/${editingId}`, { method: "PUT", headers: { - "Content-Type": "application/json", + "Content-Type": "application/json", }, body: JSON.stringify({ name, title }), } @@ -106,7 +111,7 @@ const Coach = () => { // Delete coach const removeCoach = async (id) => { try { - const response = await fetch(`http://localhost:9999/api/coach/${id}`, { + const response = await fetch(`${API_BASE_URL}/coach/${id}`, { method: "DELETE", }); diff --git a/src/components/Events.jsx b/src/components/Events.jsx index b11b60f..2ff7fc5 100644 --- a/src/components/Events.jsx +++ b/src/components/Events.jsx @@ -8,10 +8,12 @@ const Events = () => { const [errorMessage, setErrorMessage] = useState(""); const [editId, setEditId] = useState(null); + const API_BASE_URL = import.meta.env.VITE_API_BASE_URL + // Fetch events const fetchEvents = async () => { try { - const response = await axios.get("http://localhost:9999/api/event"); + const response = await axios.get(`${API_BASE_URL}/event`); setEvents(response.data.data); } catch (error) { console.error("Error fetching events:", error); @@ -33,7 +35,7 @@ const Events = () => { if (!validateForm()) return; try { const isoDate = new Date(form.date).toISOString(); - const response = await axios.post("http://localhost:9999/api/event", { + const response = await axios.post(`${API_BASE_URL}/event`, { ...form, date: isoDate, }); @@ -48,7 +50,7 @@ const Events = () => { // Delete an event const deleteEvent = async (id) => { try { - await axios.delete(`http://localhost:9999/api/event/${id}`); + await axios.delete(`${API_BASE_URL}/event/${id}`); setEvents((prev) => prev.filter((event) => event.id !== id)); toast.success("Event deleted successfully!"); } catch (error) { @@ -62,7 +64,7 @@ const Events = () => { try { const isoDate = new Date(form.date).toISOString(); const response = await axios.put( - `http://localhost:9999/api/event/${editId}`, + `${API_BASE_URL}/event/${editId}`, { ...form, date: isoDate, diff --git a/src/components/LoginForm.jsx b/src/components/LoginForm.jsx index d75f8cd..d2b8d14 100644 --- a/src/components/LoginForm.jsx +++ b/src/components/LoginForm.jsx @@ -3,7 +3,7 @@ import { toast } from "react-toastify"; import { useNavigate } from "react-router-dom"; const LoginForm = () => { - const [email, setEmail] = useState(""); + const [username,setUsername ] = useState(""); const [password, setPassword] = useState(""); const navigate = useNavigate(); @@ -11,7 +11,7 @@ const LoginForm = () => { const validEmail = "test"; const validPassword = "test@123"; - if (email === validEmail && password === validPassword) { + if (username === validEmail && password === validPassword) { toast.success("Login successful!"); navigate("/dashboard"); } else { @@ -28,15 +28,15 @@ const LoginForm = () => {
setEmail(e.target.value)} + id="username" + placeholder="Enter Your Username" + value={username} + onChange={(e) => setUsername (e.target.value)} />
diff --git a/src/pages/AdminDashboard.jsx b/src/pages/AdminDashboard.jsx index 5af74ca..6c23566 100644 --- a/src/pages/AdminDashboard.jsx +++ b/src/pages/AdminDashboard.jsx @@ -7,50 +7,6 @@ import Events from "../components/Events"; const AdminDashboard = () => { const [activeTab, setActiveTab] = useState("hero"); - // Coach state - const [coaches, setCoaches] = useState([ - { name: "John Doe", title: "Head Coach" }, - { name: "Jane Smith", title: "Assistant Coach" }, - ]); - const [newCoach, setNewCoach] = useState({ name: "", title: "" }); - - const addCoach = () => { - if (newCoach.name && newCoach.title) { - setCoaches([...coaches, newCoach]); - setNewCoach({ name: "", title: "" }); - } - }; - - const removeCoach = (index) => { - setCoaches(coaches.filter((_, i) => i !== index)); - }; - - // Event state - const [events, setEvents] = useState([ - { - title: "Team Meeting", - date: "2025-02-01", - description: "Monthly meeting.", - }, - { - title: "Workshop", - date: "2025-02-05", - description: "Training workshop.", - }, - ]); - const [newEvent, setNewEvent] = useState({ - title: "", - date: "", - description: "", - }); - - const addEvent = () => { - if (newEvent.title && newEvent.date && newEvent.description) { - setEvents([...events, newEvent]); - setNewEvent({ title: "", date: "", description: "" }); - } - }; - return (
@@ -78,31 +34,15 @@ const AdminDashboard = () => { ))}
- {/* Tab Content */} {/* Hero Content */} {activeTab === "hero" && } {/* Coach Content */} - {activeTab === "coach" && ( - - )} + {activeTab === "coach" && } {/* Events Content */} - {activeTab === "calendar" && ( - - )} + {activeTab === "calendar" && }