From 3bcb5b851d2a2cb4ef38b4c9774ee9f2c7f8f1a5 Mon Sep 17 00:00:00 2001 From: Mohak Jaiswal Date: Sat, 3 Jan 2026 19:29:52 +0530 Subject: [PATCH] Fix deadline handling and prevent invalid job application modal access --- .../components/job-application-modal.tsx | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/apps/student/components/job-application-modal.tsx b/apps/student/components/job-application-modal.tsx index 6d38e6d..cd9f91f 100644 --- a/apps/student/components/job-application-modal.tsx +++ b/apps/student/components/job-application-modal.tsx @@ -40,6 +40,9 @@ export default function JobApplicationModal({ job, studentId, resumes, isApplied const [isPending, startTransition] = useTransition(); const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null); + const deadline = new Date(job.applicationDeadline); + const isDeadlinePassed = new Date() > deadline; + const handleApply = async () => { if (!selectedResume) { setMessage({ type: 'error', text: 'Please select a resume' }); @@ -63,12 +66,14 @@ export default function JobApplicationModal({ job, studentId, resumes, isApplied setMessage({ type: 'error', text: result.error || 'Failed to submit application' }); } } catch (error) { - setMessage({ type: 'error', text: 'An error occurred while submitting your application' }); + setMessage({ + type: 'error', + text: error instanceof Error ? error.message : 'An error occurred while submitting your application' + }); } }); }; - const isDeadlinePassed = new Date() > new Date(job.applicationDeadline as any); const cannotApplyReason = isApplied ? 'You have already applied to this job' : resumes.length === 0 @@ -78,21 +83,33 @@ export default function JobApplicationModal({ job, studentId, resumes, isApplied : null; return ( - - + !isPending && setIsOpen(open)}> + {!cannotApplyReason && ( + +
+ +
+
+ )} + + {cannotApplyReason && (
- {cannotApplyReason && ( - {cannotApplyReason} - )} + {cannotApplyReason}
-
+ )} + @@ -127,7 +144,7 @@ export default function JobApplicationModal({ job, studentId, resumes, isApplied
- Deadline: {job.applicationDeadline.toLocaleDateString()} + Deadline: {deadline.toLocaleDateString()}
@@ -162,6 +179,18 @@ export default function JobApplicationModal({ job, studentId, resumes, isApplied ))} + + {selectedResume && ( + r.id.toString() === selectedResume)?.fileUrl} + target="_blank" + rel="noopener noreferrer" + className="text-sm text-blue-600 underline mt-2 inline-block" + > + Preview selected resume + + )} + {resumes.length === 0 && (

No resumes found. Please upload a resume first. @@ -171,11 +200,10 @@ export default function JobApplicationModal({ job, studentId, resumes, isApplied {/* Message Display */} {message && ( -

+ }`}>
{message.type === 'success' ? (