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: quote block for customer cases #799

Merged
merged 2 commits into from
Oct 22, 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
9 changes: 8 additions & 1 deletion src/components/customerCases/customerCase/CustomerCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ export default function CustomerCase({ customerCase }: CustomerCaseProps) {
<div key={section._key}>
{section._type === "richTextBlock" ? (
<RichText value={section.richText} />
) : section._type === "quoteBlock" ? (
section.quote && (
<div>
<Text>{section.quote}</Text>
{section.author && <Text>- {section.author}</Text>}
</div>
)
) : (
<div className={styles.imageBlockWrapper}>
{section.images.map((image) => (
{section.images?.map((image) => (
<div
key={image._key}
className={styles.imageBlockImageWrapper}
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like it should eventually be pulled out into a switch statement instead of keeping the nested ternary going

Expand Down
3 changes: 2 additions & 1 deletion studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IImage } from "studio/lib/interfaces/media";

import { ImageBlock } from "./imageBlock";
import { QuoteBlock } from "./quoteBlock";
import { RichTextBlock } from "./richTextBlock";

export interface CustomerCaseProjectInfo {
Expand All @@ -21,7 +22,7 @@ export interface CustomerCaseBase {
image: IImage;
}

export type CustomerCaseSections = (RichTextBlock | ImageBlock)[];
export type CustomerCaseSections = (RichTextBlock | ImageBlock | QuoteBlock)[];

export interface CustomerCase extends CustomerCaseBase {
projectInfo: CustomerCaseProjectInfo;
Expand Down
6 changes: 6 additions & 0 deletions studioShared/lib/interfaces/quoteBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface QuoteBlock {
_key: string;
_type: "quoteBlock";
quote?: string;
author?: string;
}
6 changes: 5 additions & 1 deletion studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export const CUSTOMER_CASE_QUERY = groq`
"list": list[] {
"text": ${translatedFieldFragment("text")},
},
}
},
_type == "quoteBlock" => {
"quote": ${translatedFieldFragment("quote")},
"author": ${translatedFieldFragment("author")},
},
}
}
`;
Expand Down
3 changes: 2 additions & 1 deletion studioShared/schemas/documents/customerCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { firstTranslation } from "studio/utils/i18n";
import { customerCaseProjectInfo } from "studioShared/schemas/fields/customerCaseProjectInfo";
import imageBlock from "studioShared/schemas/objects/imageBlock";
import listBlock from "studioShared/schemas/objects/listBlock";
import quoteBlock from "studioShared/schemas/objects/quoteBlock";
import richTextBlock from "studioShared/schemas/objects/richTextBlock";

export const customerCaseID = "customerCase";
Expand Down Expand Up @@ -49,7 +50,7 @@ const customerCase = defineType({
title: "Sections",
description: "Add sections here",
type: "array",
of: [richTextBlock, imageBlock, listBlock],
of: [richTextBlock, imageBlock, listBlock, quoteBlock],
}),
],
preview: {
Expand Down
30 changes: 30 additions & 0 deletions studioShared/schemas/objects/quoteBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineField } from "sanity";

import { firstTranslation } from "studio/utils/i18n";

const quoteBlock = defineField({
name: "quoteBlock",
type: "object",
title: "Quote Block",
fields: [
{
name: "quote",
type: "internationalizedArrayText",
title: "Quote",
},
{
name: "author",
type: "internationalizedArrayString",
title: "Author of the quote",
},
],
preview: {
select: {
title: "quote",
},
prepare({ title }) {
return { title: firstTranslation(title) ?? undefined };
},
},
});
export default quoteBlock;