Skip to content

Commit dbbeaaa

Browse files
Fix stillingsannonser
1 parent 22b45b4 commit dbbeaaa

3 files changed

Lines changed: 78 additions & 4 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { getJobAdvertBySlug } from "@/sanity/queries/jobAdvert"
2+
import { bigIconSize, DateIcon } from "@/components/icons/icon"
3+
import { notFound } from "next/navigation"
4+
import SingleInfoCard from "@/components/cards/singleInfoCard"
5+
import { type Metadata } from "next"
6+
import { Date } from "@/components/date"
7+
import { toPlainText } from "@portabletext/react"
8+
9+
interface Params {
10+
slug: string
11+
}
12+
13+
export const revalidate = 30 // 30 sek
14+
15+
/**
16+
* Side for en enkelt stillingsannose. Siden er dynamisk basert på stillingens slug variabel.
17+
* Dersom slug ikke finnes, returneres en 404 side.
18+
* @param params Parametre fra URL
19+
*/
20+
const JobAdvertPage: AsyncPage<Params> = async ({ params }) => {
21+
const ad = await getJobAdvertBySlug(params.slug)
22+
23+
if (!ad) return notFound()
24+
25+
return (
26+
<SingleInfoCard
27+
title={ad.title}
28+
descriptionBlock={ad.description_block}
29+
image={ad.image}
30+
maxParticipants={
31+
ad.number_of_positions
32+
? `Antall stillinger er ${ad.number_of_positions}`
33+
: undefined
34+
}
35+
buttonText={"Søk"}
36+
buttonUrl={ad.link}>
37+
<Deadline deadline={ad.deadline}>Søknadsfrist:</Deadline>
38+
</SingleInfoCard>
39+
)
40+
}
41+
42+
export default JobAdvertPage
43+
44+
const Deadline: Component<{ deadline?: string } & ChildProps> = ({ deadline, children }) => {
45+
if (!deadline) {
46+
return (
47+
<DateIcon title={`Søknadsfrist`} width={bigIconSize}>
48+
Opptak skjer fortløpende
49+
</DateIcon>
50+
)
51+
}
52+
return (
53+
<DateIcon title={`Søknadsfrist ${deadline}`} width={bigIconSize}>
54+
{children} <Date date={deadline} />
55+
</DateIcon>
56+
)
57+
}
58+
59+
/**
60+
* Genererer metadata for en enkelt stillingsannonse.
61+
* Kjøres ved bygging av nettsiden.
62+
* @param props Props som sendes til siden
63+
* @returns Metadata for siden
64+
* @see https://nextjs.org/docs/app/building-your-application/optimizing/metadata#dynamic-metadata
65+
*/
66+
export async function generateMetadata(props: PageProps<Params>): Promise<Metadata> {
67+
const ad = await getJobAdvertBySlug(props.params.slug)
68+
69+
if (!ad) return notFound()
70+
71+
return {
72+
title: `${ad.title} | Root Linjeforening`,
73+
description: ad.description_block ? toPlainText(ad.description_block) : "Stillingsannonse",
74+
}
75+
}

components/cards/adsCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ export const SingleAdWide: Component<JobAdvert & DefaultProps> = ({
5858
}) => (
5959
<div className={`mx-2 my-5 justify-between gap-3 ${className}`}>
6060
<div>
61-
<Link href={`bedrifter/stillingsannonser/${slug.current}`}>
61+
<Link href={`stilling/${slug.current}`}>
6262
<h3 className={"text-base text-root-primary dark:text-root-light"}>{title}</h3>
6363
</Link>
6464

6565
<DateIcon>{deadline ? <Date deadline={deadline} /> : <p>Løpende opptak</p>}</DateIcon>
6666
</div>
6767

6868
{image && (
69-
<Link href={`bedrifter/stillingsannonser/${slug.current}`}>
69+
<Link href={`stilling/${slug.current}`}>
7070
<Thumbnail image={image} />
7171
</Link>
7272
)}
@@ -81,7 +81,7 @@ export const SingleAdNarrow: Component<JobAdvert & DefaultProps> = ({
8181
slug,
8282
}) => (
8383
<div className={`mx-1 my-5 w-full flex-col ${className}`}>
84-
<Link href={`bedrifter/stillingsannonser/${slug.current}`}>
84+
<Link href={`stilling/${slug.current}`}>
8585
<h3 className={"text-base text-root-primary dark:text-root-light"}>{title}</h3>
8686
</Link>
8787
<div className={"flex justify-between"}>

components/imageViewer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const ImageViewer = ({ image }: { image?: SanityImageObject }) => {
1212

1313
if (!image?.asset) return null
1414

15-
// ✅ Detect if image is an SVG (Sanity asset ref ends in -svg)
1615
const isSVG = image.asset._ref?.includes("-svg")
1716

1817
const imageUrl = urlFor(image).url()

0 commit comments

Comments
 (0)