From 500c8b6e5db0b90491e2c05cd84053f8da303b6c Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sun, 11 Jan 2026 21:30:57 +0530 Subject: [PATCH] default layuout --- src/app/(agent)/agent/dashboard/page.tsx | 147 +++++++++++++++++++++++ src/app/(agent)/layout.tsx | 134 ++++++++++++++++++++- src/app/(user)/layout.tsx | 131 +++++++++++++++++++- src/app/(user)/user/dashboard/page.tsx | 115 ++++++++++++++++++ src/app/page.tsx | 111 ++++++----------- src/middleware.ts | 23 +++- 6 files changed, 581 insertions(+), 80 deletions(-) create mode 100644 src/app/(agent)/agent/dashboard/page.tsx create mode 100644 src/app/(user)/user/dashboard/page.tsx diff --git a/src/app/(agent)/agent/dashboard/page.tsx b/src/app/(agent)/agent/dashboard/page.tsx new file mode 100644 index 0000000..40ce30d --- /dev/null +++ b/src/app/(agent)/agent/dashboard/page.tsx @@ -0,0 +1,147 @@ +'use client'; + +import { useSession } from 'next-auth/react'; + +export default function AgentDashboard() { + const { data: session } = useSession(); + + return ( +
+ {/* Welcome Section */} +
+

+ Welcome back, {session?.user?.name?.split(' ')[0] || 'Agent'}! +

+

+ Here's an overview of your real estate business today. +

+
+ + {/* Stats Grid */} +
+
+
+
+ + + +
+
+

12

+

Active Listings

+
+ +
+
+
+ + + +
+
+

48

+

Total Clients

+
+ +
+
+
+ + + +
+
+

5

+

Upcoming Appointments

+
+ +
+
+
+ + + +
+
+

8

+

Unread Messages

+
+
+ + {/* Quick Actions */} +
+

Quick Actions

+
+ + + + + +
+
+ + {/* Recent Activity */} +
+

Recent Activity

+
+
+
+ + + +
+
+

New inquiry for 123 Main Street

+

2 hours ago

+
+
+ +
+
+ + + +
+
+

Appointment scheduled with John Doe

+

5 hours ago

+
+
+ +
+
+ + + +
+
+

Property price updated: 456 Oak Avenue

+

Yesterday

+
+
+
+
+
+ ); +} diff --git a/src/app/(agent)/layout.tsx b/src/app/(agent)/layout.tsx index 3970146..ebdf98f 100644 --- a/src/app/(agent)/layout.tsx +++ b/src/app/(agent)/layout.tsx @@ -1,7 +1,139 @@ +'use client'; + +import { useSession, signOut } from 'next-auth/react'; +import { useRouter, usePathname } from 'next/navigation'; +import { useEffect } from 'react'; +import Link from 'next/link'; + +const agentNavItems = [ + { href: '/agent/dashboard', label: 'Dashboard', icon: 'home' }, + { href: '/agent/properties', label: 'My Properties', icon: 'building' }, + { href: '/agent/clients', label: 'Clients', icon: 'users' }, + { href: '/agent/appointments', label: 'Appointments', icon: 'calendar' }, + { href: '/agent/messages', label: 'Messages', icon: 'message' }, + { href: '/agent/settings', label: 'Settings', icon: 'settings' }, +]; + +const icons: Record = { + home: ( + + + + ), + building: ( + + + + ), + users: ( + + + + ), + calendar: ( + + + + ), + message: ( + + + + ), + settings: ( + + + + + ), +}; + export default function AgentLayout({ children, }: { children: React.ReactNode; }) { - return <>{children}; + const { data: session, status } = useSession(); + const router = useRouter(); + const pathname = usePathname(); + + useEffect(() => { + if (status === 'loading') return; + + if (!session) { + router.replace('/login'); + return; + } + + // Redirect non-agents to user dashboard + const userRole = (session.user as any)?.role; + if (userRole !== 'AGENT') { + router.replace('/user/dashboard'); + } + }, [session, status, router]); + + if (status === 'loading' || !session) { + return ( +
+
+
+ ); + } + + return ( +
+ {/* Header */} +
+
+
+ + RE-QuestN + +
+ + {session?.user?.name || session?.user?.email} + + + Agent + + +
+
+
+
+ +
+ {/* Sidebar */} + + + {/* Main Content */} +
{children}
+
+
+ ); } diff --git a/src/app/(user)/layout.tsx b/src/app/(user)/layout.tsx index f709e7e..6780e06 100644 --- a/src/app/(user)/layout.tsx +++ b/src/app/(user)/layout.tsx @@ -1,7 +1,136 @@ +'use client'; + +import { useSession, signOut } from 'next-auth/react'; +import { useRouter, usePathname } from 'next/navigation'; +import { useEffect } from 'react'; +import Link from 'next/link'; + +const userNavItems = [ + { href: '/user/dashboard', label: 'Dashboard', icon: 'home' }, + { href: '/user/properties', label: 'Browse Properties', icon: 'building' }, + { href: '/user/favorites', label: 'Favorites', icon: 'heart' }, + { href: '/user/inquiries', label: 'My Inquiries', icon: 'message' }, + { href: '/user/appointments', label: 'Appointments', icon: 'calendar' }, + { href: '/user/settings', label: 'Settings', icon: 'settings' }, +]; + +const icons: Record = { + home: ( + + + + ), + building: ( + + + + ), + heart: ( + + + + ), + message: ( + + + + ), + calendar: ( + + + + ), + settings: ( + + + + + ), +}; + export default function UserLayout({ children, }: { children: React.ReactNode; }) { - return <>{children}; + const { data: session, status } = useSession(); + const router = useRouter(); + const pathname = usePathname(); + + useEffect(() => { + if (status === 'loading') return; + + if (!session) { + router.replace('/login'); + return; + } + + // Redirect agents to agent dashboard + const userRole = (session.user as any)?.role; + if (userRole === 'AGENT') { + router.replace('/agent/dashboard'); + } + }, [session, status, router]); + + if (status === 'loading' || !session) { + return ( +
+
+
+ ); + } + + return ( +
+ {/* Header */} +
+
+
+ + RE-QuestN + +
+ + {session?.user?.name || session?.user?.email} + + +
+
+
+
+ +
+ {/* Sidebar */} + + + {/* Main Content */} +
{children}
+
+
+ ); } diff --git a/src/app/(user)/user/dashboard/page.tsx b/src/app/(user)/user/dashboard/page.tsx new file mode 100644 index 0000000..138318f --- /dev/null +++ b/src/app/(user)/user/dashboard/page.tsx @@ -0,0 +1,115 @@ +'use client'; + +import { useSession } from 'next-auth/react'; + +export default function UserDashboard() { + const { data: session } = useSession(); + + return ( +
+ {/* Welcome Section */} +
+

+ Welcome, {session?.user?.name?.split(' ')[0] || 'User'}! +

+

+ Your real estate journey starts here. Explore properties, connect with agents, and find your dream home. +

+
+ + {/* Quick Actions */} +
+
+
+ + + +
+

Search Properties

+

Find your perfect home from thousands of listings

+
+ +
+
+ + + +
+

Find Agents

+

Connect with top real estate professionals

+
+ +
+
+ + + +
+

Saved Favorites

+

View your saved properties and searches

+
+
+ + {/* Stats */} +
+
+

0

+

Saved Properties

+
+
+

0

+

Active Inquiries

+
+
+

0

+

Scheduled Tours

+
+
+

0

+

Messages

+
+
+ + {/* Featured Properties */} +
+
+

Featured Properties

+ +
+ +
+ {/* Property Card Placeholder */} +
+
+ + + +
+

No featured properties yet

+ +
+
+
+ + {/* Recent Activity */} +
+

Recent Activity

+
+
+ + + +
+

No recent activity

+

+ Start exploring properties to see your activity here +

+
+
+
+ ); +} diff --git a/src/app/page.tsx b/src/app/page.tsx index 5d42ce7..960ec61 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,86 +1,43 @@ 'use client'; -import { useSession, signOut } from 'next-auth/react'; -import Link from 'next/link'; +import { useSession } from 'next-auth/react'; +import { useRouter } from 'next/navigation'; +import { useEffect } from 'react'; export default function Home() { - const { data: session } = useSession(); + const { data: session, status } = useSession(); + const router = useRouter(); + useEffect(() => { + if (status === 'loading') return; + + if (!session) { + router.replace('/login'); + return; + } + + // Redirect based on user role + const userRole = (session.user as any)?.role; + + if (userRole === 'AGENT') { + router.replace('/agent/dashboard'); + } else { + router.replace('/user/dashboard'); + } + }, [session, status, router]); + + // Loading state while determining redirect return ( -
- {/* Header */} -
-
-
- {/* Logo */} - - RE-QuestN - - - {/* User Menu */} -
- - Welcome, {session?.user?.name || session?.user?.email || 'User'} - - -
-
-
-
- - {/* Main Content */} -
-
-

- Welcome to RE-QuestN -

-

- Your real estate journey starts here. Explore properties, connect with agents, and find your dream home. -

- - {/* Quick Actions */} -
-
-
- - - -
-

Browse Properties

-

Explore thousands of listings in your area

-
- -
-
- - - -
-

Find Agents

-

Connect with top real estate professionals

-
- -
-
- - - -
-

Saved Favorites

-

View your saved properties and searches

-
-
-
-
+
+
+ RE-QuestN +
+

Loading...

+
); } diff --git a/src/middleware.ts b/src/middleware.ts index 4275cde..6b3631d 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -7,11 +7,15 @@ const publicRoutes = ["/login", "/signup", "/forgot-password", "/reset-password" export default auth((req) => { const { nextUrl } = req; const isLoggedIn = !!req.auth; + const userRole = (req.auth?.user as any)?.role; const isPublicRoute = publicRoutes.some( (route) => nextUrl.pathname === route || nextUrl.pathname.startsWith(route + "/") ); + const isAgentRoute = nextUrl.pathname.startsWith("/agent"); + const isUserRoute = nextUrl.pathname.startsWith("/user"); + const isApiRoute = nextUrl.pathname.startsWith("/api"); const isStaticRoute = nextUrl.pathname.startsWith("/_next") || nextUrl.pathname.startsWith("/assets") || @@ -24,7 +28,11 @@ export default auth((req) => { // Redirect logged-in users away from public routes (login, signup) if (isLoggedIn && isPublicRoute) { - return NextResponse.redirect(new URL("/", nextUrl.origin)); + // Redirect to appropriate dashboard based on role + if (userRole === "AGENT") { + return NextResponse.redirect(new URL("/agent/dashboard", nextUrl.origin)); + } + return NextResponse.redirect(new URL("/user/dashboard", nextUrl.origin)); } // Redirect non-logged-in users to login page for protected routes @@ -34,6 +42,19 @@ export default auth((req) => { return NextResponse.redirect(loginUrl); } + // Role-based route protection + if (isLoggedIn) { + // Prevent regular users from accessing agent routes + if (isAgentRoute && userRole !== "AGENT") { + return NextResponse.redirect(new URL("/user/dashboard", nextUrl.origin)); + } + + // Prevent agents from accessing user routes + if (isUserRoute && userRole === "AGENT") { + return NextResponse.redirect(new URL("/agent/dashboard", nextUrl.origin)); + } + } + return NextResponse.next(); });