students fked up
This commit is contained in:
6
apps/admin/app/(main)/actions.ts
Normal file
6
apps/admin/app/(main)/actions.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
'use server'
|
||||
import { signOut } from "@/auth";
|
||||
|
||||
export async function signOutAction() {
|
||||
await signOut();
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
Search,
|
||||
ChevronDown
|
||||
} from 'lucide-react';
|
||||
import { signOutAction } from './actions';
|
||||
|
||||
const navLinks = [
|
||||
{
|
||||
@@ -180,6 +181,7 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={signOutAction}
|
||||
className="w-full justify-start text-red-600 hover:text-red-700 hover:bg-red-50"
|
||||
>
|
||||
<LogOut className="w-4 h-4 mr-2" />
|
||||
|
||||
@@ -10,6 +10,7 @@ declare module 'next-auth' {
|
||||
role?: 'ADMIN' | 'USER';
|
||||
adminId?: number;
|
||||
studentId?: number;
|
||||
completedProfile?: boolean;
|
||||
[key: string]: any;
|
||||
} & DefaultSession["user"];
|
||||
}
|
||||
@@ -18,6 +19,7 @@ declare module 'next-auth' {
|
||||
role?: 'ADMIN' | 'USER';
|
||||
adminId?: number;
|
||||
studentId?: number;
|
||||
completedProfile?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +32,14 @@ declare module 'next/server' {
|
||||
const authConfig: NextAuthConfig = {
|
||||
providers: [Google],
|
||||
callbacks: {
|
||||
async jwt({ token, account, user, profile }) {
|
||||
async jwt({ token, account, user }) {
|
||||
// Only check DB on first sign in
|
||||
if (account && user && user.email) {
|
||||
const admin = await db.select().from(admins).where(eq(admins.email, user.email)).limit(1);
|
||||
if (admin.length > 0 && admin[0]) {
|
||||
token.role = 'ADMIN';
|
||||
token.adminId = admin[0].id;
|
||||
token.completedProfile = true;
|
||||
} else {
|
||||
token.role = 'USER';
|
||||
const student = await db
|
||||
@@ -46,6 +49,7 @@ const authConfig: NextAuthConfig = {
|
||||
.limit(1);
|
||||
if (student.length > 0 && student[0]) {
|
||||
token.studentId = student[0].id;
|
||||
token.completedProfile = student[0].rollNumber ? true : false;
|
||||
} else {
|
||||
const nameParts = user.name?.split(' ') ?? [];
|
||||
const firstName = nameParts[0] || '';
|
||||
@@ -61,6 +65,7 @@ const authConfig: NextAuthConfig = {
|
||||
.returning({ id: students.id });
|
||||
if (newStudent[0]) {
|
||||
token.studentId = newStudent[0].id;
|
||||
token.completedProfile = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +82,9 @@ const authConfig: NextAuthConfig = {
|
||||
if (token?.studentId) {
|
||||
session.user.studentId = token.studentId as number;
|
||||
}
|
||||
if (token?.completedProfile !== undefined) {
|
||||
session.user.completedProfile = token.completedProfile as boolean;
|
||||
}
|
||||
return session;
|
||||
},
|
||||
},
|
||||
|
||||
6
apps/student/app/(main)/actions.ts
Normal file
6
apps/student/app/(main)/actions.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
'use server'
|
||||
import { signOut } from "@/auth";
|
||||
|
||||
export async function signOutAction() {
|
||||
await signOut();
|
||||
}
|
||||
@@ -1,36 +1,291 @@
|
||||
import {
|
||||
NavigationMenu,
|
||||
NavigationMenuContent,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuLink,
|
||||
NavigationMenuList,
|
||||
NavigationMenuTrigger,
|
||||
navigationMenuTriggerStyle,
|
||||
} from '@workspace/ui/components/navigation-menu';
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import { Badge } from '@workspace/ui/components/badge';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Users,
|
||||
Briefcase,
|
||||
Menu,
|
||||
X,
|
||||
LogOut,
|
||||
Settings,
|
||||
Bell,
|
||||
Search,
|
||||
ChevronDown
|
||||
} from 'lucide-react';
|
||||
import { signOutAction } from './actions';
|
||||
|
||||
const navLinks = [
|
||||
{
|
||||
href: '/',
|
||||
label: 'Dashboard',
|
||||
icon: LayoutDashboard,
|
||||
description: 'Overview and analytics'
|
||||
},
|
||||
{
|
||||
href: '/students',
|
||||
label: 'Students',
|
||||
icon: Users,
|
||||
description: 'Manage student profiles'
|
||||
},
|
||||
{
|
||||
href: '/jobs',
|
||||
label: 'Jobs',
|
||||
icon: Briefcase,
|
||||
description: 'Job listings and applications'
|
||||
},
|
||||
];
|
||||
|
||||
export default function MainLayout({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname();
|
||||
const [isScrolled, setIsScrolled] = useState(false);
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
const [isProfileDropdownOpen, setIsProfileDropdownOpen] = useState(false);
|
||||
|
||||
// Handle scroll effect
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setIsScrolled(window.scrollY > 10);
|
||||
};
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
return () => window.removeEventListener('scroll', handleScroll);
|
||||
}, []);
|
||||
|
||||
// Close mobile menu when route changes
|
||||
useEffect(() => {
|
||||
setIsMobileMenuOpen(false);
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<header className="flex h-16 items-center justify-between border-b bg-background px-4 md:px-6">
|
||||
<nav>
|
||||
<NavigationMenu>
|
||||
<NavigationMenuList>
|
||||
<NavigationMenuItem>
|
||||
<NavigationMenuLink asChild>
|
||||
<Link href="/">Home</Link>
|
||||
</NavigationMenuLink>
|
||||
</NavigationMenuItem>
|
||||
<NavigationMenuItem>
|
||||
<NavigationMenuLink asChild>
|
||||
<Link href="/signup">Signup</Link>
|
||||
</NavigationMenuLink>
|
||||
</NavigationMenuItem>
|
||||
</NavigationMenuList>
|
||||
</NavigationMenu>
|
||||
<div className="min-h-screen bg-background font-sans">
|
||||
{/* Enhanced Sticky Navbar */}
|
||||
<header className={`sticky top-0 z-50 w-full transition-all duration-300 ${
|
||||
isScrolled
|
||||
? 'bg-white/95 backdrop-blur-md shadow-lg border-b border-gray-200/50'
|
||||
: 'bg-white/80 backdrop-blur-sm'
|
||||
}`}>
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="flex items-center justify-between h-16">
|
||||
{/* Logo Section */}
|
||||
<div className="flex items-center gap-3 group">
|
||||
<div className="relative">
|
||||
<img
|
||||
src="/favicon.ico"
|
||||
alt="Logo"
|
||||
className="w-10 h-10 rounded-xl shadow-lg group-hover:shadow-xl transition-all duration-300 group-hover:scale-110"
|
||||
/>
|
||||
<div className="absolute inset-0 rounded-xl bg-gradient-to-br from-red-500/20 to-pink-500/20 opacity-0 group-hover:opacity-100 transition-opacity duration-300" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="font-extrabold text-2xl tracking-tight text-gray-800 group-hover:text-gray-900 transition-colors duration-200">
|
||||
NextPlacement
|
||||
</span>
|
||||
<span className="text-xs text-gray-500 font-medium -mt-1">Admin Portal</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Desktop Navigation */}
|
||||
<nav className="hidden md:flex items-center gap-6">
|
||||
{navLinks.map((link) => {
|
||||
const isActive = pathname === link.href;
|
||||
const Icon = link.icon;
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className={`relative group px-6 py-3 rounded-xl font-medium transition-all duration-200 ${
|
||||
isActive
|
||||
? 'text-red-600 bg-red-50 border border-red-200'
|
||||
: 'text-gray-700 hover:text-gray-900 hover:bg-gray-50'
|
||||
}`}
|
||||
prefetch={false}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<Icon className={`w-5 h-5 transition-transform duration-200 group-hover:scale-110 ${
|
||||
isActive ? 'text-red-600' : 'text-gray-500 group-hover:text-gray-700'
|
||||
}`} />
|
||||
<span className="text-base">{link.label}</span>
|
||||
</div>
|
||||
|
||||
{/* Active indicator */}
|
||||
{isActive && (
|
||||
<div className="absolute bottom-0 left-1/2 transform -translate-x-1/2 w-1 h-1 bg-red-500 rounded-full animate-pulse" />
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Right Section - Search, Notifications, Profile */}
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Search Button */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="hidden sm:flex items-center gap-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-all duration-200"
|
||||
>
|
||||
<Search className="w-4 h-4" />
|
||||
<span className="hidden lg:inline text-sm">Search</span>
|
||||
</Button>
|
||||
|
||||
{/* Notifications */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="relative text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-all duration-200"
|
||||
>
|
||||
<Bell className="w-4 h-4" />
|
||||
<Badge className="absolute -top-1 -right-1 h-5 w-5 rounded-full bg-red-500 text-xs text-white flex items-center justify-center animate-pulse">
|
||||
3
|
||||
</Badge>
|
||||
</Button>
|
||||
|
||||
{/* Profile Dropdown */}
|
||||
<div className="relative">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsProfileDropdownOpen(!isProfileDropdownOpen)}
|
||||
className="flex items-center gap-2 text-gray-700 hover:text-gray-900 hover:bg-gray-100 transition-all duration-200"
|
||||
>
|
||||
<div className="w-8 h-8 bg-gradient-to-br from-red-500 to-pink-500 rounded-full flex items-center justify-center text-white font-semibold text-sm">
|
||||
A
|
||||
</div>
|
||||
<span className="hidden lg:inline text-sm font-medium">Admin</span>
|
||||
<ChevronDown className={`w-4 h-4 transition-transform duration-200 ${
|
||||
isProfileDropdownOpen ? 'rotate-180' : ''
|
||||
}`} />
|
||||
</Button>
|
||||
|
||||
{/* Profile Dropdown Menu */}
|
||||
{isProfileDropdownOpen && (
|
||||
<div className="absolute right-0 mt-2 w-48 bg-white rounded-xl shadow-lg border border-gray-200 py-2 z-50 animate-in slide-in-from-top-2 duration-200">
|
||||
<div className="px-4 py-3 border-b border-gray-100">
|
||||
<p className="text-sm font-medium text-gray-900">Admin User</p>
|
||||
<p className="text-xs text-gray-500">admin@nextplacement.com</p>
|
||||
</div>
|
||||
<div className="py-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full justify-start text-gray-700 hover:text-gray-900 hover:bg-gray-50"
|
||||
>
|
||||
<Settings className="w-4 h-4 mr-2" />
|
||||
Settings
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={signOutAction}
|
||||
className="w-full justify-start text-red-600 hover:text-red-700 hover:bg-red-50"
|
||||
>
|
||||
<LogOut className="w-4 h-4 mr-2" />
|
||||
Sign Out
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Mobile Menu Button */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
|
||||
className="md:hidden text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-all duration-200"
|
||||
>
|
||||
{isMobileMenuOpen ? (
|
||||
<X className="w-5 h-5" />
|
||||
) : (
|
||||
<Menu className="w-5 h-5" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mobile Navigation Menu */}
|
||||
{isMobileMenuOpen && (
|
||||
<div className="md:hidden border-t border-gray-200 bg-white/95 backdrop-blur-md animate-in slide-in-from-top-2 duration-200">
|
||||
<nav className="px-4 py-4 space-y-2">
|
||||
{navLinks.map((link) => {
|
||||
const isActive = pathname === link.href;
|
||||
const Icon = link.icon;
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className={`flex items-center gap-3 px-4 py-3 rounded-xl font-medium transition-all duration-200 ${
|
||||
isActive
|
||||
? 'text-red-600 bg-red-50 border border-red-200'
|
||||
: 'text-gray-700 hover:text-gray-900 hover:bg-gray-50'
|
||||
}`}
|
||||
prefetch={false}
|
||||
>
|
||||
<Icon className={`w-5 h-5 ${
|
||||
isActive ? 'text-red-600' : 'text-gray-500'
|
||||
}`} />
|
||||
<span>{link.label}</span>
|
||||
{isActive && (
|
||||
<div className="ml-auto w-2 h-2 bg-red-500 rounded-full animate-pulse" />
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* Mobile Profile Section */}
|
||||
<div className="pt-4 border-t border-gray-200 mt-4">
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
<div className="w-10 h-10 bg-gradient-to-br from-red-500 to-pink-500 rounded-full flex items-center justify-center text-white font-semibold">
|
||||
A
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-900">Admin User</p>
|
||||
<p className="text-xs text-gray-500">admin@nextplacement.com</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="px-4 py-2 space-y-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full justify-start text-gray-700 hover:text-gray-900 hover:bg-gray-50"
|
||||
>
|
||||
<Settings className="w-4 h-4 mr-2" />
|
||||
Settings
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full justify-start text-red-600 hover:text-red-700 hover:bg-red-50"
|
||||
>
|
||||
<LogOut className="w-4 h-4 mr-2" />
|
||||
Sign Out
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
<main>{children}</main>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="bg-background min-h-screen">
|
||||
{children}
|
||||
</main>
|
||||
|
||||
{/* Click outside to close dropdowns */}
|
||||
{isProfileDropdownOpen && (
|
||||
<div
|
||||
className="fixed inset-0 z-40"
|
||||
onClick={() => setIsProfileDropdownOpen(false)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,222 @@
|
||||
import Login from '@/components/login';
|
||||
import Studs from '@/components/studs';
|
||||
import { db, admins } from '@workspace/db';
|
||||
import { auth, signIn, signOut } from '@/auth';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@workspace/ui/components/card"
|
||||
import { Button } from "@workspace/ui/components/button"
|
||||
import { Badge } from "@workspace/ui/components/badge"
|
||||
import { Separator } from "@workspace/ui/components/separator"
|
||||
import Link from "next/link"
|
||||
import { db, companies } from "@workspace/db"
|
||||
import { Plus, Building2, Briefcase, MapPin, DollarSign, Calendar, ExternalLink } from "lucide-react"
|
||||
|
||||
async function getStudents() {
|
||||
'use server';
|
||||
const s = await db.select().from(admins);
|
||||
console.log(s);
|
||||
async function getDashboardData() {
|
||||
try {
|
||||
// Get companies with their jobs
|
||||
const result = await db.query.companies.findMany({
|
||||
with: {
|
||||
jobs: {
|
||||
where: (job, {eq}) => eq(job.active, true), // Only include active jobs
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Filter to only include companies that have active jobs
|
||||
const companiesWithActiveJobs = result.filter((company) => company.jobs.length > 0)
|
||||
|
||||
console.log("Companies with active jobs:", companiesWithActiveJobs.length)
|
||||
return companiesWithActiveJobs
|
||||
} catch (error) {
|
||||
console.error("Database query error:", error)
|
||||
// Fallback to companies only if the relation query fails
|
||||
const companiesOnly = await db.select().from(companies)
|
||||
return companiesOnly.map((company) => ({ ...company, jobs: [] }))
|
||||
}
|
||||
}
|
||||
|
||||
async function logIn() {
|
||||
'use server';
|
||||
await signIn('google');
|
||||
}
|
||||
export default async function DashboardPage() {
|
||||
const data = await getDashboardData()
|
||||
|
||||
async function logOut() {
|
||||
'use server';
|
||||
await signOut();
|
||||
}
|
||||
// Calculate stats for companies with active jobs only
|
||||
const totalActiveJobs = data.reduce((acc, company) => acc + company.jobs.filter((job) => job.active).length, 0)
|
||||
|
||||
export default async function Page() {
|
||||
const session = await auth();
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-svh">
|
||||
<div className="flex flex-col items-center justify-center gap-4">
|
||||
<h1 className="text-2xl font-bold">Hello student {session?.user?.name}</h1>
|
||||
{!session?.user && <Login action={logIn} />}
|
||||
<Studs action={getStudents} logOut={logOut} />
|
||||
<div className="min-h-screen bg-gradient-to-br">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
{/* Header Section */}
|
||||
<section className="mb-12">
|
||||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-8">
|
||||
<div>
|
||||
<h1 className="text-4xl font-bold text-gray-800 mb-2">Companies Dashboard</h1>
|
||||
<p className="text-gray-600 text-lg">Companies with active job listings</p>
|
||||
</div>
|
||||
<Link href="/jobs/new">
|
||||
<Button className="flex items-center gap-2 px-6 py-3 text-base font-medium shadow-lg hover:shadow-xl transition-all duration-200">
|
||||
<Plus className="w-5 h-5" />
|
||||
Add New Job
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Stats Cards */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
|
||||
<Card className="bg-white shadow-sm hover:shadow-md transition-shadow duration-200">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-600">Companies with Active Jobs</p>
|
||||
<p className="text-3xl font-bold text-gray-800">{data.length}</p>
|
||||
</div>
|
||||
<Building2 className="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="bg-white shadow-sm hover:shadow-md transition-shadow duration-200">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-600">Total Active Jobs</p>
|
||||
<p className="text-3xl font-bold text-gray-800">{totalActiveJobs}</p>
|
||||
</div>
|
||||
<Briefcase className="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="bg-white shadow-sm hover:shadow-md transition-shadow duration-200">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-600">Avg Jobs per Company</p>
|
||||
<p className="text-3xl font-bold text-gray-800">
|
||||
{data.length > 0 ? Math.round((totalActiveJobs / data.length) * 10) / 10 : 0}
|
||||
</p>
|
||||
</div>
|
||||
<div className="w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<div className="w-3 h-3 bg-blue-500 rounded-full"></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Companies Section */}
|
||||
<section className="space-y-8">
|
||||
{data.length === 0 ? (
|
||||
<Card className="bg-white shadow-sm">
|
||||
<CardContent className="p-12 text-center">
|
||||
<Building2 className="w-16 h-16 text-gray-300 mx-auto mb-4" />
|
||||
<h3 className="text-xl font-semibold text-gray-700 mb-2">No companies with active jobs</h3>
|
||||
<p className="text-gray-500 mb-6">Get started by adding your first job listing</p>
|
||||
<Link href="/jobs/new">
|
||||
<Button className="flex items-center gap-2">
|
||||
<Plus className="w-4 h-4" />
|
||||
Add Job
|
||||
</Button>
|
||||
</Link>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
data.map((company) => (
|
||||
<Card
|
||||
key={company.id}
|
||||
className="bg-white shadow-sm hover:shadow-md transition-all duration-200 overflow-hidden"
|
||||
>
|
||||
<CardHeader className="pb-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="w-12 h-12 bg-gray-100 rounded-lg flex items-center justify-center">
|
||||
<Building2 className="w-6 h-6 text-gray-600" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-xl font-semibold text-gray-800">{company.name}</CardTitle>
|
||||
<p className="text-sm text-gray-500 mt-1">{company.email}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
{company.jobs.filter((job) => job.active).length} active job
|
||||
{company.jobs.filter((job) => job.active).length !== 1 ? "s" : ""}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
{company.description && company.description !== "N/A" && (
|
||||
<p className="text-sm text-gray-600 mt-3">{company.description}</p>
|
||||
)}
|
||||
</CardHeader>
|
||||
|
||||
<Separator />
|
||||
|
||||
<CardContent className="pt-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-medium text-gray-700">Active Job Listings</h3>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
{company.jobs
|
||||
.filter((job) => job.active)
|
||||
.map((job) => (
|
||||
<Card
|
||||
key={job.id}
|
||||
className="group hover:shadow-lg transition-all duration-200 border border-gray-200 bg-gray-50 hover:bg-white"
|
||||
>
|
||||
<CardContent className="p-4">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<h4 className="font-medium text-gray-800 text-sm leading-tight line-clamp-2">
|
||||
{job.title}
|
||||
</h4>
|
||||
<Badge
|
||||
variant="default"
|
||||
className="text-xs bg-blue-100 text-blue-700 hover:bg-blue-200"
|
||||
>
|
||||
Active
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
{job.location && job.location !== "N/A" && (
|
||||
<div className="flex items-center gap-1 text-xs text-gray-500">
|
||||
<MapPin className="w-3 h-3" />
|
||||
<span className="truncate">{job.location}</span>
|
||||
</div>
|
||||
)}
|
||||
{job.salary && job.salary !== "N/A" && (
|
||||
<div className="flex items-center gap-1 text-xs text-gray-500">
|
||||
<DollarSign className="w-3 h-3" />
|
||||
<span className="truncate">{job.salary}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-1 text-xs text-gray-500">
|
||||
<Calendar className="w-3 h-3" />
|
||||
<span>Deadline: {job.applicationDeadline.toLocaleDateString()}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{job.link && (
|
||||
<div className="pt-2">
|
||||
<a
|
||||
href={job.link}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-700 font-medium group-hover:underline"
|
||||
>
|
||||
View Job
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -8,19 +8,34 @@ async function logIn() {
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-svh">
|
||||
<div className="flex flex-col items-center justify-center gap-4">
|
||||
<form action={logIn}>
|
||||
<Button type="submit" variant="outline" className="w-full h-12">
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-primary/0 via-primary/10 to-primary/0 translate-x-[-100%] group-hover:translate-x-[100%] transition-transform duration-700 ease-out pointer-events-none" />
|
||||
<div className="relative min-h-svh flex items-center justify-center overflow-hidden bg-gradient-to-br from-blue-100 via-red-100 to-pink-100 transition-colors duration-500">
|
||||
{/* Animated floating shapes */}
|
||||
<div className="pointer-events-none absolute inset-0 z-0">
|
||||
<div className="absolute top-10 left-1/4 w-32 h-32 bg-rose-200/40 rounded-full blur-2xl animate-float-slow" />
|
||||
<div className="absolute bottom-20 right-1/4 w-40 h-40 bg-blue-200/30 rounded-full blur-2xl animate-float-medium" />
|
||||
<div className="absolute top-1/2 left-1/2 w-24 h-24 bg-red-300/30 rounded-full blur-2xl animate-float-fast" />
|
||||
</div>
|
||||
<div className="relative z-10 backdrop-blur-md bg-white/70 rounded-2xl shadow-2xl p-10 flex flex-col items-center gap-8 border border-white/30 max-w-sm w-full transition-all duration-300 hover:shadow-[0_0_32px_4px_rgba(239,68,68,0.25)] hover:border-red-400/60">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
{/* Animated logo */}
|
||||
<img src="/favicon.ico" alt="Logo" className="w-14 h-14 mb-2 drop-shadow-lg animate-bounce-slow" />
|
||||
<h1 className="text-2xl font-bold text-gray-800 tracking-tight">Placement Portal Admin</h1>
|
||||
<p className="text-gray-500 text-sm text-center">Sign in to manage placements and students</p>
|
||||
<p className="text-xs text-red-500 font-semibold italic mt-1 animate-fade-in">Empower your journey. Shape the future.</p>
|
||||
</div>
|
||||
<form action={logIn} className="w-full">
|
||||
<Button type="submit" variant="outline" className="w-full h-12 relative overflow-hidden group rounded-lg shadow-md hover:shadow-lg transition-all focus:ring-2 focus:ring-red-400">
|
||||
<span className="absolute inset-0 bg-gradient-to-r from-red-200/0 via-red-200/20 to-red-200/0 translate-x-[-100%] group-hover:translate-x-[100%] transition-transform duration-700 ease-out pointer-events-none" />
|
||||
<img
|
||||
src="https://static.cdnlogo.com/logos/g/35/google-icon.svg"
|
||||
alt="Google logo"
|
||||
className="w-5 h-5 transition-transform duration-200"
|
||||
className="w-5 h-5 mr-2 inline-block align-middle"
|
||||
/>
|
||||
<span className="relative z-10 font-medium transition-colors duration-200 group-hover:text-foreground">
|
||||
<span className="relative z-10 font-medium transition-colors duration-200 group-hover:text-red-700 group-hover:drop-shadow-md">
|
||||
Sign in with Google
|
||||
</span>
|
||||
{/* Button ripple effect */}
|
||||
<span className="absolute left-1/2 top-1/2 w-0 h-0 bg-red-300/40 rounded-full opacity-0 group-active:opacity-100 group-active:w-32 group-active:h-32 group-active:animate-ripple -translate-x-1/2 -translate-y-1/2 pointer-events-none" />
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
46
apps/student/app/signup/action.ts
Normal file
46
apps/student/app/signup/action.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
'use server'
|
||||
import { db, students } from '@workspace/db';
|
||||
import { eq } from '@workspace/db/drizzle';
|
||||
import { studentSignupSchema } from './schema';
|
||||
import { auth } from '@/auth';
|
||||
|
||||
export async function signupAction(data: FormData) {
|
||||
const session = await auth();
|
||||
const studentId = session?.user?.studentId;
|
||||
if (!studentId) {
|
||||
return { error: 'Student ID not found in session.' };
|
||||
}
|
||||
|
||||
const formData = Object.fromEntries(data.entries());
|
||||
const parsedData = await studentSignupSchema.safeParseAsync(formData);
|
||||
|
||||
if (!parsedData.success) {
|
||||
return { error: parsedData.error.issues };
|
||||
}
|
||||
|
||||
const student = parsedData.data;
|
||||
|
||||
await db.update(students).set({
|
||||
rollNumber: student.rollNumber,
|
||||
firstName: student.firstName,
|
||||
middleName: student.middleName,
|
||||
lastName: student.lastName,
|
||||
mothersName: student.mothersName,
|
||||
gender: student.gender,
|
||||
dob: student.dob,
|
||||
personalGmail: student.personalGmail,
|
||||
phoneNumber: student.phoneNumber,
|
||||
address: student.address,
|
||||
degree: student.degree,
|
||||
branch: student.branch,
|
||||
year: student.year,
|
||||
skills: student.skills,
|
||||
linkedin: student.linkedin,
|
||||
github: student.github,
|
||||
ssc: String(student.ssc),
|
||||
hsc: String(student.hsc),
|
||||
isDiploma: student.isDiploma,
|
||||
}).where(eq(students.id, studentId));
|
||||
|
||||
}
|
||||
|
||||
@@ -26,39 +26,7 @@ import {
|
||||
SelectValue,
|
||||
} from '@workspace/ui/components/select';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@workspace/ui/components/card';
|
||||
|
||||
// Form schema
|
||||
const formSchema = z.object({
|
||||
// Personal Details
|
||||
firstName: z.string().min(1, 'First name is required'),
|
||||
lastName: z.string().min(1, 'Last name is required'),
|
||||
fathersName: z.string().optional(),
|
||||
mothersName: z.string().optional(),
|
||||
email: z.string().email('Invalid email address'),
|
||||
rollNumber: z.string().min(1, 'Roll number is required'),
|
||||
phoneNumber: z.string().min(10, 'Phone number must be at least 10 digits'),
|
||||
address: z.string().min(1, 'Address is required'),
|
||||
|
||||
// Academic Details
|
||||
degree: z.string().min(1, 'Degree is required'),
|
||||
year: z.string().min(1, 'Year is required'),
|
||||
branch: z.string().min(1, 'Branch is required'),
|
||||
ssc: z.string().min(1, 'SSC percentage is required'),
|
||||
hsc: z.string().min(1, 'HSC percentage is required'),
|
||||
|
||||
// Semester Grades
|
||||
sem1: z.string().min(1, 'Semester 1 grade is required'),
|
||||
sem1KT: z.string().min(1, 'Semester 1 KT status is required'),
|
||||
sem2: z.string().min(1, 'Semester 2 grade is required'),
|
||||
sem2KT: z.string().min(1, 'Semester 2 KT status is required'),
|
||||
|
||||
// Additional Details
|
||||
linkedin: z.string().url('Invalid LinkedIn URL'),
|
||||
github: z.string().url('Invalid GitHub URL'),
|
||||
skills: z.string().optional(),
|
||||
});
|
||||
|
||||
type FormData = z.infer<typeof formSchema>;
|
||||
import { studentSignupSchema, StudentSignup } from './schema';
|
||||
|
||||
const steps = [
|
||||
{
|
||||
@@ -84,8 +52,8 @@ export default function StudentRegistrationForm() {
|
||||
const [currentStep, setCurrentStep] = useState(1);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const form = useForm<FormData>({
|
||||
resolver: zodResolver(formSchema),
|
||||
const form = useForm<StudentSignup>({
|
||||
resolver: zodResolver(studentSignupSchema),
|
||||
defaultValues: {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
52
apps/student/app/signup/schema.ts
Normal file
52
apps/student/app/signup/schema.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const sgpiSchema = z.object({
|
||||
sem: z.number().min(1).max(8),
|
||||
sgpi: z.number().min(0).max(10),
|
||||
kt: z.boolean(),
|
||||
ktDead: z.boolean(),
|
||||
});
|
||||
|
||||
export const internshipSchema = z.object({
|
||||
title: z.string(),
|
||||
company: z.string(),
|
||||
description: z.string(),
|
||||
location: z.string(),
|
||||
startDate: z.coerce.date(),
|
||||
endDate: z.coerce.date(),
|
||||
});
|
||||
|
||||
export const resumeSchema = z.object({
|
||||
title: z.string(),
|
||||
link: z.string().url(),
|
||||
});
|
||||
|
||||
export const studentSignupSchema = z.object({
|
||||
rollNumber: z.string().max(12),
|
||||
firstName: z.string().max(255),
|
||||
middleName: z.string().max(255),
|
||||
lastName: z.string().max(255),
|
||||
mothersName: z.string().max(255),
|
||||
gender: z.string().max(10),
|
||||
dob: z.coerce.date(),
|
||||
personalGmail: z.string().email(),
|
||||
phoneNumber: z.string().max(10),
|
||||
address: z.string(),
|
||||
degree: z.string(),
|
||||
branch: z.string(),
|
||||
year: z.string(),
|
||||
skills: z.array(z.string()),
|
||||
linkedin: z.string(),
|
||||
github: z.string(),
|
||||
ssc: z.coerce.number(),
|
||||
hsc: z.coerce.number(),
|
||||
isDiploma: z.boolean(),
|
||||
sgpi: z.array(sgpiSchema),
|
||||
internships: z.array(internshipSchema).optional(),
|
||||
resume: z.array(resumeSchema).optional(),
|
||||
});
|
||||
|
||||
export type StudentSignup = z.infer<typeof studentSignupSchema>;
|
||||
export type Internship = z.infer<typeof internshipSchema>;
|
||||
export type Resume = z.infer<typeof resumeSchema>;
|
||||
export type SGPI = z.infer<typeof sgpiSchema>;
|
||||
@@ -10,6 +10,7 @@ declare module 'next-auth' {
|
||||
role?: 'ADMIN' | 'USER';
|
||||
adminId?: number;
|
||||
studentId?: number;
|
||||
completedProfile?: boolean;
|
||||
[key: string]: any;
|
||||
} & DefaultSession["user"];
|
||||
}
|
||||
@@ -18,6 +19,7 @@ declare module 'next-auth' {
|
||||
role?: 'ADMIN' | 'USER';
|
||||
adminId?: number;
|
||||
studentId?: number;
|
||||
completedProfile?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +32,14 @@ declare module 'next/server' {
|
||||
const authConfig: NextAuthConfig = {
|
||||
providers: [Google],
|
||||
callbacks: {
|
||||
async jwt({ token, account, user, profile }) {
|
||||
async jwt({ token, account, user }) {
|
||||
// Only check DB on first sign in
|
||||
if (account && user && user.email) {
|
||||
const admin = await db.select().from(admins).where(eq(admins.email, user.email)).limit(1);
|
||||
if (admin.length > 0 && admin[0]) {
|
||||
token.role = 'ADMIN';
|
||||
token.adminId = admin[0].id;
|
||||
token.completedProfile = true;
|
||||
} else {
|
||||
token.role = 'USER';
|
||||
const student = await db
|
||||
@@ -46,6 +49,7 @@ const authConfig: NextAuthConfig = {
|
||||
.limit(1);
|
||||
if (student.length > 0 && student[0]) {
|
||||
token.studentId = student[0].id;
|
||||
token.completedProfile = student[0].rollNumber ? true : false;
|
||||
} else {
|
||||
const nameParts = user.name?.split(' ') ?? [];
|
||||
const firstName = nameParts[0] || '';
|
||||
@@ -61,6 +65,7 @@ const authConfig: NextAuthConfig = {
|
||||
.returning({ id: students.id });
|
||||
if (newStudent[0]) {
|
||||
token.studentId = newStudent[0].id;
|
||||
token.completedProfile = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +82,9 @@ const authConfig: NextAuthConfig = {
|
||||
if (token?.studentId) {
|
||||
session.user.studentId = token.studentId as number;
|
||||
}
|
||||
if (token?.completedProfile !== undefined) {
|
||||
session.user.completedProfile = token.completedProfile as boolean;
|
||||
}
|
||||
return session;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -7,6 +7,11 @@ export default auth((req: NextRequest) => {
|
||||
}
|
||||
|
||||
if (req.auth.user?.role === 'USER') {
|
||||
if (!req.auth.user?.completedProfile && !req.nextUrl.pathname.startsWith('/signup')) {
|
||||
const signupUrl = process.env.STUDENT_PROFILE_URL ?? 'http://localhost:3000/signup';
|
||||
return NextResponse.redirect(new URL(signupUrl, req.url));
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user