|
| 1 | +import { notFound, redirect } from 'next/navigation'; |
| 2 | +import type { Metadata } from 'next'; |
| 3 | +import { createMetadata } from '@/utils/metadata'; |
| 4 | +import { getAuthSession } from '@/lib/auth/authSession'; |
| 5 | +import { prisma } from '@/prisma/prisma'; |
| 6 | +import { getListingForEdit } from '@/server/services/ecosystemCareers/queries'; |
| 7 | +import { SubmitListingForm } from '@/components/ecosystem-careers/SubmitListingForm'; |
| 8 | +import '@/components/profile/shell/styles.css'; |
| 9 | + |
| 10 | +export const metadata: Metadata = createMetadata({ |
| 11 | + title: 'Edit listing · Ecosystem Careers', |
| 12 | +}); |
| 13 | + |
| 14 | +interface Params { |
| 15 | + params: Promise<{ id: string }>; |
| 16 | +} |
| 17 | + |
| 18 | +export default async function EditListingPage({ params }: Params) { |
| 19 | + const { id } = await params; |
| 20 | + const session = await getAuthSession(); |
| 21 | + if (!session?.user?.id) { |
| 22 | + redirect(`/login?callbackUrl=/ecosystem-careers/${id}/edit`); |
| 23 | + } |
| 24 | + |
| 25 | + const listing = await getListingForEdit(id, session.user.id); |
| 26 | + if (!listing || !listing.projectId) notFound(); |
| 27 | + |
| 28 | + const project = await prisma.project.findUnique({ |
| 29 | + where: { id: listing.projectId }, |
| 30 | + select: { id: true, project_name: true, logo_url: true }, |
| 31 | + }); |
| 32 | + if (!project) notFound(); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="profile"> |
| 36 | + <main className="pr-page" style={{ maxWidth: 720, margin: '0 auto', padding: '32px 16px 96px' }}> |
| 37 | + <header className="pr-page-head"> |
| 38 | + <div> |
| 39 | + <h1 className="pr-ttl">Edit listing</h1> |
| 40 | + <p className="pr-sub"> |
| 41 | + Updating “{listing.title}” for {project.project_name}. |
| 42 | + </p> |
| 43 | + </div> |
| 44 | + </header> |
| 45 | + <SubmitListingForm |
| 46 | + projects={[project]} |
| 47 | + listingId={listing.id} |
| 48 | + initialValues={{ |
| 49 | + project_id: project.id, |
| 50 | + title: listing.title, |
| 51 | + short_description: listing.shortDescription, |
| 52 | + description: listing.description ?? '', |
| 53 | + location: listing.location ?? '', |
| 54 | + remote_type: |
| 55 | + (listing.remoteType as 'remote' | 'onsite' | 'hybrid' | null) ?? '', |
| 56 | + employment_type: |
| 57 | + (listing.employmentType as 'full_time' | 'contract' | 'part_time' | null) ?? '', |
| 58 | + seniority: extractYears(listing.seniority), |
| 59 | + tags: listing.tags.join(', '), |
| 60 | + apply_url: listing.applyUrl, |
| 61 | + }} |
| 62 | + /> |
| 63 | + </main> |
| 64 | + </div> |
| 65 | + ); |
| 66 | +} |
| 67 | + |
| 68 | +function extractYears(stored: string | null): string { |
| 69 | + if (!stored) return ''; |
| 70 | + const m = stored.match(/^(\d{1,2})\+\s*years?$/i); |
| 71 | + return m ? m[1] : ''; |
| 72 | +} |
0 commit comments