Skip to content

Commit

Permalink
feat: initial employees page
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Oct 16, 2024
1 parent 053e1d0 commit e6eabee
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/app/(main)/[lang]/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function seoDataFromPageData(
case "compensations": {
return data.queryResponse.compensationsPage.data.seo;
}
case "employeesPage": {
// TODO
return null;
}
}
}

Expand Down Expand Up @@ -124,7 +128,13 @@ async function Page({ params }: Props) {
case "customerCase":
return (
// TODO: implement customer case detail page
<pre style={{ background: "hotpink", marginTop: "8rem" }}>
<pre
style={{
background: "hotpink",
marginTop: "8rem",
textWrap: "wrap",
}}
>
{JSON.stringify(pageData, null, 2)}
</pre>
);
Expand All @@ -134,6 +144,19 @@ async function Page({ params }: Props) {
) : (
<Legal document={queryResponse.data} />
);
case "employeesPage":
return (
// TODO: implement employees page
<pre
style={{
background: "hotpink",
marginTop: "8rem",
textWrap: "wrap",
}}
>
{JSON.stringify(pageData, null, 2)}
</pre>
);
}
return Page404;
})()}
Expand Down
43 changes: 42 additions & 1 deletion src/utils/pageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -258,6 +261,43 @@ async function fetchLegalDocument({
};
}

async function fetchEmployeesPage({
language,
path,
perspective,
}: PageDataParams): Promise<PageFromParams<
QueryResponseInitial<EmployeesPage>,
typeof employeesPageId
> | null> {
if (path.length === 0) {
return null;
}
const queryResponse = await loadStudioQuery<EmployeesPage | null>(
EMPLOYEES_PAGE_QUERY,
{
slug: path[0],
language,
},
{ perspective },
);
if (!isNonNullQueryResponse(queryResponse)) {
return null;
}
const pathTranslations =
await loadStudioQuery<InternationalizedString | null>(
SLUG_FIELD_TRANSLATIONS_FROM_LANGUAGE_QUERY,
{
slug: path[0],
language,
},
);
return {
queryResponse,
docType: employeesPageId,
pathTranslations: pathTranslations.data ?? [],
};
}

export interface PageDataParams {
language: string;
path: string[];
Expand All @@ -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))
);
}
10 changes: 10 additions & 0 deletions studio/deskStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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"),
),
]),
);

Expand Down
10 changes: 10 additions & 0 deletions studio/lib/interfaces/employeesPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface EmployeesPage {
_createdAt: string;
_id: string;
_rev: string;
_type: string;
_updatedAt: string;
language: string;
basicTitle: string;
slug: string;
}
13 changes: 12 additions & 1 deletion studio/lib/queries/specialPages.ts
Original file line number Diff line number Diff line change
@@ -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[] {
Expand Down Expand Up @@ -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")},
}
`;
2 changes: 2 additions & 0 deletions studio/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -41,5 +42,6 @@ export const schema: { types: SchemaTypeDefinition[] } = {
locale,
richText,
seo,
employeesPage,
],
};
44 changes: 44 additions & 0 deletions studio/schemas/documents/specialPages/employeesPage.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e6eabee

Please sign in to comment.