Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 - update customer cases interface #787

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/components/customerCases/CustomerCasesPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CustomerCasesPreview = ({
}: CustomerCasesPreviewProps) => {
const { data: customerCases } = useQuery<CustomerCasePage>(
CUSTOMER_CASES_PAGE_QUERY,
{ slug: initialCustomerCases.data.slug.current },
{ slug: initialCustomerCases.data.slug },
{ initial: initialCustomerCases },
);

Expand Down
4 changes: 1 addition & 3 deletions studio/lib/interfaces/specialPages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { SeoData } from "src/utils/seo";

import { Slug } from "./global";

export interface CustomerCasePage {
_createdAt: string;
_id: string;
Expand All @@ -10,7 +8,7 @@ export interface CustomerCasePage {
_updatedAt: string;
basicTitle: string;
page: string;
slug: Slug;
slug: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Since the customer case page is field translated, the slug is returned as a string.

language: string;
seo: SeoData;
}
26 changes: 18 additions & 8 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";
import { PortableTextBlock } 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;
language: string;
slug: string;
basicTitle: string;
_updatedAt: string;
slug: Slug;
_createdAt: string;
_rev: string;
_type: 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