import type {QueryResponseInitial} from '@sanity/react-loader'; import type {SanityContext} from 'hydrogen-sanity'; export type SkinRitualStepCms = { num: string; kicker: string; title: string; body: string; duration: string; }; export type SkinRitualSectionCms = { eyebrow: string; headlinePrefix: string; headlineItalic: string; intro: string; steps: SkinRitualStepCms[]; footerText: string; primaryCtaLabel: string; primaryCtaHref: string; sectionBackground: string; burgundy: string; gold: string; charcoal: string; muted: string; gridLine: string; numMuted: string; }; type SanitySkinRitualPayload = { eyebrow?: string | null; headlinePrefix?: string | null; headlineItalic?: string | null; intro?: string | null; steps?: Array<{ num?: string | null; kicker?: string | null; title?: string | null; body?: string | null; duration?: string | null; } | null> | null; footerText?: string | null; primaryCtaLabel?: string | null; primaryCtaHref?: string | null; sectionBackground?: string | null; burgundy?: string | null; gold?: string | null; charcoal?: string | null; muted?: string | null; gridLine?: string | null; numMuted?: string | null; } | null; /** Defaults from `React/src/app/components/SkinRitual.tsx`. */ export const MOCK_SKIN_RITUAL_SECTION_CMS: SkinRitualSectionCms = { eyebrow: 'Your Daily Practice', headlinePrefix: 'The ABiiR ', headlineItalic: 'Experience', intro: 'A thoughtfully curated 4-step routine designed to transform your skin in as little as 4 minutes.', footerText: 'Experience the magic and science of Ayurveda with skincare collection.', primaryCtaLabel: 'Shop Experience Kit', primaryCtaHref: '/products/experience-kit', sectionBackground: '#f8f4ef', burgundy: '#5d0b24', gold: '#b39763', charcoal: '#1a1a18', muted: '#7a7068', gridLine: 'rgba(26, 26, 24, 0.06)', numMuted: 'rgba(26, 26, 24, 0.28)', steps: [ { num: '01', kicker: 'Step 01 · Cleanse', title: 'Cleanse', body: 'Begin with our Botanical Cleansing Oil to melt away makeup and impurities while nourishing your skin barrier. 2 pumps and massage oil gently on dry face and neck, massaging in a circular motion to break down makeup and impurities. Rinse thoroughly afterward.', duration: '60 sec', }, { num: '02', kicker: 'Step 02 · Treat', title: 'Treat', body: 'Layer our Hydra Serum with powerful actives onto freshly washed skin both in the morning and evening before your moisturizer. Gently massage the serum in a circular motion across your face & neck.', duration: '30 sec', }, { num: '03', kicker: 'Step 03 · Sculpt', title: 'Sculpt', body: 'Start with a clean face. Apply hydra serum. This helps the gua sha tool glide smoothly over your skin. Our Copper Gua Sha, a beauty tool that helps regenerate collagen and aids detoxification of the skin.', duration: '2 min', }, { num: '04', kicker: 'Step 04 · Seal & Protect', title: 'Seal & Protect', body: 'Finish with our best-selling cream. It is a luxurious and rich formula that provides deep soothing and moisturizing. This masterpiece is infused with Gotu Kola which offer antioxidant, firming, and hydrating properties for a glowing complexion.', duration: '30 sec', }, ], }; export function normalizeSkinRitualSanityPayload( raw: unknown, ): SkinRitualSectionCms | null { if (raw == null || typeof raw !== 'object') return null; const b = raw as SanitySkinRitualPayload; if (!b?.eyebrow || !b?.intro || !b?.footerText || !b?.steps?.length) { return null; } const steps: SkinRitualStepCms[] = []; for (const row of b.steps) { if ( !row?.num || !row?.kicker || !row?.title || !row?.body || !row?.duration ) { continue; } steps.push({ num: row.num, kicker: row.kicker, title: row.title, body: row.body, duration: row.duration, }); } if (!steps.length) return null; return { eyebrow: b.eyebrow, headlinePrefix: b.headlinePrefix ?? 'The ABiiR ', headlineItalic: b.headlineItalic ?? 'Experience', intro: b.intro, steps, footerText: b.footerText, primaryCtaLabel: b.primaryCtaLabel ?? 'Shop Experience Kit', primaryCtaHref: b.primaryCtaHref ?? '/products/experience-kit', sectionBackground: b.sectionBackground ?? '#f8f4ef', burgundy: b.burgundy ?? '#5d0b24', gold: b.gold ?? '#b39763', charcoal: b.charcoal ?? '#1a1a18', muted: b.muted ?? '#7a7068', gridLine: b.gridLine ?? 'rgba(26, 26, 24, 0.06)', numMuted: b.numMuted ?? 'rgba(26, 26, 24, 0.28)', }; } export async function loadSkinRitualFromSanity(args: { sanity: SanityContext; groq: string; }): Promise<{skinRitualCms: SkinRitualSectionCms}> { const initial: QueryResponseInitial = await args.sanity .loadQuery(args.groq) .catch( (): QueryResponseInitial => ({ data: null, sourceMap: undefined, }), ); const normalized = normalizeSkinRitualSanityPayload(initial.data); return { skinRitualCms: normalized ?? MOCK_SKIN_RITUAL_SECTION_CMS, }; }