feat(student): fixed greydout botton in jobs application
This commit is contained in:
@@ -140,3 +140,20 @@ export async function getResumes(studentId: number) {
|
|||||||
return { success: false, error: 'Failed to fetch resumes' };
|
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' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,10 +46,12 @@ export default function JobsPage({
|
|||||||
jobs,
|
jobs,
|
||||||
resumes,
|
resumes,
|
||||||
studentId,
|
studentId,
|
||||||
|
appliedJobIds = [],
|
||||||
}: {
|
}: {
|
||||||
jobs: Job[];
|
jobs: Job[];
|
||||||
resumes: Resume[];
|
resumes: Resume[];
|
||||||
studentId: number;
|
studentId: number;
|
||||||
|
appliedJobIds?: number[];
|
||||||
}) {
|
}) {
|
||||||
const [filteredJobs, setFilteredJobs] = useState<Job[]>([]);
|
const [filteredJobs, setFilteredJobs] = useState<Job[]>([]);
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import JobsClient from './JobClient';
|
|||||||
import { auth } from '@/auth';
|
import { auth } from '@/auth';
|
||||||
import { db, resumes } from '@workspace/db';
|
import { db, resumes } from '@workspace/db';
|
||||||
import { eq } from '@workspace/db/drizzle';
|
import { eq } from '@workspace/db/drizzle';
|
||||||
|
import { getStudentApplicationJobIds } from '../actions';
|
||||||
|
|
||||||
export default async function JobsPage() {
|
export default async function JobsPage() {
|
||||||
const session = await auth();
|
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));
|
let reusmes = await db.select().from(resumes).where(eq(resumes.studentId, studentId));
|
||||||
|
|
||||||
return <JobsClient jobs={jobs} resumes={reusmes} studentId={studentId} />;
|
// Get student's applied job IDs
|
||||||
|
const { success, appliedJobIds } = await getStudentApplicationJobIds(studentId);
|
||||||
|
const studentAppliedJobIds = success ? appliedJobIds : [];
|
||||||
|
|
||||||
|
return <JobsClient jobs={jobs} resumes={reusmes} studentId={studentId} appliedJobIds={studentAppliedJobIds} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,36 @@ import { Button } from "@workspace/ui/components/button"
|
|||||||
import { Badge } from "@workspace/ui/components/badge"
|
import { Badge } from "@workspace/ui/components/badge"
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@workspace/ui/components/dialog"
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@workspace/ui/components/dialog"
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@workspace/ui/components/select"
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@workspace/ui/components/select"
|
||||||
import {
|
import {
|
||||||
Building2,
|
Building2,
|
||||||
MapPin,
|
MapPin,
|
||||||
DollarSign,
|
DollarSign,
|
||||||
Calendar,
|
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<typeof jobs> & {
|
||||||
|
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,
|
Star,
|
||||||
CheckCircle,
|
CheckCircle,
|
||||||
FileText,
|
FileText,
|
||||||
@@ -20,28 +45,13 @@ import {
|
|||||||
import { applyForJob } from "../app/(main)/actions"
|
import { applyForJob } from "../app/(main)/actions"
|
||||||
|
|
||||||
interface JobApplicationModalProps {
|
interface JobApplicationModalProps {
|
||||||
job: {
|
job: Job & { minCGPA: number };
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
company: {
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
location: string;
|
|
||||||
salary: string;
|
|
||||||
description: string;
|
|
||||||
applicationDeadline: Date;
|
|
||||||
minCGPA: number;
|
|
||||||
link?: string;
|
|
||||||
};
|
|
||||||
studentId: number;
|
studentId: number;
|
||||||
resumes: Array<{
|
resumes: Resume[];
|
||||||
id: number;
|
isApplied?: boolean;
|
||||||
title: string;
|
|
||||||
link: string;
|
|
||||||
}>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function JobApplicationModal({ job, studentId, resumes }: JobApplicationModalProps) {
|
export default function JobApplicationModal({ job, studentId, resumes, isApplied = false }: JobApplicationModalProps) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [selectedResume, setSelectedResume] = useState<string>('');
|
const [selectedResume, setSelectedResume] = useState<string>('');
|
||||||
const [isApplying, setIsApplying] = useState(false);
|
const [isApplying, setIsApplying] = useState(false);
|
||||||
@@ -58,7 +68,7 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await applyForJob(job.id, studentId, parseInt(selectedResume));
|
const result = await applyForJob(job.id, studentId, parseInt(selectedResume));
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
setMessage({ type: 'success', text: 'Application submitted successfully!' });
|
setMessage({ type: 'success', text: 'Application submitted successfully!' });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -81,8 +91,8 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
return (
|
return (
|
||||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
className="bg-blue-600 hover:bg-blue-700"
|
className="bg-blue-600 hover:bg-blue-700"
|
||||||
disabled={isDeadlinePassed}
|
disabled={isDeadlinePassed}
|
||||||
>
|
>
|
||||||
@@ -111,7 +121,7 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
Active
|
Active
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4 text-sm text-gray-600">
|
<div className="grid grid-cols-2 gap-4 text-sm text-gray-600">
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<MapPin className="w-4 h-4" />
|
<MapPin className="w-4 h-4" />
|
||||||
@@ -138,7 +148,7 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
{/* Application Form */}
|
{/* Application Form */}
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h4 className="font-semibold text-gray-900">Application Details</h4>
|
<h4 className="font-semibold text-gray-900">Application Details</h4>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||||
Select Resume *
|
Select Resume *
|
||||||
@@ -168,8 +178,8 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
{/* Message Display */}
|
{/* Message Display */}
|
||||||
{message && (
|
{message && (
|
||||||
<div className={`p-3 rounded-lg ${
|
<div className={`p-3 rounded-lg ${
|
||||||
message.type === 'success'
|
message.type === 'success'
|
||||||
? 'bg-green-100 text-green-700 border border-green-200'
|
? 'bg-green-100 text-green-700 border border-green-200'
|
||||||
: 'bg-red-100 text-red-700 border border-red-200'
|
: 'bg-red-100 text-red-700 border border-red-200'
|
||||||
}`}>
|
}`}>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
@@ -185,15 +195,15 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
|
|
||||||
{/* Action Buttons */}
|
{/* Action Buttons */}
|
||||||
<div className="flex gap-3 pt-4">
|
<div className="flex gap-3 pt-4">
|
||||||
<Button
|
<Button
|
||||||
onClick={handleApply}
|
onClick={handleApply}
|
||||||
disabled={isApplying || resumes.length === 0}
|
disabled={isApplying || resumes.length === 0}
|
||||||
className="flex-1 bg-blue-600 hover:bg-blue-700"
|
className="flex-1 bg-blue-600 hover:bg-blue-700"
|
||||||
>
|
>
|
||||||
{isApplying ? 'Submitting...' : 'Submit Application'}
|
{isApplying ? 'Submitting...' : 'Submit Application'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => setIsOpen(false)}
|
onClick={() => setIsOpen(false)}
|
||||||
disabled={isApplying}
|
disabled={isApplying}
|
||||||
>
|
>
|
||||||
@@ -216,4 +226,4 @@ export default function JobApplicationModal({ job, studentId, resumes }: JobAppl
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user