diff --git a/apps/student/app/(main)/actions.ts b/apps/student/app/(main)/actions.ts index e6be2f0..5fe9baf 100644 --- a/apps/student/app/(main)/actions.ts +++ b/apps/student/app/(main)/actions.ts @@ -140,3 +140,20 @@ export async function getResumes(studentId: number) { return { success: false, error: 'Failed to fetch resumes' }; } } + +export async function getStudentApplicationJobIds(studentId: number) { + try { + const studentApplications = await db.query.applications.findMany({ + where: eq(applications.studentId, studentId), + columns: { + jobId: true, + }, + }); + + const appliedJobIds = studentApplications.map(app => app.jobId); + return { success: true, appliedJobIds }; + } catch (error) { + console.error('Error fetching student applied job IDs:', error); + return { success: false, error: 'Failed to fetch applied job IDs' }; + } +} diff --git a/apps/student/app/(main)/jobs/JobClient.tsx b/apps/student/app/(main)/jobs/JobClient.tsx index b368e4e..9128b15 100644 --- a/apps/student/app/(main)/jobs/JobClient.tsx +++ b/apps/student/app/(main)/jobs/JobClient.tsx @@ -46,10 +46,12 @@ export default function JobsPage({ jobs, resumes, studentId, + appliedJobIds = [], }: { jobs: Job[]; resumes: Resume[]; studentId: number; + appliedJobIds?: number[]; }) { const [filteredJobs, setFilteredJobs] = useState([]); const [searchTerm, setSearchTerm] = useState(''); diff --git a/apps/student/app/(main)/jobs/page.tsx b/apps/student/app/(main)/jobs/page.tsx index add5f78..b943875 100644 --- a/apps/student/app/(main)/jobs/page.tsx +++ b/apps/student/app/(main)/jobs/page.tsx @@ -2,6 +2,7 @@ import JobsClient from './JobClient'; import { auth } from '@/auth'; import { db, resumes } from '@workspace/db'; import { eq } from '@workspace/db/drizzle'; +import { getStudentApplicationJobIds } from '../actions'; export default async function JobsPage() { const session = await auth(); @@ -13,5 +14,9 @@ export default async function JobsPage() { }); let reusmes = await db.select().from(resumes).where(eq(resumes.studentId, studentId)); - return ; + // Get student's applied job IDs + const { success, appliedJobIds } = await getStudentApplicationJobIds(studentId); + const studentAppliedJobIds = success ? appliedJobIds : []; + + return ; } diff --git a/apps/student/components/job-application-modal.tsx b/apps/student/components/job-application-modal.tsx index ac58b2d..c033099 100644 --- a/apps/student/components/job-application-modal.tsx +++ b/apps/student/components/job-application-modal.tsx @@ -6,11 +6,36 @@ import { Button } from "@workspace/ui/components/button" import { Badge } from "@workspace/ui/components/badge" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@workspace/ui/components/dialog" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@workspace/ui/components/select" -import { - Building2, - MapPin, - DollarSign, - Calendar, +import { + Building2, + MapPin, + DollarSign, + Calendar, + Star, + CheckCircle, + FileText, + Upload, + AlertCircle +} from "lucide-react" +import { applyForJob } from "../app/(main)/actions" +import { type InferSelectModel } from '@workspace/db/drizzle'; +import { jobs, companies, resumes } from '@workspace/db/schema'; + +export type Job = InferSelectModel & { + company: typeof companies.$inferSelect; +}; + +export type Resume = typeof resumes.$inferSelect;t { useState } from 'react'; +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 { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@workspace/ui/components/dialog" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@workspace/ui/components/select" +import { + Building2, + MapPin, + DollarSign, + Calendar, Star, CheckCircle, FileText, @@ -20,28 +45,13 @@ import { import { applyForJob } from "../app/(main)/actions" interface JobApplicationModalProps { - job: { - id: number; - title: string; - company: { - name: string; - }; - location: string; - salary: string; - description: string; - applicationDeadline: Date; - minCGPA: number; - link?: string; - }; + job: Job & { minCGPA: number }; studentId: number; - resumes: Array<{ - id: number; - title: string; - link: string; - }>; + resumes: Resume[]; + isApplied?: boolean; } -export default function JobApplicationModal({ job, studentId, resumes }: JobApplicationModalProps) { +export default function JobApplicationModal({ job, studentId, resumes, isApplied = false }: JobApplicationModalProps) { const [isOpen, setIsOpen] = useState(false); const [selectedResume, setSelectedResume] = useState(''); const [isApplying, setIsApplying] = useState(false); @@ -58,7 +68,7 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl try { const result = await applyForJob(job.id, studentId, parseInt(selectedResume)); - + if (result.success) { setMessage({ type: 'success', text: 'Application submitted successfully!' }); setTimeout(() => { @@ -81,8 +91,8 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl return ( - - ); -} \ No newline at end of file +}