diff --git a/package-lock.json b/package-lock.json index 03357af..5564781 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "file-saver": "^2.0.5", "jspdf": "^3.0.3", "jspdf-autotable": "^5.0.2", + "lucide-react": "^0.545.0", "react": "^19.1.0", "react-chartjs-2": "^5.3.0", "react-dom": "^19.1.0", @@ -3571,6 +3572,15 @@ "dev": true, "license": "ISC" }, + "node_modules/lucide-react": { + "version": "0.545.0", + "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.545.0.tgz", + "integrity": "sha512-7r1/yUuflQDSt4f1bpn5ZAocyIxcTyVyBBChSVtBKn5M+392cPmI5YJMWOJKk/HUWGm5wg83chlAZtCcGbEZtw==", + "license": "ISC", + "peerDependencies": { + "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/magic-string": { "version": "0.30.17", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", diff --git a/package.json b/package.json index 302a8f6..a646710 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "file-saver": "^2.0.5", "jspdf": "^3.0.3", "jspdf-autotable": "^5.0.2", + "lucide-react": "^0.545.0", "react": "^19.1.0", "react-chartjs-2": "^5.3.0", "react-dom": "^19.1.0", diff --git a/src/assets/img/TaskSphereLogo.png b/src/assets/img/TaskSphereLogo.png new file mode 100644 index 0000000..a0d3be8 Binary files /dev/null and b/src/assets/img/TaskSphereLogo.png differ diff --git a/src/components/Signin.jsx b/src/components/Signin.jsx index 5888f72..8a150fd 100644 --- a/src/components/Signin.jsx +++ b/src/components/Signin.jsx @@ -1,10 +1,8 @@ -// src/components/Signin.jsx import React, { useState, useEffect } from "react"; import { useNavigate, useLocation, useOutletContext } from "react-router-dom"; import Swal from "sweetalert2"; -import "../components/Style/Style.css"; -import Logo1 from "../assets/img/Dct-Logo.png"; -import Logo2 from "../assets/img/Costum.png"; +import Logo1 from "../assets/img/TaskSphereLogo.png"; +import Logo2 from "../assets/img/Dct-Logo.png"; import { supabase } from "../supabaseClient"; import { UserAuth } from "../Contex/AuthContext"; import SigninHead from "./heade-foot/SigninHead"; @@ -20,13 +18,21 @@ const Signin = () => { const { setIsLoggedIn } = useOutletContext(); const { login } = UserAuth(); - // ===================================================== - // 🚫 Route Guard (Trap user inside /Signin) - // ===================================================== + // Hard lock page scroll (belt-and-suspenders) useEffect(() => { - const storedUser = localStorage.getItem("customUser"); + const prevDoc = document.documentElement.style.overflow; + const prevBody = document.body.style.overflow; + document.documentElement.style.overflow = "hidden"; + document.body.style.overflow = "hidden"; + return () => { + document.documentElement.style.overflow = prevDoc; + document.body.style.overflow = prevBody; + }; + }, []); - // 🔹 If user is logged in, redirect to their dashboard + // Route guard + useEffect(() => { + const storedUser = localStorage.getItem("customUser"); if (storedUser) { const user = JSON.parse(storedUser); const roleRoutes = { @@ -37,27 +43,16 @@ const Signin = () => { }; navigate(roleRoutes[user.user_roles] || "/Signin", { replace: true }); } else { - // 🔹 If user is not logged in, trap them inside /Signin - const allowedPaths = ["/", "/Signin", "/signin"]; - if (!allowedPaths.includes(location.pathname)) { - navigate("/Signin", { replace: true }); - } - - // Disable back/forward navigation + const allowed = ["/", "/Signin", "/signin"]; + if (!allowed.includes(location.pathname)) navigate("/Signin", { replace: true }); window.history.pushState(null, "", window.location.href); - window.onpopstate = () => { - window.history.pushState(null, "", window.location.href); - }; + window.onpopstate = () => window.history.pushState(null, "", window.location.href); } }, [location, navigate]); - // ===================================================== - // 🔹 Handle Sign In - // ===================================================== const handleSignIn = async (e) => { e.preventDefault(); setLoading(true); - try { const { data: user, error } = await supabase .from("user_credentials") @@ -67,27 +62,15 @@ const Signin = () => { .single(); if (error || !user) { - Swal.fire({ - icon: "error", - title: "Login failed", - text: "Invalid credentials. Please try again.", - }); + Swal.fire({ icon: "error", title: "Login failed", text: "Invalid credentials. Please try again." }); return; } - // ✅ Save to context + localStorage login(user); localStorage.setItem("customUser", JSON.stringify(user)); localStorage.setItem("user_id", user.user_id); setIsLoggedIn(true); - console.log("✅ User signed in:", { - user_id: user.user_id, - uuid: user.id, - role: user.user_roles, - }); - - // 🔹 Role-based navigation const roleRoutes = { 1: { path: "/Manager", label: "Manager" }, 2: { path: "/Member", label: "Member" }, @@ -106,107 +89,115 @@ const Signin = () => { }); navigate(target.path); } else { - Swal.fire({ - icon: "warning", - title: "Unknown role", - text: "Please contact the administrator.", - }); + Swal.fire({ icon: "warning", title: "Unknown role", text: "Please contact the administrator." }); } } catch (err) { - Swal.fire({ - icon: "error", - title: "Server Error", - text: "Something went wrong. Please try again later.", - }); + Swal.fire({ icon: "error", title: "Server Error", text: "Something went wrong. Please try again later." }); console.error("❌ SignIn Error:", err.message); } finally { setLoading(false); } }; + useEffect(() => { - const storedUser = localStorage.getItem("customUser"); - if (storedUser) { - const user = JSON.parse(storedUser); - const roleRoutes = { - 1: "/Manager/Dashboard", - 2: "/Member/Dashboard", - 3: "/Adviser/Dashboard", - 4: "/Instructor/Dashboard", - }; - navigate(roleRoutes[user.user_roles] || "/Signin", { replace: true }); - } -}, []); + const storedUser = localStorage.getItem("customUser"); + if (storedUser) { + const user = JSON.parse(storedUser); + const roleRoutes = { + 1: "/Manager/Dashboard", + 2: "/Member/Dashboard", + 3: "/Adviser/Dashboard", + 4: "/Instructor/Dashboard", + }; + navigate(roleRoutes[user.user_roles] || "/Signin", { replace: true }); + } + }, [navigate]); - // ===================================================== - // 🔹 UI - // ===================================================== return ( -