Skip to content

Commit

Permalink
feat(customerCases): update interface to match customer case schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Oct 16, 2024
1 parent 7816b8e commit 1672c6f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/components/customerCases/CustomerCases.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import LinkButton from "src/components/linkButton/LinkButton";
import { RichText } from "src/components/richText/RichText";
import Text from "src/components/text/Text";
import { sharedCustomerCasesLink } from "src/components/utils/linkTypes";
import { getDraftModeInfo } from "src/utils/draftmode";
import { CustomerCasePage } from "studio/lib/interfaces/specialPages";
import { CustomerCase } from "studioShared/lib/interfaces/customerCases";
import { CustomerCaseBase } from "studioShared/lib/interfaces/customerCases";
import { CUSTOMER_CASES_QUERY } from "studioShared/lib/queries/customerCases";
import { loadSharedQuery } from "studioShared/lib/store";

Expand All @@ -18,7 +17,7 @@ const CustomerCases = async ({ customerCasesPage }: CustomerCasesProps) => {
const { perspective } = getDraftModeInfo();

const [sharedCustomerCases] = await Promise.all([
loadSharedQuery<CustomerCase[]>(
loadSharedQuery<CustomerCaseBase[]>(
CUSTOMER_CASES_QUERY,
{ language: customerCasesPage.language },
{ perspective },
Expand All @@ -29,11 +28,11 @@ const CustomerCases = async ({ customerCasesPage }: CustomerCasesProps) => {
<div className={styles.wrapper}>
<Text type="h1"> {customerCasesPage.basicTitle} </Text>
{sharedCustomerCases && sharedCustomerCases.data.length > 0 ? (
sharedCustomerCases.data.map((customerCase: CustomerCase) => (
sharedCustomerCases.data.map((customerCase) => (
<div key={customerCase._id}>
<Text type="h2">{customerCase.basicTitle}</Text>
{customerCase.richText && (
<RichText value={customerCase.richText} />
{customerCase.description && (
<Text>{customerCase.description}</Text>
)}
</div>
))
Expand Down
24 changes: 17 additions & 7 deletions studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { PortableTextBlock, Slug } from "sanity";

export interface CustomerCase {
language: string;
export interface CustomerCaseProjectInfo {
customer: string;
name: string;
duration: string;
sector: string;
delivery: string;
consultants: string[];
}

export interface CustomerCaseBase {
_id: string;
basicTitle: string;
_updatedAt: string;
language: string;
slug: Slug;
_createdAt: string;
_rev: string;
_type: string;
basicTitle: string;
description: string;
}

export interface CustomerCase extends CustomerCaseBase {
richText: PortableTextBlock[];
projectInfo: CustomerCaseProjectInfo;
}
17 changes: 10 additions & 7 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import { groq } from "next-sanity";
import { LANGUAGE_FIELD_FRAGMENT } from "studio/lib/queries/i18n";
import { translatedFieldFragment } from "studio/lib/queries/utils/i18n";

const CUSTOMER_CASE_BASE_FRAGMENT = groq`
_id,
${LANGUAGE_FIELD_FRAGMENT},
"slug": ${translatedFieldFragment("slug")},
"basicTitle": ${translatedFieldFragment("basicTitle")},
"description": ${translatedFieldFragment("description")}
`;

export const CUSTOMER_CASES_QUERY = groq`
*[_type == "customerCase"]{
${LANGUAGE_FIELD_FRAGMENT},
"basicTitle": ${translatedFieldFragment("basicTitle")},
"richText": ${translatedFieldFragment("richText")}
${CUSTOMER_CASE_BASE_FRAGMENT}
}
`;

export const CUSTOMER_CASE_QUERY = groq`
*[_type == "customerCase" && ${translatedFieldFragment("slug")} == $slug][0] {
${LANGUAGE_FIELD_FRAGMENT},
"slug": ${translatedFieldFragment("slug")},
"basicTitle": ${translatedFieldFragment("basicTitle")},
"description": ${translatedFieldFragment("description")},
${CUSTOMER_CASE_BASE_FRAGMENT}
"richText": ${translatedFieldFragment("richText")},
"projectInfo": projectInfo {
customer,
Expand Down

0 comments on commit 1672c6f

Please sign in to comment.