Skip to content

Commit

Permalink
v3 - replace SalaryAndBenefits with Compensations list (#551)
Browse files Browse the repository at this point in the history
* feat: Office document

* refactor(compensations): rename salaryAndBenefits to compensations

* feat(studio): move Compensations under Static Pages

* feat(Compensations): document list for compensations

* chore(salaryAndBenefits): add deprecation TODO
  • Loading branch information
mathiazom authored Aug 30, 2024
1 parent 8e3f64e commit 1cabfb5
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 73 deletions.
26 changes: 11 additions & 15 deletions src/app/(main)/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ 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 Compensations from "src/compensations/Compensations";
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 { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits";
import { CompensationsPage } from "studio/lib/payloads/compensations";
import {
BLOG_PAGE_QUERY,
POSTS_QUERY,
SALARY_AND_BENEFITS_PAGE_QUERY,
COMPENSATIONS_PAGE_QUERY,
SEO_SLUG_QUERY,
SLUG_QUERY,
} from "studio/lib/queries/pages";
import { loadQuery } from "studio/lib/store";
import SalaryAndBenefitsPreview from "src/salaryAndBenefits/SalaryAndBenefitsPreview";
import CompensationsPreview from "src/compensations/CompensationsPreview";

export const dynamic = "force-dynamic";

Expand All @@ -36,12 +36,12 @@ async function Page({ params }: Props) {
const { slug } = params;
const { perspective, isDraftMode } = getDraftModeInfo();

const [initialPage, initialBlogPage, initialSalaryAndBenefitsPage] =
const [initialPage, initialBlogPage, initialCompensationsPage] =
await Promise.all([
loadQuery<PageBuilder>(SLUG_QUERY, { slug }, { perspective }),
loadQuery<BlogPage>(BLOG_PAGE_QUERY, { slug }, { perspective }),
loadQuery<SalaryAndBenefitsPage>(
SALARY_AND_BENEFITS_PAGE_QUERY,
loadQuery<CompensationsPage>(
COMPENSATIONS_PAGE_QUERY,
{ slug },
{ perspective },
),
Expand All @@ -50,7 +50,7 @@ async function Page({ params }: Props) {
if (
!initialPage.data &&
!initialBlogPage.data &&
!initialSalaryAndBenefitsPage.data
!initialCompensationsPage.data
) {
console.log(`Page ${slug} not found`);
// TODO: add error snackbar
Expand Down Expand Up @@ -102,15 +102,11 @@ async function Page({ params }: Props) {
);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"use client";
import styles from "./salaryAndBenefits.module.css";
import styles from "./compensations.module.css";
import Text from "src/components/text/Text";
import { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits";
import { CompensationsPage } from "studio/lib/payloads/compensations";
import { RichText } from "src/components/richText/RichText";
import SalaryCalculator, {
Degree,
} from "./components/salaryCalculator/SalaryCalculator";
import { useState } from "react";
import { calculatePension, calculateSalary } from "./utils/calculateSalary";

interface SalaryAndBenefitsProps {
salaryAndBenefits: SalaryAndBenefitsPage;
interface CompensationsProps {
compensations: CompensationsPage;
}

interface SalaryCalculatorFormState {
examinationYear: number;
selectedDegree: Degree;
}

const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => {
const Compensations = ({ compensations }: CompensationsProps) => {
const currentYear = new Date().getFullYear();

const [formState, setFormState] = useState<SalaryCalculatorFormState>({
Expand Down Expand Up @@ -54,8 +54,8 @@ const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => {

return (
<div className={styles.wrapper}>
<Text type="h1">{salaryAndBenefits.basicTitle}</Text>
{salaryAndBenefits.showSalaryCalculator && (
<Text type="h1">{compensations.basicTitle}</Text>
{compensations.showSalaryCalculator && (
<>
<SalaryCalculator
examinationYearValue={formState.examinationYear}
Expand All @@ -75,7 +75,7 @@ const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => {
</>
)}
<div className={styles.benefits}>
{salaryAndBenefits.benefits.map((benefit) => (
{compensations.benefits.map((benefit) => (
<div key={benefit._key} className={styles.benefitWrapper}>
<Text type="h2">{benefit.basicTitle}</Text>
<RichText value={benefit.richText} />
Expand All @@ -86,4 +86,4 @@ const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => {
);
};

export default SalaryAndBenefits;
export default Compensations;
28 changes: 28 additions & 0 deletions src/compensations/CompensationsPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";
import { Suspense } from "react";
import Compensations from "./Compensations";
import { QueryResponseInitial, useQuery } from "@sanity/react-loader";
import { CompensationsPage } from "studio/lib/payloads/compensations";
import { COMPENSATIONS_PAGE_QUERY } from "studio/lib/queries/pages";

interface CompensationsPreviewProps {
initialCompensations: QueryResponseInitial<CompensationsPage>;
}

const CompensationsPreview = ({
initialCompensations,
}: CompensationsPreviewProps) => {
const { data } = useQuery<CompensationsPage>(
COMPENSATIONS_PAGE_QUERY,
{ slug: initialCompensations.data.slug.current },
{ initial: initialCompensations },
);

return (
<Suspense>
<Compensations compensations={data} />
</Suspense>
);
};

export default CompensationsPreview;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RadioButtonGroup,
} from "src/components/forms/radioButtonGroup/RadioButtonGroup";
import Button from "src/components/buttons/Button";
import { maxExperience } from "src/salaryAndBenefits/utils/calculateSalary";
import { maxExperience } from "src/compensations/utils/calculateSalary";

export type Degree = "bachelor" | "master";

Expand Down
File renamed without changes.
File renamed without changes.
28 changes: 0 additions & 28 deletions src/salaryAndBenefits/SalaryAndBenefitsPreview.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Benefit {
richText: PortableTextBlock[];
}

export interface SalaryAndBenefitsPage {
export interface CompensationsPage {
_createdAt: string;
_id: string;
_rev: string;
Expand Down
4 changes: 2 additions & 2 deletions studio/lib/queries/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const BLOG_PAGE_QUERY = groq`
*[_type == "blog" && slug.current == $slug][0]
`;

export const SALARY_AND_BENEFITS_PAGE_QUERY = groq`
*[_type == "salaryAndBenefits" && slug.current == $slug][0]
export const COMPENSATIONS_PAGE_QUERY = groq`
*[_type == "compensations" && slug.current == $slug][0]
`;

export const POSTS_QUERY = groq`
Expand Down
5 changes: 4 additions & 1 deletion studio/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import posts from "./schemas/documents/post";
import categories from "./schemas/fields/categories";
import legalDocument from "./schemas/documents/legalDocuments";
import benefit from "./schemas/documents/benefit";
import salaryAndBenefits from "./schemas/documents/salaryAndBenefits";
import office from "./schemas/documents/office";
import compensations from "./schemas/documents/compensations";
import salaryAndBenefits from "./schemas/documents/salaryAndBenefits";

export const schema: { types: SchemaTypeDefinition[] } = {
types: [
office,
siteSettings,
navigationManager,
socialMediaLinks,
Expand All @@ -29,6 +31,7 @@ export const schema: { types: SchemaTypeDefinition[] } = {
posts,
categories,
legalDocument,
compensations,
salaryAndBenefits,
benefit,
office,
Expand Down
17 changes: 7 additions & 10 deletions studio/schemas/deskStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { soMeLinksID } from "./documents/socialMediaProfiles";
import { siteSettingsID } from "./documents/siteSettings";
import { postId } from "./documents/post";
import { legalDocumentID } from "./documents/legalDocuments";
import { salaryAndBenefitsId } from "./documents/salaryAndBenefits";
import { compensationsId } from "./documents/compensations";

export default (S: StructureBuilder) =>
S.list()
Expand Down Expand Up @@ -66,15 +66,12 @@ export default (S: StructureBuilder) =>
.documentId(blogId)
.title("Blog Overview & Settings"),
),
S.listItem()
.title("Compensations")
.icon(HeartIcon)
.child(
S.documentTypeList(compensationsId).title("Compensations"),
),
]),
),
S.listItem()
.title("Salary and Benefits")
.icon(HeartIcon)
.child(
S.document()
.schemaType(salaryAndBenefitsId)
.documentId(salaryAndBenefitsId)
.title("Salary and Benefits"),
),
]);
34 changes: 34 additions & 0 deletions studio/schemas/documents/compensations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { defineField, defineType } from "sanity";
import { titleSlug } from "../schemaTypes/slug";
import seo from "../objects/seo";
import { title } from "../fields/text";
import { benefitId } from "./benefit";

export const compensationsId = "compensations";

const compensations = defineType({
name: compensationsId,
type: "document",
title: "Compensations",
fields: [
title,
titleSlug,
seo,
defineField({
name: "showSalaryCalculator",
title: "Show Salary Calculator",
description: "Should the salary calculator be visible on the page?",
type: "boolean",
initialValue: true,
}),
defineField({
name: "benefits",
title: "Benefits",
description: "Manage benefits for the compensations page",
type: "array",
of: [{ type: benefitId }],
}),
],
});

export default compensations;
12 changes: 8 additions & 4 deletions studio/schemas/documents/salaryAndBenefits.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { defineField, defineType } from "sanity";
import { title } from "../fields/text";
import { titleSlug } from "../schemaTypes/slug";
import seo from "../objects/seo";
import { title } from "../fields/text";
import { benefitId } from "./benefit";

export const salaryAndBenefitsId = "salaryAndBenefits";
// TODO: deprecated, drop support once important deployments have updated

const salaryAndBenefits = defineType({
name: salaryAndBenefitsId,
type: "document",
name: "salaryAndBenefits",
title: "Salary and Benefits",
type: "document",
deprecated: {
reason: "Use the Compensations document type instead",
},
readOnly: true,
fields: [
title,
titleSlug,
Expand Down
4 changes: 2 additions & 2 deletions studio/schemas/objects/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Parent {
// Lazy reference to avoid circular dependency
const lazyPageBuilderID = () => "pageBuilder";
const lazyBlogID = () => "blog";
const lazySalaryAndBenefitsID = () => "salaryAndBenefits";
const lazyCompensationsID = () => "compensations";

export const link = defineField({
name: linkID,
Expand Down Expand Up @@ -61,7 +61,7 @@ export const link = defineField({
to: [
{ type: lazyPageBuilderID() },
{ type: lazyBlogID() },
{ type: lazySalaryAndBenefitsID() },
{ type: lazyCompensationsID() },
],
validation: (Rule: any) =>
Rule.custom((value: any, context: any) => {
Expand Down

0 comments on commit 1cabfb5

Please sign in to comment.