diff --git a/src/app/(main)/[slug]/page.tsx b/src/app/(main)/[slug]/page.tsx index 0e9deffa3..cf9988578 100644 --- a/src/app/(main)/[slug]/page.tsx +++ b/src/app/(main)/[slug]/page.tsx @@ -2,12 +2,12 @@ import { Metadata } from "next"; import { redirect } from "next/navigation"; import { Blog } from "src/blog/Blog"; import BlogPreview from "src/blog/BlogPreview"; -import SalaryAndBenefits from 'src/salaryAndBenefits/SalaryAndBenefits'; +import SalaryAndBenefits from "src/salaryAndBenefits/SalaryAndBenefits"; import { getDraftModeInfo } from "src/utils/draftmode"; import SectionRenderer from "src/utils/renderSection"; import { fetchSeoData, generateMetadataFromSeo } from "src/utils/seo"; import { BlogPage, PageBuilder, Post } from "studio/lib/payloads/pages"; -import { SalaryAndBenefits as SalaryAndBenefitsPayload } from 'studio/lib/payloads/salaryAndBenefits'; +import { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits"; import { BLOG_PAGE_QUERY, POSTS_QUERY, @@ -36,13 +36,22 @@ async function Page({ params }: Props) { const { slug } = params; const { perspective, isDraftMode } = getDraftModeInfo(); - const [initialPage, initialBlogPage, initialSalaryAndBenefitsPage] = await Promise.all([ - loadQuery(SLUG_QUERY, { slug }, { perspective }), - loadQuery(BLOG_PAGE_QUERY, { slug }, { perspective }), - loadQuery(SALARY_AND_BENEFITS_PAGE_QUERY, { slug }, { perspective }), - ]); + const [initialPage, initialBlogPage, initialSalaryAndBenefitsPage] = + await Promise.all([ + loadQuery(SLUG_QUERY, { slug }, { perspective }), + loadQuery(BLOG_PAGE_QUERY, { slug }, { perspective }), + loadQuery( + SALARY_AND_BENEFITS_PAGE_QUERY, + { slug }, + { perspective }, + ), + ]); - if (!initialPage.data && !initialBlogPage.data && !initialSalaryAndBenefitsPage.data) { + if ( + !initialPage.data && + !initialBlogPage.data && + !initialSalaryAndBenefitsPage.data + ) { console.log(`Page ${slug} not found`); // TODO: add error snackbar redirect("/"); @@ -53,7 +62,7 @@ async function Page({ params }: Props) { const initialPosts = await loadQuery( POSTS_QUERY, { slug }, - { perspective } + { perspective }, ); if (!initialPosts) { @@ -95,9 +104,13 @@ async function Page({ params }: Props) { if (initialSalaryAndBenefitsPage.data) { return isDraftMode ? ( - + ) : ( - + ); } diff --git a/src/salaryAndBenefits/SalaryAndBenefits.tsx b/src/salaryAndBenefits/SalaryAndBenefits.tsx index 4f1278efd..5a1e6fad1 100644 --- a/src/salaryAndBenefits/SalaryAndBenefits.tsx +++ b/src/salaryAndBenefits/SalaryAndBenefits.tsx @@ -1,10 +1,10 @@ import styles from "./salaryAndBenefits.module.css"; import Text from "src/components/text/Text"; -import { SalaryAndBenefits as SalaryAndBenefitsPayload } from "studio/lib/payloads/salaryAndBenefits"; +import { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits"; import { RichText } from "src/components/richText/RichText"; interface SalaryAndBenefitsProps { - salaryAndBenefits: SalaryAndBenefitsPayload; + salaryAndBenefits: SalaryAndBenefitsPage; } const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => { diff --git a/src/salaryAndBenefits/SalaryAndBenefitsPreview.tsx b/src/salaryAndBenefits/SalaryAndBenefitsPreview.tsx index 3994dc4d4..246d209fa 100644 --- a/src/salaryAndBenefits/SalaryAndBenefitsPreview.tsx +++ b/src/salaryAndBenefits/SalaryAndBenefitsPreview.tsx @@ -2,17 +2,17 @@ import { Suspense } from "react"; import SalaryAndBenefits from "./SalaryAndBenefits"; import { QueryResponseInitial, useQuery } from "@sanity/react-loader"; -import { SalaryAndBenefits as SalaryAndBenefitsPayload } from "studio/lib/payloads/salaryAndBenefits"; +import { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits"; import { SALARY_AND_BENEFITS_PAGE_QUERY } from "studio/lib/queries/pages"; interface SalaryAndBenefitsPreviewProps { - initialSalaryAndBenefits: QueryResponseInitial; + initialSalaryAndBenefits: QueryResponseInitial; } const SalaryAndBenefitsPreview = ({ initialSalaryAndBenefits, }: SalaryAndBenefitsPreviewProps) => { - const { data: newData } = useQuery( + const { data: newData } = useQuery( SALARY_AND_BENEFITS_PAGE_QUERY, { slug: initialSalaryAndBenefits.data.slug.current }, { initial: initialSalaryAndBenefits }, diff --git a/studio/lib/payloads/salaryAndBenefits.ts b/studio/lib/payloads/salaryAndBenefits.ts index f80dfb46d..cc847e3cc 100644 --- a/studio/lib/payloads/salaryAndBenefits.ts +++ b/studio/lib/payloads/salaryAndBenefits.ts @@ -1,5 +1,5 @@ -import { PortableTextBlock } from 'src/components/richText/RichText'; -import { Slug } from './global'; +import { PortableTextBlock } from "src/components/richText/RichText"; +import { Slug } from "./global"; export interface Benefit { _type: string; @@ -8,8 +8,7 @@ export interface Benefit { richText: PortableTextBlock[]; } - -export interface SalaryAndBenefits { +export interface SalaryAndBenefitsPage { _createdAt: string; _id: string; _rev: string; @@ -19,4 +18,4 @@ export interface SalaryAndBenefits { page: string; slug: Slug; benefits: Benefit[]; -} \ No newline at end of file +}