feat(student): fixed greydout botton in jobs application

This commit is contained in:
Unchanted
2025-08-21 14:02:41 +05:30
parent 8bfe681dd4
commit 42a511ccb6
4 changed files with 70 additions and 36 deletions

View File

@@ -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' };
}
}

View File

@@ -46,10 +46,12 @@ export default function JobsPage({
jobs,
resumes,
studentId,
appliedJobIds = [],
}: {
jobs: Job[];
resumes: Resume[];
studentId: number;
appliedJobIds?: number[];
}) {
const [filteredJobs, setFilteredJobs] = useState<Job[]>([]);
const [searchTerm, setSearchTerm] = useState('');

View File

@@ -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 <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} />;
}

View File

@@ -18,30 +18,40 @@ import {
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,
CheckCircle,
FileText,
Upload,
AlertCircle
} from "lucide-react"
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<string>('');
const [isApplying, setIsApplying] = useState(false);