Skip to content

Commit

Permalink
Add resultBlock section to sharedStudio
Browse files Browse the repository at this point in the history
  • Loading branch information
idamand committed Oct 31, 2024
1 parent 50a15e0 commit fa6b018
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 10 deletions.
8 changes: 7 additions & 1 deletion studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IImage } from "studio/lib/interfaces/media";

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

export interface CustomerCaseProjectInfo {
Expand All @@ -27,7 +28,12 @@ export interface CustomerCaseBase {
image: IImage;
}

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

export interface CustomerCase extends CustomerCaseBase {
projectInfo: CustomerCaseProjectInfo;
Expand Down
11 changes: 11 additions & 0 deletions studioShared/lib/interfaces/resultBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface ResultListItem {
result: string;
description: string;
}

export interface ResultBlock {
_key: string;
_type: "resultBlock";
resultBlockTitle?: string;
resultList?: ResultListItem[];
}
7 changes: 7 additions & 0 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export const CUSTOMER_CASE_QUERY = groq`
"quote": ${translatedFieldFragment("quote")},
"author": ${translatedFieldFragment("author")},
},
_type == "resultBlock" => {
"resultBlockTitle": ${translatedFieldFragment("resultBlockTitle")},
"resultList": resultList[] {
result,
"description": ${translatedFieldFragment("description")},
}
}
}
}
`;
Expand Down
72 changes: 63 additions & 9 deletions studioShared/schemas/objects/resultBlock.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,84 @@
import { defineField } from "sanity";

import { isInternationalizedString } from "studio/lib/interfaces/global";
import { firstTranslation } from "studio/utils/i18n";

const resultBlock = defineField({
name: "resultBlock",
type: "object",
title: "Result Block",
description: "This block can be used to add some results from the project.",
fields: [
{
name: "result",
type: "string",
title: "Result",
description: "Add result, eg. '+ 72%'",
name: "resultBlockTitle",
title: "Result Block Title",
description:
"Please provide a title for the result block, for example: 'These are the results from the project'",
type: "internationalizedArrayString",
},
{
name: "description",
type: "internationalizedArrayText",
title: "Description of the result, eg. 'Satisfied users'",
name: "resultList",
title: "List of results",
description: "Add up to five results to be included in this list",
type: "array",
validation: (rule) =>
rule.max(5).error("You can add a maximum of five results"),
of: [
{
type: "object",
title: "Result List Item",
name: "resultlistitem",
fields: [
{
name: "result",
type: "string",
title: "Result",
description: "Add result, for example '+ 72%'",
},
{
name: "description",
type: "internationalizedArrayString",
title: "Description of the result, for example 'Satisfied users'",
},
],
preview: {
select: {
item: "description",
},
prepare({ item }) {
if (item !== undefined && !isInternationalizedString(item)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof item}`,
);
}
return {
title:
item !== undefined
? (firstTranslation(item) ?? undefined)
: undefined,
};
},
},
},
],
},
],
preview: {
select: {
title: "description",
title: "resultBlockTitle",
},
prepare({ title }) {
return { title: firstTranslation(title) ?? undefined };
if (title !== undefined && !isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
return {
title:
title !== undefined
? (firstTranslation(title) ?? undefined)
: undefined,
};
},
},
});
Expand Down

0 comments on commit fa6b018

Please sign in to comment.