updated changes
This commit is contained in:
parent
cefe73d813
commit
ef84d106ec
|
@ -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",
|
||||
});
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = () => {
|
|||
<div className="mt-8">
|
||||
<div>
|
||||
<label htmlFor="email" className="text-lg font-medium">
|
||||
Email
|
||||
Username
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full border-2 border-gray-100 rounded-xl p-4 mt-1 bg-transparent"
|
||||
id="email"
|
||||
placeholder="Enter Your Email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
id="username"
|
||||
placeholder="Enter Your Username"
|
||||
value={username}
|
||||
onChange={(e) => setUsername (e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2">
|
||||
|
|
|
@ -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 (
|
||||
<div className="min-h-screen w-full bg-black text-white">
|
||||
<motion.div className="w-full">
|
||||
|
@ -78,31 +34,15 @@ const AdminDashboard = () => {
|
|||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<motion.div key={activeTab} className="p-8">
|
||||
{/* Hero Content */}
|
||||
{activeTab === "hero" && <Hero />}
|
||||
{/* Coach Content */}
|
||||
{activeTab === "coach" && (
|
||||
<Coach
|
||||
coaches={coaches}
|
||||
newCoach={newCoach}
|
||||
setNewCoach={setNewCoach}
|
||||
addCoach={addCoach}
|
||||
removeCoach={removeCoach}
|
||||
/>
|
||||
)}
|
||||
{activeTab === "coach" && <Coach />}
|
||||
|
||||
{/* Events Content */}
|
||||
{activeTab === "calendar" && (
|
||||
<Events
|
||||
events={events}
|
||||
newEvent={newEvent}
|
||||
setNewEvent={setNewEvent}
|
||||
addEvent={addEvent}
|
||||
/>
|
||||
)}
|
||||
{activeTab === "calendar" && <Events />}
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue