2025-12-18 21:37:28 +01:00
|
|
|
"use client";
|
|
|
|
|
|
2025-12-22 18:09:09 +01:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { useAuth } from "./auth-context";
|
|
|
|
|
import { layoutStyles } from "./styles/shared";
|
|
|
|
|
import constants from "../../shared/constants.json";
|
|
|
|
|
|
|
|
|
|
const { ADMIN, REGULAR } = constants.roles;
|
2025-12-18 22:24:46 +01:00
|
|
|
|
2025-12-18 21:37:28 +01:00
|
|
|
export default function Home() {
|
2025-12-22 18:09:09 +01:00
|
|
|
const { user, isLoading, hasRole } = useAuth();
|
|
|
|
|
const router = useRouter();
|
2025-12-18 23:33:32 +01:00
|
|
|
|
2025-12-18 21:37:28 +01:00
|
|
|
useEffect(() => {
|
2025-12-22 18:09:09 +01:00
|
|
|
if (isLoading) return;
|
2025-12-18 21:37:28 +01:00
|
|
|
|
2025-12-22 18:09:09 +01:00
|
|
|
if (!user) {
|
|
|
|
|
router.replace("/login");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-12-18 22:08:31 +01:00
|
|
|
|
2025-12-22 18:09:09 +01:00
|
|
|
// Redirect based on role
|
|
|
|
|
if (hasRole(ADMIN)) {
|
|
|
|
|
router.replace("/admin/appointments");
|
|
|
|
|
} else if (hasRole(REGULAR)) {
|
|
|
|
|
router.replace("/booking");
|
|
|
|
|
} else {
|
|
|
|
|
// User with no roles - redirect to login
|
|
|
|
|
router.replace("/login");
|
|
|
|
|
}
|
|
|
|
|
}, [user, isLoading, hasRole, router]);
|
2025-12-18 22:08:31 +01:00
|
|
|
|
2025-12-18 21:37:28 +01:00
|
|
|
return (
|
refactor(frontend): consolidate shared styles into centralized style system
- Create comprehensive shared.ts with design tokens and categorized styles:
- layoutStyles: main, loader, content variants
- cardStyles: card, tableCard, cardHeader
- tableStyles: complete table styling
- paginationStyles: pagination controls
- formStyles: inputs, labels, errors
- buttonStyles: primary, secondary, accent, danger variants
- badgeStyles: status badges with color variants
- bannerStyles: error/success banners
- modalStyles: modal overlay and content
- toastStyles: toast notifications
- utilityStyles: divider, emptyState, etc.
- Refactor all page components to use shared styles:
- page.tsx (counter)
- audit/page.tsx
- booking/page.tsx
- appointments/page.tsx
- profile/page.tsx
- invites/page.tsx
- admin/invites/page.tsx
- admin/availability/page.tsx
- Reduce code duplication significantly (each page now has only
truly page-specific styles)
- Maintain backwards compatibility with sharedStyles export
2025-12-21 23:45:47 +01:00
|
|
|
<main style={layoutStyles.main}>
|
2025-12-22 18:09:09 +01:00
|
|
|
<div style={layoutStyles.loader}>Redirecting...</div>
|
2025-12-18 21:37:28 +01:00
|
|
|
</main>
|
|
|
|
|
);
|
|
|
|
|
}
|