updated changes

This commit is contained in:
bhavnish.arora 2025-01-29 17:43:19 +05:30
parent cefe73d813
commit ef84d106ec
4 changed files with 25 additions and 78 deletions

View file

@ -8,11 +8,16 @@ const Coach = () => {
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const [editingId, setEditingId] = useState(null); const [editingId, setEditingId] = useState(null);
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
const DEBUG = false;
// Fetch coaches // Fetch coaches
const fetchCoaches = async () => { const fetchCoaches = async () => {
try { try {
const response = await fetch("http://localhost:9999/api/coach"); const response = await fetch(API_BASE_URL+"/coach");
const data = await response.json(); const data = await response.json();
DEBUG && console.log(`fetchCoaches.response`,response);
if (response.ok) { if (response.ok) {
setCoaches(data.data); setCoaches(data.data);
} else { } else {
@ -35,7 +40,7 @@ const Coach = () => {
} }
try { try {
const response = await fetch("http://localhost:9999/api/coach", { const response = await fetch(`${API_BASE_URL}/coach`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -66,11 +71,11 @@ const Coach = () => {
} }
try { try {
const response = await fetch( const response = await fetch(
`http://localhost:9999/api/coach/${editingId}`, `${API_BASE_URL}/coach/${editingId}`,
{ {
method: "PUT", method: "PUT",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ name, title }), body: JSON.stringify({ name, title }),
} }
@ -106,7 +111,7 @@ const Coach = () => {
// Delete coach // Delete coach
const removeCoach = async (id) => { const removeCoach = async (id) => {
try { try {
const response = await fetch(`http://localhost:9999/api/coach/${id}`, { const response = await fetch(`${API_BASE_URL}/coach/${id}`, {
method: "DELETE", method: "DELETE",
}); });

View file

@ -8,10 +8,12 @@ const Events = () => {
const [errorMessage, setErrorMessage] = useState(""); const [errorMessage, setErrorMessage] = useState("");
const [editId, setEditId] = useState(null); const [editId, setEditId] = useState(null);
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
// Fetch events // Fetch events
const fetchEvents = async () => { const fetchEvents = async () => {
try { try {
const response = await axios.get("http://localhost:9999/api/event"); const response = await axios.get(`${API_BASE_URL}/event`);
setEvents(response.data.data); setEvents(response.data.data);
} catch (error) { } catch (error) {
console.error("Error fetching events:", error); console.error("Error fetching events:", error);
@ -33,7 +35,7 @@ const Events = () => {
if (!validateForm()) return; if (!validateForm()) return;
try { try {
const isoDate = new Date(form.date).toISOString(); 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, ...form,
date: isoDate, date: isoDate,
}); });
@ -48,7 +50,7 @@ const Events = () => {
// Delete an event // Delete an event
const deleteEvent = async (id) => { const deleteEvent = async (id) => {
try { 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)); setEvents((prev) => prev.filter((event) => event.id !== id));
toast.success("Event deleted successfully!"); toast.success("Event deleted successfully!");
} catch (error) { } catch (error) {
@ -62,7 +64,7 @@ const Events = () => {
try { try {
const isoDate = new Date(form.date).toISOString(); const isoDate = new Date(form.date).toISOString();
const response = await axios.put( const response = await axios.put(
`http://localhost:9999/api/event/${editId}`, `${API_BASE_URL}/event/${editId}`,
{ {
...form, ...form,
date: isoDate, date: isoDate,

View file

@ -3,7 +3,7 @@ import { toast } from "react-toastify";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
const LoginForm = () => { const LoginForm = () => {
const [email, setEmail] = useState(""); const [username,setUsername ] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const navigate = useNavigate(); const navigate = useNavigate();
@ -11,7 +11,7 @@ const LoginForm = () => {
const validEmail = "test"; const validEmail = "test";
const validPassword = "test@123"; const validPassword = "test@123";
if (email === validEmail && password === validPassword) { if (username === validEmail && password === validPassword) {
toast.success("Login successful!"); toast.success("Login successful!");
navigate("/dashboard"); navigate("/dashboard");
} else { } else {
@ -28,15 +28,15 @@ const LoginForm = () => {
<div className="mt-8"> <div className="mt-8">
<div> <div>
<label htmlFor="email" className="text-lg font-medium"> <label htmlFor="email" className="text-lg font-medium">
Email Username
</label> </label>
<input <input
type="text" type="text"
className="w-full border-2 border-gray-100 rounded-xl p-4 mt-1 bg-transparent" className="w-full border-2 border-gray-100 rounded-xl p-4 mt-1 bg-transparent"
id="email" id="username"
placeholder="Enter Your Email" placeholder="Enter Your Username"
value={email} value={username}
onChange={(e) => setEmail(e.target.value)} onChange={(e) => setUsername (e.target.value)}
/> />
</div> </div>
<div className="mt-2"> <div className="mt-2">

View file

@ -7,50 +7,6 @@ import Events from "../components/Events";
const AdminDashboard = () => { const AdminDashboard = () => {
const [activeTab, setActiveTab] = useState("hero"); 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 ( return (
<div className="min-h-screen w-full bg-black text-white"> <div className="min-h-screen w-full bg-black text-white">
<motion.div className="w-full"> <motion.div className="w-full">
@ -78,31 +34,15 @@ const AdminDashboard = () => {
</button> </button>
))} ))}
</div> </div>
{/* Tab Content */} {/* Tab Content */}
<motion.div key={activeTab} className="p-8"> <motion.div key={activeTab} className="p-8">
{/* Hero Content */} {/* Hero Content */}
{activeTab === "hero" && <Hero />} {activeTab === "hero" && <Hero />}
{/* Coach Content */} {/* Coach Content */}
{activeTab === "coach" && ( {activeTab === "coach" && <Coach />}
<Coach
coaches={coaches}
newCoach={newCoach}
setNewCoach={setNewCoach}
addCoach={addCoach}
removeCoach={removeCoach}
/>
)}
{/* Events Content */} {/* Events Content */}
{activeTab === "calendar" && ( {activeTab === "calendar" && <Events />}
<Events
events={events}
newEvent={newEvent}
setNewEvent={setNewEvent}
addEvent={addEvent}
/>
)}
</motion.div> </motion.div>
</motion.div> </motion.div>
</div> </div>