- | {order.id} |
-
- {order.customer}
- |
- {order.amount} |
-
-
- {order.status}
+
+ {recentOrders.map((o) => (
+
+ | {o.id} |
+ {o.customer} |
+ {o.amount} |
+
+
+ {o.status}
|
- {order.date} |
))}
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 953821a..9b54840 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -1,56 +1,51 @@
-// src/App.jsx - PERFECT: ANY USER=LandingPage | ANY ADMIN=HomeAdmin
+// src/App.jsx
import { Routes, Route, Navigate } from "react-router-dom";
+import { useAuth } from "./utils/auth";
+
+/* Pages */
import LandingPage from "./Pages/LandingPage";
-import Login from "./Authentication/Login";
-import Signup from "./Authentication/Signup";
import ProductsPage from "./Pages/ProductsPage";
import ProductDetails from "./Pages/ProductsDetails";
import Cart from "./Pages/Cart";
import AboutUs from "./Pages/About";
import Contact from "./Pages/Contact";
-import HomeAdmin from "./Admin/HomeAdmin";
-import ProtectedRoute from "./ProtectedRoutes/ProtectedRote";
-import Settings from "./Profile/ProfileSettings";
+
+/* Auth Pages */
+import Login from "./Authentication/Login";
+import SignupUser from "./Authentication/SignupUser";
+import SignupAdmin from "./Authentication/SignupAdmin";
+
+/* Profile */
import Profile from "./Profile/Profile";
+import Settings from "./Profile/ProfileSettings";
+
+/* Admin */
+import HomeAdmin from "./Admin/HomeAdmin";
+
+/* Components */
import Navbar from "./reusableComponents/Navbar";
-import { useAuth } from "./utils/auth";
+import AdminNavbar from "./reusableComponents/AdminNavbar";
+import ProtectedRoute from "./ProtectedRoutes/ProtectedRote";
+/* Loading Spinner */
function LoadingSpinner() {
return (
);
}
-// ✅ PERFECT LOGIC: role="user" → LandingPage | role="admin" → HomeAdmin
+/* =======================
+ HOME PAGE LOGIC
+======================= */
function HomePage() {
const { user, loading } = useAuth();
- console.log("🎯 HomePage:", {
- userId: user?.id,
- role: user?.role,
- isUser: user?.role === "user",
- isAdmin: user?.role === "admin",
- loading
- });
-
if (loading) return ;
- // ✅ GUEST → LandingPage
- if (!user) {
- console.log("✅ GUEST → LANDING PAGE");
- return (
- <>
-
-
- >
- );
- }
-
- // ✅ ANY USER (role="user") → LANDING PAGE
- if (user.role === "user") {
- console.log("✅ USER (", user.id, ") → LANDING PAGE");
+ // 👤 Guest or User → Public Navbar + Landing
+ if (!user || user.role === "user") {
return (
<>
@@ -59,45 +54,100 @@ function HomePage() {
);
}
- // ✅ ANY ADMIN (role="admin") → HOMEADMIN
+ // 👑 Admin → Admin Navbar + Admin Home
if (user.role === "admin") {
- console.log("✅ ADMIN (", user.id, ") → HOMEADMIN");
return (
<>
-
+
>
);
}
- // ✅ FALLBACK → LANDING PAGE
- console.log("✅ FALLBACK → LANDING PAGE");
- return (
- <>
-
-
- >
- );
+ return ;
}
+/* =======================
+ APP ROUTES
+======================= */
export default function App() {
return (
+ {/* 🌍 PUBLIC ROUTES */}
} />
- } />
- } />
+ } />
+ } />
} />
} />
-
- } />
- } />
- } />
-
- } />
-
- } />
- } />
-
+
+ {/* 🔐 AUTH ROUTES */}
+ } />
+ } />
+ } />
+
+ {/* 👤 USER PROTECTED ROUTES */}
+
+ <>
+
+
+ >
+
+ }
+ />
+
+
+ <>
+
+
+ >
+
+ }
+ />
+
+
+ <>
+
+
+ >
+
+ }
+ />
+
+ {/* 👑 ADMIN PROTECTED ROUTES */}
+
+ <>
+
+
+ >
+
+ }
+ />
+
+
+ <>
+
+
+ >
+
+ }
+ />
+
+ {/* ❌ FALLBACK */}
} />
);
diff --git a/frontend/src/Authentication/Login.jsx b/frontend/src/Authentication/Login.jsx
index ef39d0c..25e208d 100644
--- a/frontend/src/Authentication/Login.jsx
+++ b/frontend/src/Authentication/Login.jsx
@@ -1,174 +1,148 @@
-// src/Authentication/Login.jsx - FULL WORKING CODE
import React, { useState, useEffect } from "react";
-import { useNavigate, Link, useLocation } from "react-router-dom";
-import Input from "../reusableComponents/Input";
+import { Link, useNavigate, useLocation } from "react-router-dom";
import { loginUser } from "../Services/authService";
import { useAuth } from "../utils/auth";
export default function Login() {
const [form, setForm] = useState({ identifier: "", password: "" });
- const [errors, setErrors] = useState({});
- const [isSubmitting, setIsSubmitting] = useState(false);
+ const [error, setError] = useState("");
+ const [loading, setLoading] = useState(false);
+
const navigate = useNavigate();
const location = useLocation();
const { login, user } = useAuth();
- // ✅ AUTO REDIRECT if already logged in
+ // Auto redirect if already logged in
useEffect(() => {
if (user) {
- console.log("🔄 AUTO REDIRECT - Already logged in:", user.id, user.role);
- navigate("/", { replace: true });
+ navigate(user.role === "admin" ? "/admin/home" : "/", { replace: true });
}
}, [user, navigate]);
+ const handleChange = (e) => {
+ setForm({ ...form, [e.target.name]: e.target.value });
+ setError("");
+ };
+
const handleSubmit = async (e) => {
e.preventDefault();
- setErrors({});
-
- if (!form.identifier.trim() || !form.password.trim()) {
- setErrors({ general: "Please fill all fields" });
- return;
- }
+ setLoading(true);
- setIsSubmitting(true);
-
try {
- console.log("🔍 LOGIN API CALL...");
- const response = await loginUser(form);
- console.log("🔍 LOGIN RESPONSE:", response.data);
-
- const token = response.data.tokens.access;
-
- // ✅ STORE BACKEND ROLE + USER INFO (CRITICAL!)
- localStorage.setItem('userRole', response.data.role);
- localStorage.setItem('username', response.data.username);
- localStorage.setItem('fullname', response.data.fullname);
-
- console.log("💾 STORED ROLE:", response.data.role);
-
- // ✅ Trigger AuthProvider
- login(token);
-
- // ✅ Wait for state update then redirect
- setTimeout(() => {
- console.log("✅ LOGIN COMPLETE - Redirecting...");
- navigate("/", { replace: true });
- }, 100);
-
- } catch (error) {
- console.error("❌ LOGIN ERROR:", error.response?.data);
- setErrors({
- general: error.response?.data?.error ||
- error.response?.data?.detail ||
- "Login failed. Please try again."
- });
+ const res = await loginUser(form);
+ login(res.data.tokens.access);
+
+ navigate(
+ res.data.role === "admin" ? "/admin/home" : "/",
+ { replace: true }
+ );
+ } catch (err) {
+ setError(
+ err.response?.data?.error ||
+ err.response?.data?.detail ||
+ "Invalid credentials"
+ );
} finally {
- setIsSubmitting(false);
+ setLoading(false);
}
};
- const handleInputChange = (e) => {
- const { name, value } = e.target;
- setForm(prev => ({ ...prev, [name]: value }));
- if (errors[name]) setErrors(prev => ({ ...prev, [name]: '' }));
- };
-
return (
-
-
- {/* Header */}
+
+
+ {/* CARD */}
+
+
+ {/* LOGO / TITLE */}
-
-
+
+ S
-
- Welcome Back
+
+ Sign in to ShopEase
- Sign in to your account
+
+ Welcome back, please login
+
- {/* Success Message */}
+ {/* SUCCESS MESSAGE */}
{location.state?.message && (
-
+
{location.state.message}
)}
- {/* Form */}
-
- {/* Footer */}
-
-
- Don't have an account?
-
- Sign up here
-
-
-
- Forgot password?
-
- Reset now
-
-
+ {/* FOOTER */}
+
+ Don’t have an account?
+
+ Create account
+
diff --git a/frontend/src/Authentication/Signup.jsx b/frontend/src/Authentication/Signup.jsx
index a58aa00..3507ebb 100644
--- a/frontend/src/Authentication/Signup.jsx
+++ b/frontend/src/Authentication/Signup.jsx
@@ -1,8 +1,7 @@
-// src/Authentication/Signup.jsx - FULL PRODUCTION READY
import React, { useState } from "react";
import { useNavigate, Link, useLocation } from "react-router-dom";
import Input from "../reusableComponents/Input";
-import { registerUser, registerAdmin } from "../Services/authService";
+import { registerUser } from "../Services/authService";
export default function Signup() {
const [form, setForm] = useState({
@@ -10,20 +9,17 @@ export default function Signup() {
});
const [errors, setErrors] = useState({});
const [isSubmitting, setIsSubmitting] = useState(false);
- const [registeringAs, setRegisteringAs] = useState("user");
const navigate = useNavigate();
const location = useLocation();
const validateForm = () => {
const newErrors = {};
-
if (!form.fullname.trim()) newErrors.fullname = "Full name is required";
if (!form.username.trim()) newErrors.username = "Username is required";
if (!form.email.trim()) newErrors.email = "Email is required";
if (!form.mobile.trim()) newErrors.mobile = "Mobile number is required";
if (form.password.length < 6) newErrors.password = "Password must be at least 6 characters";
if (form.password !== form.confirm_password) newErrors.confirm_password = "Passwords don't match";
-
setErrors(newErrors);
return Object.keys(newErrors).length === 0;
};
@@ -31,32 +27,14 @@ export default function Signup() {
const handleSubmit = async (e) => {
e.preventDefault();
if (!validateForm()) return;
-
setIsSubmitting(true);
setErrors({});
-
try {
- console.log(`🔍 REGISTER ${registeringAs.toUpperCase()}...`);
-
- if (registeringAs === "admin") {
- await registerAdmin(form);
- } else {
- await registerUser(form);
- }
-
- console.log(`✅ ${registeringAs.toUpperCase()} REGISTERED!`);
- navigate("/login", {
- state: {
- message: `${registeringAs.charAt(0).toUpperCase() + registeringAs.slice(1)} account created successfully! Please login.`
- }
- });
-
+ await registerUser(form);
+ navigate("/login", { state: { message: "User account created successfully! Please login." } });
} catch (error) {
- console.error("❌ REGISTRATION ERROR:", error.response?.data);
setErrors({
- general: error.response?.data?.detail ||
- error.response?.data?.error ||
- "Registration failed. Please try again."
+ general: error.response?.data?.detail || error.response?.data?.error || "Registration failed. Please try again."
});
} finally {
setIsSubmitting(false);
@@ -71,173 +49,62 @@ export default function Signup() {
return (
-
+
+
{/* Header */}
-
-
- |