created different file for the routes, and changes all the import
This commit is contained in:
parent
73b31778db
commit
45444ba8bd
@ -20,6 +20,7 @@ import {
|
|||||||
XCircle,
|
XCircle,
|
||||||
Wallet,
|
Wallet,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
import { ROUTES } from "@/lib/routes";
|
||||||
|
|
||||||
export default function EmployeePage() {
|
export default function EmployeePage() {
|
||||||
const { user, logout, isLoading } = useAuth();
|
const { user, logout, isLoading } = useAuth();
|
||||||
@ -41,8 +42,10 @@ export default function EmployeePage() {
|
|||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading && !user) router.replace("/");
|
// if (!isLoading && !user) router.replace("/");
|
||||||
else if (!isLoading && user?.role === "manager") router.replace("/manager");
|
// else if (!isLoading && user?.role === "manager") router.replace("/manager");
|
||||||
|
if (!isLoading && !user) router.replace(ROUTES.home);
|
||||||
|
else if (!isLoading && user?.role === "manager") router.replace(ROUTES.manager);
|
||||||
else if (!isLoading && user) loadData();
|
else if (!isLoading && user) loadData();
|
||||||
}, [user, isLoading, router, loadData]);
|
}, [user, isLoading, router, loadData]);
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import {
|
|||||||
XCircle,
|
XCircle,
|
||||||
LayoutDashboard,
|
LayoutDashboard,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
import { ROUTES } from "@/lib/routes";
|
||||||
|
|
||||||
type FilterStatus = "All" | "Pending" | "Approved" | "Rejected";
|
type FilterStatus = "All" | "Pending" | "Approved" | "Rejected";
|
||||||
|
|
||||||
@ -32,8 +33,10 @@ export default function ManagerPage() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading && !user) router.replace("/");
|
// if (!isLoading && !user) router.replace("/");
|
||||||
else if (!isLoading && user?.role === "employee") router.replace("/employee");
|
// else if (!isLoading && user?.role === "employee") router.replace("/employee");
|
||||||
|
if (!isLoading && !user) router.replace(ROUTES.home);
|
||||||
|
else if (!isLoading && user?.role === "employee") router.replace(ROUTES.employee);
|
||||||
else if (!isLoading && user) loadData();
|
else if (!isLoading && user) loadData();
|
||||||
}, [user, isLoading, router, loadData]);
|
}, [user, isLoading, router, loadData]);
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { Label } from "@/components/ui/label";
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
import { CalendarDays, AlertCircle, Loader2 } from "lucide-react";
|
import { CalendarDays, AlertCircle, Loader2 } from "lucide-react";
|
||||||
|
import { ROUTES } from "@/lib/routes";
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const { login, user, isLoading } = useAuth();
|
const { login, user, isLoading } = useAuth();
|
||||||
@ -20,7 +21,8 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading && user) {
|
if (!isLoading && user) {
|
||||||
router.replace(user.role === "manager" ? "/manager" : "/employee");
|
// router.replace(user.role === "manager" ? "/manager" : "/employee");
|
||||||
|
router.replace(user.role === "manager" ? ROUTES.manager : ROUTES.employee);
|
||||||
}
|
}
|
||||||
}, [user, isLoading, router]);
|
}, [user, isLoading, router]);
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
import { ROUTES } from "@/lib/routes";
|
||||||
|
|
||||||
import React, {
|
import React, {
|
||||||
createContext,
|
createContext,
|
||||||
@ -61,7 +62,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const logout = () => {
|
const logout = () => {
|
||||||
setUser(null);
|
setUser(null);
|
||||||
localStorage.removeItem("lms_user");
|
localStorage.removeItem("lms_user");
|
||||||
router.push("/");
|
// router.push("/");
|
||||||
|
router.push(ROUTES.home);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user