'use client'; import { 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, 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; interface JobApplicationModalProps { job: Job & { minCGPA: number }; studentId: number; resumes: Resume[]; isApplied?: boolean; } export default function JobApplicationModal({ job, studentId, resumes, isApplied = false }: JobApplicationModalProps) { const [isOpen, setIsOpen] = useState(false); const [selectedResume, setSelectedResume] = useState(''); const [isApplying, setIsApplying] = useState(false); const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null); const handleApply = async () => { if (!selectedResume) { setMessage({ type: 'error', text: 'Please select a resume' }); return; } setIsApplying(true); setMessage(null); try { const result = await applyForJob(job.id, studentId, parseInt(selectedResume)); if (result.success) { setMessage({ type: 'success', text: 'Application submitted successfully!' }); setTimeout(() => { setIsOpen(false); setMessage(null); setSelectedResume(''); }, 2000); } else { setMessage({ type: 'error', text: result.error || 'Failed to submit application' }); } } catch (error) { setMessage({ type: 'error', text: 'An error occurred while submitting your application' }); } finally { setIsApplying(false); } }; const isDeadlinePassed = new Date() > job.applicationDeadline; return ( Apply for {job.title}
{/* Job Details */}

{job.title}

{job.company.name}

Active
{job.location}
{job.salary}
Deadline: {job.applicationDeadline.toLocaleDateString()}
Min CGPA: {job.minCGPA}

{job.description}

{/* Application Form */}

Application Details

{resumes.length === 0 && (

No resumes found. Please upload a resume first.

)}
{/* Message Display */} {message && (
{message.type === 'success' ? ( ) : ( )} {message.text}
)} {/* Action Buttons */}
{/* Additional Info */}
Important Notes:
  • • Make sure your resume is up-to-date and relevant to this position
  • • You can only apply once per job posting
  • • Applications will be reviewed by the company within 1-2 weeks
  • • You'll receive email notifications about your application status
); }