From c669b01b3f3bbca37f4fcc429873c9b17dab9172 Mon Sep 17 00:00:00 2001 From: Ane Date: Wed, 11 Dec 2024 12:42:18 +0100 Subject: [PATCH] image and title in sanity --- .../customerCasesEntry/CustomerCasesList.tsx | 62 ++++++++++--------- src/components/sections/hero/Hero.tsx | 5 ++ src/components/sections/hero/hero.module.css | 8 +++ studio/lib/interfaces/pages.ts | 2 + studio/lib/queries/pages.ts | 1 + studio/schemas/objects/sections/hero.ts | 39 +++++++++++- 6 files changed, 84 insertions(+), 33 deletions(-) diff --git a/src/components/sections/customerCasesEntry/CustomerCasesList.tsx b/src/components/sections/customerCasesEntry/CustomerCasesList.tsx index 44e15b8de..fa04f868f 100644 --- a/src/components/sections/customerCasesEntry/CustomerCasesList.tsx +++ b/src/components/sections/customerCasesEntry/CustomerCasesList.tsx @@ -24,47 +24,49 @@ const CustomerCaseList = ({ customerCasePageSlug, }: CustomerCasesProps) => { const [selectedCustomerCase, setSelectedCustomerCase] = - useState(customerCases[0] || null); + useState(customerCases[0]); const deliveryNames = [ - selectedCustomerCase.projectInfo.deliveries.projectManagement && + selectedCustomerCase?.projectInfo.deliveries.projectManagement && "Project Management", - selectedCustomerCase.projectInfo.deliveries.design && "Design", - selectedCustomerCase.projectInfo.deliveries.development && "Development", + selectedCustomerCase?.projectInfo.deliveries.design && "Design", + selectedCustomerCase?.projectInfo.deliveries.development && "Development", ].filter(Boolean); return ( -
-
-
-
- - - +
+
+
+ - + + + +
+ + {selectedCustomerCase.image && ( + + )} +
- - {selectedCustomerCase.image && ( - - )} -
-
+ ) ); }; export default CustomerCaseList; diff --git a/src/components/sections/hero/Hero.tsx b/src/components/sections/hero/Hero.tsx index 8c0b581fe..d9e289bd6 100644 --- a/src/components/sections/hero/Hero.tsx +++ b/src/components/sections/hero/Hero.tsx @@ -1,3 +1,4 @@ +import { SanityImage } from "src/components/image/SanityImage"; import Text from "src/components/text/Text"; import { HeroSection } from "studio/lib/interfaces/pages"; @@ -16,7 +17,11 @@ export const Hero = ({ hero, isLanding = false }: HeroProps) => {
{isLanding ? (
+ {hero.title} {hero.description} +
+ +
) : ( // If splashy segments are added to the hero section in the landing page, this serves as a great fallback option. diff --git a/src/components/sections/hero/hero.module.css b/src/components/sections/hero/hero.module.css index f55b0dfa8..4cbfd898a 100644 --- a/src/components/sections/hero/hero.module.css +++ b/src/components/sections/hero/hero.module.css @@ -24,6 +24,7 @@ composes: shared; align-self: center; padding: var(--padding-xl) var(--padding-rem); + gap: var(--padding-rem); @media (max-width: 834px) { padding: var(--padding-l) var(--padding-s); @@ -34,6 +35,13 @@ } } +.img{ + width: 100%; + max-width: 60rem; + justify-content: flex-end; + display: flex !important; +} + .primary { composes: shared; } diff --git a/studio/lib/interfaces/pages.ts b/studio/lib/interfaces/pages.ts index d4305dcfc..67670522d 100644 --- a/studio/lib/interfaces/pages.ts +++ b/studio/lib/interfaces/pages.ts @@ -10,7 +10,9 @@ import { ILink } from "./navigation"; export interface HeroSection { _type: "hero"; _key: string; + title: string; description: string; + image: IImage; } export interface LogoSaladSection { diff --git a/studio/lib/queries/pages.ts b/studio/lib/queries/pages.ts index faa1d7f41..69766a785 100644 --- a/studio/lib/queries/pages.ts +++ b/studio/lib/queries/pages.ts @@ -8,6 +8,7 @@ const SECTIONS_FRAGMENT = groq` ..., _type == "hero" => { ..., + "title": ${translatedFieldFragment("title")}, "description": ${translatedFieldFragment("description")}, }, _type == "article" => { diff --git a/studio/schemas/objects/sections/hero.ts b/studio/schemas/objects/sections/hero.ts index 903543731..696437ced 100644 --- a/studio/schemas/objects/sections/hero.ts +++ b/studio/schemas/objects/sections/hero.ts @@ -9,6 +9,31 @@ export const hero = defineField({ title: "Hero Section", type: "object", fields: [ + { + name: "title", + title: "title", + type: "internationalizedArrayString", + validation: (rule) => + rule.custom<{ value: string; _type: string; _key: string }[]>( + (value) => { + if (!value) return true; + + const invalidItems = value.filter( + (item) => + typeof item.value === "string" && item.value.length > 200, + ); + + if (invalidItems.length > 0) { + return invalidItems.map((item) => ({ + message: "title cannot be more than 200 characters long.", + path: [{ _key: item._key }, "value"], + })); + } + + return true; + }, + ), + }, { name: "description", title: "Description", @@ -34,15 +59,23 @@ export const hero = defineField({ }, ), }, + { + name: "image", + title: "Image", + type: "image", + options: { + hotspot: true, + }, + }, ], preview: { select: { - description: "description", + title: "title", }, prepare(selection) { - const { description } = selection; + const { title } = selection; return { - title: allTranslation(description) ?? undefined, + title: allTranslation(title) ?? undefined, subtitle: "Hero Section", }; },