diff --git a/studioShared/lib/queries/customerCases.ts b/studioShared/lib/queries/customerCases.ts index 98ab66bbf..28fbdb46c 100644 --- a/studioShared/lib/queries/customerCases.ts +++ b/studioShared/lib/queries/customerCases.ts @@ -46,6 +46,12 @@ export const CUSTOMER_CASE_QUERY = groq` "images": images[] { ${INTERNATIONALIZED_IMAGE_FRAGMENT} } + }, + _type == "listBlock" => { + "description": ${translatedFieldFragment("description")}, + "list": list[] { + "text": ${translatedFieldFragment("text")}, + }, } } } diff --git a/studioShared/schemas/documents/customerCase.ts b/studioShared/schemas/documents/customerCase.ts index 1f0ff2abf..b641e7df5 100644 --- a/studioShared/schemas/documents/customerCase.ts +++ b/studioShared/schemas/documents/customerCase.ts @@ -7,6 +7,7 @@ import { titleSlug } from "studio/schemas/schemaTypes/slug"; 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 richTextBlock from "studioShared/schemas/objects/richTextBlock"; export const customerCaseID = "customerCase"; @@ -48,7 +49,7 @@ const customerCase = defineType({ title: "Sections", description: "Add sections here", type: "array", - of: [richTextBlock, imageBlock], + of: [richTextBlock, imageBlock, listBlock], }), defineField({ name: richTextID, diff --git a/studioShared/schemas/objects/listBlock.ts b/studioShared/schemas/objects/listBlock.ts new file mode 100644 index 000000000..465e6a551 --- /dev/null +++ b/studioShared/schemas/objects/listBlock.ts @@ -0,0 +1,73 @@ +import { defineField } from "sanity"; + +import { isInternationalizedString } from "studio/lib/interfaces/global"; +import { firstTranslation } from "studio/utils/i18n"; +const listBlock = defineField({ + name: "listBlock", + title: "List Block", + description: + "This block could be used to add a list of skills, tools, methods etc. used for this project.", + type: "object", + fields: [ + { + name: "description", + title: "Description", + description: + "Please provide a brief sentence describing the list. For example: The following skills were applied in this project:", + type: "internationalizedArrayString", + }, + { + name: "list", + title: "List", + description: + "Add the items to be included in this list (e.g., skills, tools, methods).", + type: "array", + of: [ + { + type: "object", // You need to define it as an object since it's a custom field + title: "List Item", + name: "listItem", + fields: [ + { + name: "text", + title: "Text", + type: "internationalizedArrayString", + }, + ], + preview: { + select: { + item: "text", + }, + prepare({ item }) { + if (!isInternationalizedString(item)) { + throw new TypeError( + `Expected 'item' to be InternationalizedString, was ${typeof item}`, + ); + } + return { + title: firstTranslation(item) ?? undefined, + }; + }, + }, + }, + ], + }, + ], + preview: { + select: { + description: "description", + }, + prepare({ description }) { + if (!isInternationalizedString(description)) { + throw new TypeError( + `Expected 'description' to be InternationalizedString, was ${typeof description}`, + ); + } + return { + title: firstTranslation(description) ?? undefined, + }; + }, + }, +}); + +export default listBlock;