Skip to content

Commit

Permalink
refactor(SalaryAndBenefits): rename SalaryAndBenefitsPayload -> Salar…
Browse files Browse the repository at this point in the history
…yAndBenefitsPage
  • Loading branch information
mathiazom committed Aug 22, 2024
1 parent 9f418b6 commit 1e53edd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
35 changes: 24 additions & 11 deletions src/app/(main)/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -36,13 +36,22 @@ async function Page({ params }: Props) {
const { slug } = params;
const { perspective, isDraftMode } = getDraftModeInfo();

const [initialPage, initialBlogPage, initialSalaryAndBenefitsPage] = await Promise.all([
loadQuery<PageBuilder>(SLUG_QUERY, { slug }, { perspective }),
loadQuery<BlogPage>(BLOG_PAGE_QUERY, { slug }, { perspective }),
loadQuery<SalaryAndBenefitsPayload>(SALARY_AND_BENEFITS_PAGE_QUERY, { slug }, { perspective }),
]);
const [initialPage, initialBlogPage, initialSalaryAndBenefitsPage] =
await Promise.all([
loadQuery<PageBuilder>(SLUG_QUERY, { slug }, { perspective }),
loadQuery<BlogPage>(BLOG_PAGE_QUERY, { slug }, { perspective }),
loadQuery<SalaryAndBenefitsPage>(
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("/");
Expand All @@ -53,7 +62,7 @@ async function Page({ params }: Props) {
const initialPosts = await loadQuery<Post[]>(
POSTS_QUERY,
{ slug },
{ perspective }
{ perspective },
);

if (!initialPosts) {
Expand Down Expand Up @@ -95,9 +104,13 @@ async function Page({ params }: Props) {

if (initialSalaryAndBenefitsPage.data) {
return isDraftMode ? (
<SalaryAndBenefitsPreview initialSalaryAndBenefits={initialSalaryAndBenefitsPage} />
<SalaryAndBenefitsPreview
initialSalaryAndBenefits={initialSalaryAndBenefitsPage}
/>
) : (
<SalaryAndBenefits salaryAndBenefits={initialSalaryAndBenefitsPage.data} />
<SalaryAndBenefits
salaryAndBenefits={initialSalaryAndBenefitsPage.data}
/>
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/salaryAndBenefits/SalaryAndBenefits.tsx
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/salaryAndBenefits/SalaryAndBenefitsPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SalaryAndBenefitsPayload>;
initialSalaryAndBenefits: QueryResponseInitial<SalaryAndBenefitsPage>;
}

const SalaryAndBenefitsPreview = ({
initialSalaryAndBenefits,
}: SalaryAndBenefitsPreviewProps) => {
const { data: newData } = useQuery<SalaryAndBenefitsPayload>(
const { data: newData } = useQuery<SalaryAndBenefitsPage>(
SALARY_AND_BENEFITS_PAGE_QUERY,
{ slug: initialSalaryAndBenefits.data.slug.current },
{ initial: initialSalaryAndBenefits },
Expand Down
9 changes: 4 additions & 5 deletions studio/lib/payloads/salaryAndBenefits.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,8 +8,7 @@ export interface Benefit {
richText: PortableTextBlock[];
}


export interface SalaryAndBenefits {
export interface SalaryAndBenefitsPage {
_createdAt: string;
_id: string;
_rev: string;
Expand All @@ -19,4 +18,4 @@ export interface SalaryAndBenefits {
page: string;
slug: Slug;
benefits: Benefit[];
}
}

0 comments on commit 1e53edd

Please sign in to comment.