|
| 1 | +import React from 'react' |
| 2 | +import Link from 'next/link' |
| 3 | +import { notFound } from 'next/navigation' |
| 4 | +import prisma from '@/lib/db' |
| 5 | +import { Prisma } from '@prisma/client' |
| 6 | +import JobDetails from '@/components/jobs/JobDetails' |
| 7 | + |
| 8 | +// Type for job with relations |
| 9 | +type JobWithRelations = Prisma.JobGetPayload<{ |
| 10 | + include: { |
| 11 | + company: true |
| 12 | + tags: { include: { tag: true } } |
| 13 | + metadata: true |
| 14 | + sources: true |
| 15 | + } |
| 16 | +}> |
| 17 | + |
| 18 | +interface JobPageProps { |
| 19 | + params: Promise<{ id: string }> |
| 20 | +} |
| 21 | + |
| 22 | +export default async function JobPage({ params }: JobPageProps) { |
| 23 | + const { id } = await params |
| 24 | + const jobId = parseInt(id, 10) |
| 25 | + |
| 26 | + if (isNaN(jobId)) { |
| 27 | + notFound() |
| 28 | + } |
| 29 | + |
| 30 | + const job = (await prisma.job.findUnique({ |
| 31 | + where: { id: jobId }, |
| 32 | + include: { |
| 33 | + company: true, |
| 34 | + tags: { include: { tag: true } }, |
| 35 | + metadata: true, |
| 36 | + sources: true, |
| 37 | + }, |
| 38 | + })) as JobWithRelations | null |
| 39 | + |
| 40 | + if (!job) { |
| 41 | + notFound() |
| 42 | + } |
| 43 | + |
| 44 | + await prisma.$disconnect() |
| 45 | + |
| 46 | + return ( |
| 47 | + <div className="flex flex-col inset-0 z-50 bg-primary transition-transform"> |
| 48 | + <section className={`bg-gray-100 py-4 md:py-6`}> |
| 49 | + <div className="container mx-auto py-16 px-8 md:px-20 lg:px-32"> |
| 50 | + {/* Navigation */} |
| 51 | + <nav className="mb-6"> |
| 52 | + <Link |
| 53 | + href="/jobs" |
| 54 | + className="text-blue-600 hover:text-blue-800 transition-colors duration-200" |
| 55 | + > |
| 56 | + ← Back to Jobs |
| 57 | + </Link> |
| 58 | + </nav> |
| 59 | + |
| 60 | + {/* Job Details */} |
| 61 | + <JobDetails job={job} /> |
| 62 | + </div> |
| 63 | + </section> |
| 64 | + </div> |
| 65 | + ) |
| 66 | +} |
| 67 | + |
| 68 | +// Generate metadata for SEO |
| 69 | +export async function generateMetadata({ params }: JobPageProps) { |
| 70 | + const { id } = await params |
| 71 | + const jobId = parseInt(id, 10) |
| 72 | + |
| 73 | + if (isNaN(jobId)) { |
| 74 | + return { |
| 75 | + title: 'Job Not Found', |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + const job = await prisma.job.findUnique({ |
| 80 | + where: { id: jobId }, |
| 81 | + select: { |
| 82 | + title: true, |
| 83 | + company: { select: { name: true } }, |
| 84 | + description: true, |
| 85 | + }, |
| 86 | + }) |
| 87 | + |
| 88 | + if (!job) { |
| 89 | + return { |
| 90 | + title: 'Job Not Found', |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + const companyName = job.company?.name || 'Unknown Company' |
| 95 | + const title = `${job.title} - ${companyName}` |
| 96 | + const description = |
| 97 | + job.description?.substring(0, 160) || `${job.title} job opportunity at ${companyName}` |
| 98 | + |
| 99 | + return { |
| 100 | + title, |
| 101 | + description, |
| 102 | + openGraph: { |
| 103 | + title, |
| 104 | + description, |
| 105 | + type: 'website', |
| 106 | + }, |
| 107 | + } |
| 108 | +} |
0 commit comments