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 11, 2024
1 parent 315db19 commit f6714c2
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/app/(main)/[lang]/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ 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 @@ -103,6 +105,15 @@ 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
40 changes: 39 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 { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { LocaleDocument } from "studio/lib/interfaces/locale";
import { PageBuilder } from "studio/lib/interfaces/pages";
Expand All @@ -16,12 +17,14 @@ import { PAGE_BY_SLUG_QUERY } from "studio/lib/queries/pages";
import {
COMPENSATIONS_PAGE_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 @@ -231,6 +234,40 @@ async function fetchLegalDocument({
};
}

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

export interface PageDataParams {
language: string;
path: string[];
Expand All @@ -242,6 +279,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 @@ -28,6 +28,7 @@ import { brokenLinkID } from "./schemas/documents/siteSettings/brokenLink";
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 @@ -172,6 +173,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_QUERY = groq`
*[_type == "compensations" && ${translatedFieldFragment("slug")} == $slug][0] {
...,
"language": $language,
${LANGUAGE_FIELD_FRAGMENT},
"slug": ${translatedFieldFragment("slug")},
"basicTitle": ${translatedFieldFragment("basicTitle")},
"benefitsByLocation": benefitsByLocation[] {
Expand All @@ -24,3 +25,13 @@ export const COMPENSATIONS_PAGE_QUERY = groq`
//Customer Cases
export const CUSTOMER_CASES_PAGE_QUERY = groq`
*[_type == "customerCasesPage" && slug.current == $slug][0]`;

//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 @@ -15,6 +15,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 categories from "./schemas/fields/categories";
import { richText } from "./schemas/fields/text";
Expand Down Expand Up @@ -49,5 +50,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 f6714c2

Please sign in to comment.