AI slop goes brr

This commit is contained in:
Anushlinux
2025-07-03 01:11:57 +05:30
parent afd9bb194a
commit ef98f8e1ba
13 changed files with 799 additions and 114 deletions

View File

@@ -0,0 +1,80 @@
import { db, jobs, companies, applications, students } from '@workspace/db';
import { eq } from '@workspace/db/drizzle';
import { notFound } from 'next/navigation';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@workspace/ui/components/card';
import { Table, TableBody, TableHead, TableHeader, TableRow, TableCell } from '@workspace/ui/components/table';
interface JobPageProps {
params: { jobId: string };
}
export const dynamic = 'force-dynamic';
export default async function JobDetailPage({ params }: JobPageProps) {
const jobId = Number(params.jobId);
if (isNaN(jobId)) notFound();
const jobRes = await db.select().from(jobs).where(eq(jobs.id, jobId)).limit(1);
if (jobRes.length === 0) notFound();
const job = jobRes[0];
const companyRes = await db.select().from(companies).where(eq(companies.id, job.companyId)).limit(1);
const company = companyRes[0];
const applicants = await db
.select({
applicationId: applications.id,
status: applications.status,
firstName: students.firstName,
lastName: students.lastName,
email: students.email,
})
.from(applications)
.leftJoin(students, eq(applications.studentId, students.id))
.where(eq(applications.jobId, jobId));
return (
<div className="container mx-auto py-10 space-y-10">
<Card>
<CardHeader>
<CardTitle>{job.title}</CardTitle>
<CardDescription>Company: {company?.name ?? 'Unknown'}</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
<p className="text-sm"><strong>Location:</strong> {job.location}</p>
<p className="text-sm"><strong>Salary:</strong> {job.salary}</p>
<p className="text-sm"><strong>Deadline:</strong> {job.applicationDeadline.toLocaleDateString()}</p>
<p className="whitespace-pre-line mt-4">{job.description}</p>
</CardContent>
</Card>
<section className="space-y-4">
<h2 className="text-2xl font-semibold tracking-tight">Students Applied</h2>
{applicants.length === 0 ? (
<p className="text-muted-foreground text-sm">No applications yet.</p>
) : (
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Email</TableHead>
<TableHead>Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{applicants.map((a) => (
<TableRow key={a.applicationId}>
<TableCell>{`${a.firstName ?? ''} ${a.lastName ?? ''}`.trim()}</TableCell>
<TableCell>{a.email}</TableCell>
<TableCell className="capitalize">{a.status}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
)}
</section>
</div>
);
}

View File

@@ -0,0 +1,73 @@
import { db, jobs, companies } from '@workspace/db';
import { eq } from '@workspace/db/drizzle';
import Link from 'next/link';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@workspace/ui/components/card';
import { Button } from '@workspace/ui/components/button';
export const dynamic = 'force-dynamic';
async function getAllJobsWithCompany() {
const allJobs = await db.select().from(jobs);
const allCompanies = await db.select().from(companies);
return allJobs.map(job => ({
...job,
company: allCompanies.find(c => c.id === job.companyId) || null,
}));
}
export default async function JobsListPage() {
const jobsWithCompany = await getAllJobsWithCompany();
return (
<div className="container mx-auto py-10 space-y-8">
<h1 className="text-3xl font-bold mb-6">All Jobs</h1>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{jobsWithCompany.length === 0 && (
<p className="text-muted-foreground">No jobs found.</p>
)}
{jobsWithCompany.map((job) => (
<Card key={job.id} className="flex flex-col bg-white text-black border border-gray-200">
<CardHeader>
<CardTitle className="flex items-center gap-2">
<span>{job.title}</span>
<span className="ml-auto text-xs px-2 py-1 rounded bg-gray-100 border text-gray-600">
{job.active ? 'Active' : 'Inactive'}
</span>
</CardTitle>
<CardDescription>
<span>Company: {job.company?.name ?? 'Unknown'}</span>
</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
<div className="flex items-center gap-2">
<img src={job.company?.imageURL} alt={job.company?.name} className="w-10 h-10 rounded object-cover border" />
<div>
<div className="font-semibold">{job.company?.name}</div>
<div className="text-xs text-gray-500">{job.company?.email}</div>
</div>
</div>
<div className="mt-2">
<div className="text-sm"><strong>Location:</strong> {job.location}</div>
<div className="text-sm"><strong>Salary:</strong> {job.salary}</div>
<div className="text-sm"><strong>Deadline:</strong> {job.applicationDeadline.toLocaleDateString()}</div>
<div className="text-sm"><strong>Min CGPA:</strong> {job.minCGPA}</div>
<div className="text-sm"><strong>Min SSC:</strong> {job.minSSC}</div>
<div className="text-sm"><strong>Min HSC:</strong> {job.minHSC}</div>
<div className="text-sm"><strong>Allow Dead KT:</strong> {job.allowDeadKT ? 'Yes' : 'No'}</div>
<div className="text-sm"><strong>Allow Live KT:</strong> {job.allowLiveKT ? 'Yes' : 'No'}</div>
<div className="text-sm"><strong>Job Link:</strong> <a href={job.link} target="_blank" rel="noopener noreferrer" className="underline text-primary">{job.link}</a></div>
<div className="text-sm"><strong>Description:</strong> <span className="whitespace-pre-line">{job.description}</span></div>
<div className="text-xs text-gray-400 mt-2">Created: {job.createdAt.toLocaleDateString()} | Updated: {job.updatedAt.toLocaleDateString()}</div>
</div>
</CardContent>
<div className="p-4 pt-0 mt-auto flex gap-2">
<Link href={`/jobs/${job.id}`}>
<Button variant="outline" className="bg-white text-primary border-primary">View Details</Button>
</Link>
</div>
</Card>
))}
</div>
</div>
);
}

View File

@@ -9,28 +9,64 @@ import {
} from '@workspace/ui/components/navigation-menu';
import Link from 'next/link';
const navLinks = [
{ href: '/', label: 'Home', icon: '🏠' },
{ href: '/students', label: 'Students', icon: '🎓' },
{ href: '/jobs', label: 'Jobs', icon: '💼' },
];
export default function MainLayout({ children }: { children: React.ReactNode }) {
// Helper to check active link (client-side only)
const isActive = (href: string) => {
if (typeof window === 'undefined') return false;
if (href === '/') return window.location.pathname === '/';
return window.location.pathname.startsWith(href);
};
return (
<div>
<header className="flex h-16 items-center justify-between border-b bg-background px-4 md:px-6">
<nav>
<div className="flex min-h-screen bg-background text-foreground">
{/* Sidebar */}
<aside className="hidden md:flex flex-col w-64 p-6 gap-8">
<div className="sticky top-8">
<div className="flex flex-col gap-6 rounded-2xl shadow-xl bg-sidebar border border-sidebar-border p-6">
<div className="flex items-center gap-3 mb-6">
<img src="/favicon.ico" alt="Logo" className="w-10 h-10" />
<span className="font-extrabold text-xl tracking-tight text-sidebar-primary">Admin Portal</span>
</div>
<div className="text-xs uppercase font-semibold text-muted-foreground mb-2 tracking-widest pl-1">Navigation</div>
<nav className="flex flex-col gap-2">
{navLinks.map((link) => (
<Link
key={link.href}
href={link.href}
className="flex items-center gap-3 px-4 py-2 rounded-xl font-medium transition-colors text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-sidebar-accent data-[active=true]:bg-primary data-[active=true]:text-primary-foreground"
data-active={typeof window !== 'undefined' && isActive(link.href)}
>
<span className="text-lg">{link.icon}</span>
{link.label}
</Link>
))}
</nav>
</div>
</div>
</aside>
{/* Main content */}
<div className="flex-1 flex flex-col min-h-screen">
<header className="md:hidden flex items-center justify-between h-16 border-b bg-background px-4">
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuLink asChild>
<Link href="/">Home</Link>
</NavigationMenuLink>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink asChild>
<Link href="/students">Students</Link>
</NavigationMenuLink>
</NavigationMenuItem>
{navLinks.map((link) => (
<NavigationMenuItem key={link.href}>
<NavigationMenuLink asChild>
<Link href={link.href}>{link.label}</Link>
</NavigationMenuLink>
</NavigationMenuItem>
))}
</NavigationMenuList>
</NavigationMenu>
</nav>
</header>
<main>{children}</main>
</header>
<main className="flex-1 bg-background text-foreground p-4 md:p-10">{children}</main>
</div>
</div>
);
}

View File

@@ -1,26 +1,159 @@
import Studs from '@/components/studs';
import { db, students } from '@workspace/db';
import { auth, signOut } from '@/auth';
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@workspace/ui/components/card';
import { Input } from '@workspace/ui/components/input';
import { Textarea } from '@workspace/ui/components/textarea';
import { Button } from '@workspace/ui/components/button';
import Link from 'next/link';
import { revalidatePath } from 'next/cache';
import { db, companies, jobs } from '@workspace/db';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, DialogDescription } from '@workspace/ui/components/dialog';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@workspace/ui/components/accordion';
import { Badge } from '@workspace/ui/components/badge';
async function getStudents() {
// -----------------------
// Server Actions
// -----------------------
async function createCompany(formData: FormData) {
'use server';
const s = await db.select().from(students);
console.log(s);
const name = String(formData.get('name') ?? '').trim();
const email = String(formData.get('email') ?? '').trim();
const link = String(formData.get('link') ?? '').trim();
const description = String(formData.get('description') ?? '').trim() || 'N/A';
const imageURL = String(formData.get('imageURL') ?? '').trim() || 'https://via.placeholder.com/200x200?text=Company';
if (!name) return;
await db.insert(companies).values({ name, email, link, description, imageURL });
revalidatePath('/');
}
async function logOut() {
async function createJob(formData: FormData) {
'use server';
await signOut();
const companyId = Number(formData.get('companyId'));
const title = String(formData.get('title') ?? '').trim();
const link = String(formData.get('jobLink') ?? '').trim();
const description = String(formData.get('jobDescription') ?? '').trim() || 'N/A';
const location = String(formData.get('location') ?? '').trim() || 'N/A';
const imageURL = String(formData.get('jobImageURL') ?? '').trim() || 'https://via.placeholder.com/100x100?text=Job';
const salary = String(formData.get('salary') ?? '').trim() || 'N/A';
const deadlineRaw = formData.get('deadline');
const applicationDeadline = deadlineRaw ? new Date(String(deadlineRaw)) : new Date();
if (!companyId || !title) return;
await db.insert(jobs).values({
companyId,
title,
link,
description,
location,
imageURL,
salary,
applicationDeadline,
active: true,
});
revalidatePath('/');
}
export default async function Page() {
const session = await auth();
// -----------------------
// Component Helpers
// -----------------------
async function getDashboardData() {
const comps = await db.select().from(companies);
const allJobs = await db.select().from(jobs);
return comps.map((comp) => ({
...comp,
jobs: allJobs.filter((j) => j.companyId === comp.id),
}));
}
export default async function DashboardPage() {
const data = await getDashboardData();
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 admin {session?.user?.name}</h1>
<Studs action={getStudents} logOut={logOut} />
</div>
<div className="container mx-auto py-10 space-y-10">
<section className="flex justify-between items-center">
<div>
<h1 className="text-3xl font-bold text-primary">Companies Dashboard</h1>
<p className="text-muted-foreground mt-1">Manage companies and their job openings.</p>
</div>
<Dialog>
<DialogTrigger asChild>
<Button className="bg-primary text-primary-foreground hover:bg-primary/90 transition-colors">Add New Company</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Add a new company</DialogTitle>
<DialogDescription>
Fill in the details below to add a new company to the portal.
</DialogDescription>
</DialogHeader>
<form action={createCompany} className="grid grid-cols-1 gap-4 py-4">
<Input name="name" placeholder="Company name" required />
<Input name="email" placeholder="Contact email" type="email" required />
<Input name="link" placeholder="Website / careers link" />
<Input name="imageURL" placeholder="Image URL" />
<Textarea name="description" placeholder="Short description" />
<Button type="submit" className="w-fit">Add Company</Button>
</form>
</DialogContent>
</Dialog>
</section>
<section className="space-y-6">
{data.length === 0 && <Card className="p-10 text-muted-foreground text-center shadow-lg border-border bg-card">No companies yet. Add your first company to get started!</Card>}
<div className="grid gap-8 md:grid-cols-2 lg:grid-cols-3">
{data.map((company) => (
<Card key={company.id} className="flex flex-col shadow-xl border border-border bg-card rounded-2xl overflow-hidden">
<CardHeader className="p-6">
<CardTitle className="flex items-center gap-4">
<img src={company.imageURL} alt={company.name} className="w-14 h-14 rounded-xl border-2 border-border object-cover" />
<div>
<h3 className="font-bold text-lg">{company.name}</h3>
<a href={company.link} target="_blank" rel="noopener noreferrer" className="text-sm text-primary hover:underline">{company.link}</a>
</div>
</CardTitle>
</CardHeader>
<CardContent className="px-6 pb-2 space-y-3">
<h4 className="font-semibold text-muted-foreground">Open Positions</h4>
{company.jobs.length === 0 && <p className="text-sm text-muted-foreground/80">No jobs yet.</p>}
{company.jobs.map((job) => (
<Link key={job.id} href={`/jobs/${job.id}`} className="flex justify-between items-center p-3 rounded-lg hover:bg-background transition-colors border border-transparent hover:border-border">
<span>{job.title}</span>
<Badge variant={job.active ? "secondary" : "outline"}>{job.active ? "Active" : "Inactive"}</Badge>
</Link>
))}
</CardContent>
<CardFooter className="mt-auto p-0">
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="add-job">
<AccordionTrigger className="px-6 text-primary hover:text-primary/90 font-semibold">
Add New Job
</AccordionTrigger>
<AccordionContent className="p-6 bg-background border-t">
<form action={createJob} className="flex flex-col w-full gap-3">
<input type="hidden" name="companyId" value={company.id} />
<Input name="title" placeholder="Job title" required />
<Input name="jobLink" placeholder="Job link" />
<Input name="location" placeholder="Location" />
<Input name="salary" placeholder="Salary" />
<Input name="deadline" type="date" />
<Textarea name="jobDescription" placeholder="Job description" />
<Button type="submit" size="sm" className="bg-accent text-accent-foreground hover:bg-accent/90 transition-colors self-start">Add Job</Button>
</form>
</AccordionContent>
</AccordionItem>
</Accordion>
</CardFooter>
</Card>
))}
</div>
</section>
</div>
);
}
export const dynamic = 'force-dynamic';

View File

@@ -1,26 +1,61 @@
import { columns, Student } from './columns';
import { DataTable } from './data-table';
import { db, students } from '@workspace/db';
import { Input } from '@workspace/ui/components/input';
import { Button } from '@workspace/ui/components/button';
import { revalidatePath } from 'next/cache';
import { eq } from '@workspace/db/drizzle';
import { Card } from '@workspace/ui/components/card';
async function getData(): Promise<Student[]> {
const data = await db.select().from(students);
return data;
}
async function addStudent(formData: FormData) {
'use server';
const email = String(formData.get('email') ?? '').trim();
if (!email) return;
const exists = await db.select().from(students).where(eq(students.email, email)).limit(1);
if (exists.length === 0) {
await db.insert(students).values({ email });
}
revalidatePath('/students');
}
async function StudentsTable() {
const data = await getData();
return (
<div className="container mx-auto py-10">
<div className="space-y-4">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-semibold tracking-tight">Students</h1>
<div className="text-sm text-muted-foreground">
{data.length} {data.length === 1 ? 'student' : 'students'} total
<div className="space-y-8">
{/* Add Student */}
<Card className="p-6 shadow-md border border-border bg-card">
<h2 className="text-2xl font-bold mb-4 text-primary">Add Student</h2>
<form action={addStudent} className="flex gap-2 items-end">
<Input name="email" type="email" placeholder="Student email" className="max-w-sm" required />
<Button type="submit" className="bg-primary text-primary-foreground hover:bg-primary/90 transition-colors">Add Student</Button>
</form>
</Card>
{/* Students Table */}
<Card className="p-6 shadow-md border border-border bg-card">
<div className="flex items-center justify-between mb-4">
<h1 className="text-2xl font-semibold tracking-tight text-accent">Students</h1>
<div className="text-sm text-muted-foreground">
{data.length} {data.length === 1 ? 'student' : 'students'} total
</div>
</div>
</div>
<DataTable columns={columns} data={data} />
{data.length === 0 ? (
<div className="text-center text-muted-foreground">No students yet. Add your first student above!</div>
) : (
<DataTable columns={columns} data={data} />
)}
</Card>
</div>
{/* Toast placeholder for feedback */}
</div>
);
}