From e6eabee1278e8aa3bb6781e86b7fa5cba0720d65 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Wed, 16 Oct 2024 14:15:35 +0200 Subject: [PATCH] feat: initial employees page --- src/app/(main)/[lang]/[...path]/page.tsx | 25 ++++++++++- src/utils/pageData.ts | 43 +++++++++++++++++- studio/deskStructure.ts | 10 +++++ studio/lib/interfaces/employeesPage.ts | 10 +++++ studio/lib/queries/specialPages.ts | 13 +++++- studio/schema.ts | 2 + .../documents/specialPages/employeesPage.ts | 44 +++++++++++++++++++ 7 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 studio/lib/interfaces/employeesPage.ts create mode 100644 studio/schemas/documents/specialPages/employeesPage.ts diff --git a/src/app/(main)/[lang]/[...path]/page.tsx b/src/app/(main)/[lang]/[...path]/page.tsx index 628c964e0..5e8d859ab 100644 --- a/src/app/(main)/[lang]/[...path]/page.tsx +++ b/src/app/(main)/[lang]/[...path]/page.tsx @@ -41,6 +41,10 @@ function seoDataFromPageData( case "compensations": { return data.queryResponse.compensationsPage.data.seo; } + case "employeesPage": { + // TODO + return null; + } } } @@ -124,7 +128,13 @@ async function Page({ params }: Props) { case "customerCase": return ( // TODO: implement customer case detail page -
+                
                   {JSON.stringify(pageData, null, 2)}
                 
); @@ -134,6 +144,19 @@ async function Page({ params }: Props) { ) : ( ); + case "employeesPage": + return ( + // TODO: implement employees page +
+                  {JSON.stringify(pageData, null, 2)}
+                
+ ); } return Page404; })()} diff --git a/src/utils/pageData.ts b/src/utils/pageData.ts index 66894ba53..74f980cf7 100644 --- a/src/utils/pageData.ts +++ b/src/utils/pageData.ts @@ -3,6 +3,7 @@ import { QueryResponseInitial } from "@sanity/react-loader"; import { CompanyLocation } from "studio/lib/interfaces/companyDetails"; import { CompensationsPage } from "studio/lib/interfaces/compensations"; +import { EmployeesPage } from "studio/lib/interfaces/employeesPage"; import { InternationalizedString } from "studio/lib/interfaces/global"; import { LegalDocument } from "studio/lib/interfaces/legalDocuments"; import { LocaleDocument } from "studio/lib/interfaces/locale"; @@ -22,12 +23,14 @@ import { import { COMPENSATIONS_PAGE_BY_SLUG_QUERY, CUSTOMER_CASES_PAGE_QUERY, + EMPLOYEES_PAGE_QUERY, } from "studio/lib/queries/specialPages"; import { loadStudioQuery } from "studio/lib/store"; import { legalDocumentID } from "studio/schemas/documents/admin/legalDocuments"; import { compensationsId } from "studio/schemas/documents/compensations"; import { pageBuilderID } from "studio/schemas/documents/pageBuilder"; import { customerCasesPageID } from "studio/schemas/documents/specialPages/customerCasesPage"; +import { employeesPageId } from "studio/schemas/documents/specialPages/employeesPage"; import { CustomerCase } from "studioShared/lib/interfaces/customerCases"; import { CUSTOMER_CASE_QUERY } from "studioShared/lib/queries/customerCases"; import { loadSharedQuery } from "studioShared/lib/store"; @@ -258,6 +261,43 @@ async function fetchLegalDocument({ }; } +async function fetchEmployeesPage({ + language, + path, + perspective, +}: PageDataParams): Promise, + typeof employeesPageId +> | null> { + if (path.length === 0) { + return null; + } + const queryResponse = await loadStudioQuery( + EMPLOYEES_PAGE_QUERY, + { + slug: path[0], + language, + }, + { perspective }, + ); + if (!isNonNullQueryResponse(queryResponse)) { + return null; + } + const pathTranslations = + await loadStudioQuery( + SLUG_FIELD_TRANSLATIONS_FROM_LANGUAGE_QUERY, + { + slug: path[0], + language, + }, + ); + return { + queryResponse, + docType: employeesPageId, + pathTranslations: pathTranslations.data ?? [], + }; +} + export interface PageDataParams { language: string; path: string[]; @@ -269,6 +309,7 @@ export async function fetchPageDataFromParams(params: PageDataParams) { (await fetchDynamicPage(params)) ?? (await fetchCompensationsPage(params)) ?? (await fetchCustomerCase(params)) ?? - (await fetchLegalDocument(params)) + (await fetchLegalDocument(params)) ?? + (await fetchEmployeesPage(params)) ); } diff --git a/studio/deskStructure.ts b/studio/deskStructure.ts index 16e40a722..f88127c66 100644 --- a/studio/deskStructure.ts +++ b/studio/deskStructure.ts @@ -26,6 +26,7 @@ import { brandAssetsID } from "./schemas/documents/siteSettings/brandAssets"; import { localeID } from "./schemas/documents/siteSettings/locale"; import { soMeLinksID } from "./schemas/documents/siteSettings/socialMediaProfiles"; import { customerCasesPageID } from "./schemas/documents/specialPages/customerCasesPage"; +import { employeesPageId } from "./schemas/documents/specialPages/employeesPage"; // Admin Section const adminSection = (S: StructureBuilder) => @@ -157,6 +158,15 @@ const specialPagesSection = (S: StructureBuilder) => .documentId(customerCasesPageID) .title("Customer Cases"), ), + S.listItem() + .title("Employees") + .icon(UsersIcon) + .child( + S.document() + .schemaType(employeesPageId) + .documentId(employeesPageId) + .title("Employees"), + ), ]), ); diff --git a/studio/lib/interfaces/employeesPage.ts b/studio/lib/interfaces/employeesPage.ts new file mode 100644 index 000000000..3a8f56ca5 --- /dev/null +++ b/studio/lib/interfaces/employeesPage.ts @@ -0,0 +1,10 @@ +export interface EmployeesPage { + _createdAt: string; + _id: string; + _rev: string; + _type: string; + _updatedAt: string; + language: string; + basicTitle: string; + slug: string; +} diff --git a/studio/lib/queries/specialPages.ts b/studio/lib/queries/specialPages.ts index c1269ef08..d26aa2b0b 100644 --- a/studio/lib/queries/specialPages.ts +++ b/studio/lib/queries/specialPages.ts @@ -1,12 +1,13 @@ import { groq } from "next-sanity"; +import { LANGUAGE_FIELD_FRAGMENT } from "./i18n"; import { translatedFieldFragment } from "./utils/i18n"; //Compensations export const COMPENSATIONS_PAGE_BY_SLUG_QUERY = groq` *[_type == "compensations" && ${translatedFieldFragment("slug")} == $slug][0] { ..., - "language": $language, + ${LANGUAGE_FIELD_FRAGMENT}, "slug": ${translatedFieldFragment("slug")}, "basicTitle": ${translatedFieldFragment("basicTitle")}, "benefitsByLocation": benefitsByLocation[] { @@ -53,3 +54,13 @@ export const CUSTOMER_CASES_PAGE_SITEMAP_QUERY = groq` slug } `; + +//Employees Page +export const EMPLOYEES_PAGE_QUERY = groq` + *[_type == "employeesPage" && ${translatedFieldFragment("slug")} == $slug][0] { + ..., + ${LANGUAGE_FIELD_FRAGMENT}, + "slug": ${translatedFieldFragment("slug")}, + "basicTitle": ${translatedFieldFragment("basicTitle")}, + } +`; diff --git a/studio/schema.ts b/studio/schema.ts index 099a9e4f6..0f994c0c2 100644 --- a/studio/schema.ts +++ b/studio/schema.ts @@ -12,6 +12,7 @@ import locale from "./schemas/documents/siteSettings/locale"; import navigationManager from "./schemas/documents/siteSettings/navigationManager"; import socialMediaLinks from "./schemas/documents/siteSettings/socialMediaProfiles"; import customerCasesPage from "./schemas/documents/specialPages/customerCasesPage"; +import employeesPage from "./schemas/documents/specialPages/employeesPage"; import callToActionField from "./schemas/fields/callToActionFields"; import { richText } from "./schemas/fields/text"; import benefitsByLocation from "./schemas/objects/compensations/benefitsByLocation"; @@ -41,5 +42,6 @@ export const schema: { types: SchemaTypeDefinition[] } = { locale, richText, seo, + employeesPage, ], }; diff --git a/studio/schemas/documents/specialPages/employeesPage.ts b/studio/schemas/documents/specialPages/employeesPage.ts new file mode 100644 index 000000000..2559c9440 --- /dev/null +++ b/studio/schemas/documents/specialPages/employeesPage.ts @@ -0,0 +1,44 @@ +import { defineType } from "sanity"; + +import { isInternationalizedString } from "studio/lib/interfaces/global"; +import { title, titleID } from "studio/schemas/fields/text"; +import { titleSlug } from "studio/schemas/schemaTypes/slug"; +import { firstTranslation } from "studio/utils/i18n"; + +export const employeesPageId = "employeesPage"; + +const employeesPage = defineType({ + name: employeesPageId, + type: "document", + title: "Employees Page", + fields: [ + { + name: titleID.basic, + type: "internationalizedArrayString", + title: "Page Title", + description: + "Enter the primary title that will be displayed at the top of the employees page. This is what users will see when they visit the page.", + }, + { + ...titleSlug, + type: "internationalizedArrayString", + }, + ], + preview: { + select: { + title: title.name, + }, + prepare({ title }) { + if (!isInternationalizedString(title)) { + throw new TypeError( + `Expected 'title' to be InternationalizedString, was ${typeof title}`, + ); + } + return { + title: firstTranslation(title) ?? undefined, + }; + }, + }, +}); + +export default employeesPage;