281 lines
9.6 KiB
TypeScript
281 lines
9.6 KiB
TypeScript
import type {QueryResponseInitial} from '@sanity/react-loader';
|
|
import type {SanityContext} from 'hydrogen-sanity';
|
|
|
|
export type TestimonialItemCms = {
|
|
name: string;
|
|
location: string;
|
|
avatarInitials: string;
|
|
rating: number;
|
|
product: string;
|
|
text: string;
|
|
verified: boolean;
|
|
};
|
|
|
|
export type TestimonialStatCms = {
|
|
value: string;
|
|
label: string;
|
|
sub: string;
|
|
};
|
|
|
|
export type TestimonialsSectionCms = {
|
|
title: string;
|
|
testimonials: TestimonialItemCms[];
|
|
stats: [TestimonialStatCms, TestimonialStatCms, TestimonialStatCms];
|
|
sectionBackground: string;
|
|
cardBackground: string;
|
|
gold: string;
|
|
charcoal: string;
|
|
muted: string;
|
|
verifiedGreen: string;
|
|
gridLine: string;
|
|
dotInactive: string;
|
|
};
|
|
|
|
type SanityTestimonialsPayload = {
|
|
title?: string | null;
|
|
testimonials?: Array<{
|
|
name?: string | null;
|
|
location?: string | null;
|
|
avatarInitials?: string | null;
|
|
rating?: number | null;
|
|
product?: string | null;
|
|
text?: string | null;
|
|
verified?: boolean | null;
|
|
} | null> | null;
|
|
stats?: Array<{
|
|
value?: string | null;
|
|
label?: string | null;
|
|
sub?: string | null;
|
|
} | null> | null;
|
|
sectionBackground?: string | null;
|
|
cardBackground?: string | null;
|
|
gold?: string | null;
|
|
charcoal?: string | null;
|
|
muted?: string | null;
|
|
verifiedGreen?: string | null;
|
|
gridLine?: string | null;
|
|
dotInactive?: string | null;
|
|
} | null;
|
|
|
|
function clampRating(n: number): number {
|
|
if (!Number.isFinite(n)) return 5;
|
|
return Math.max(1, Math.min(5, Math.round(n)));
|
|
}
|
|
|
|
/** From `React/src/app/components/Testimonials.tsx`. */
|
|
export const MOCK_TESTIMONIALS_SECTION_CMS: TestimonialsSectionCms = {
|
|
title: 'What Our Community Says',
|
|
sectionBackground: '#ede8e0',
|
|
cardBackground: '#f8f4ef',
|
|
gold: '#b39763',
|
|
charcoal: '#1a1a18',
|
|
muted: '#7a7068',
|
|
verifiedGreen: '#257910',
|
|
gridLine: 'rgba(26, 26, 24, 0.08)',
|
|
dotInactive: 'rgba(26, 26, 24, 0.2)',
|
|
stats: [
|
|
{
|
|
value: '5',
|
|
label: 'Targeted Ayurvedic Botanicals',
|
|
sub: 'Small batches, High standards',
|
|
},
|
|
{value: '96%', label: 'Would Recommend', sub: 'To a friend or family'},
|
|
{
|
|
value: '98%',
|
|
label: 'Naturally derived ingredients',
|
|
sub: '0% synthetic fragrances, sulphates or parabens',
|
|
},
|
|
],
|
|
testimonials: [
|
|
{
|
|
name: 'Namita',
|
|
location: '',
|
|
avatarInitials: 'NA',
|
|
rating: 5,
|
|
product: 'Hydra Face serum',
|
|
text:
|
|
"After a few weeks of using this saffron serum, it's become part of my routine. The formula feels luxurious without being heavy, and my skin feels noticeably softer. The subtle, warm herbal scent makes each application feel soothing and indulgent. Over time, I've noticed a more balanced, dewy look; it's not instant results, but a gentle glow that builds with consistency.",
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Vidhi Desai',
|
|
location: '',
|
|
avatarInitials: 'VD',
|
|
rating: 5,
|
|
product: 'Hydra Face serum',
|
|
text:
|
|
"The first thing that I usually notice in any beauty product is its fragrance, and the entire product line have very soothing fragrance. For the serum as its name suggests hydra, it does hydrate skin with natural oils. So far no negative results that I see on my face after using any of these products.",
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Anshuman Rajurkar',
|
|
location: '',
|
|
avatarInitials: 'AR',
|
|
rating: 5,
|
|
product: 'Hydrating Moisturizer',
|
|
text:
|
|
"I've been using this for three months, and my skin feels much firmer and looks more radiant. It has helped reduce the appearance of dry patches and gives a nice, healthy glow. It's very gentle, and I feel confident knowing I'm putting clean, botanical ingredients on my face. It also has very soothing fragrance. Highly recommend for daily use!",
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Arundhati',
|
|
location: '',
|
|
avatarInitials: 'AU',
|
|
rating: 5,
|
|
product: 'Hydra Face serum',
|
|
text:
|
|
'Very nice product with the richness of ayurveda! ingredients like the natural oil named kumkumadi oil which nourishes the skin and gives glow',
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Varsha Sethi',
|
|
location: '',
|
|
avatarInitials: 'VS',
|
|
rating: 5,
|
|
product: 'Hydra Cleansing Oil',
|
|
text:
|
|
'Love the consistency and the scent. The product does a great job at removing all the makeup and is a great first step in the nighttime skincare regimen.',
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Aditi Pandit',
|
|
location: '',
|
|
avatarInitials: 'AP',
|
|
rating: 5,
|
|
product: 'Hydrating Moisturizer',
|
|
text:
|
|
'I loved how my skin felt soft and hydrated even after one use. Plus it smells great.',
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Shweta A',
|
|
location: '',
|
|
avatarInitials: 'SA',
|
|
rating: 5,
|
|
product: 'Hydrating Moisturizer',
|
|
text:
|
|
"Simply loved the quality, fragrance and texture of it. It leaves skin smooth, nourished and moisturized for the whole day.\nSometimes I just add sunscreen on top and I am set for the day.",
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Amruta',
|
|
location: '',
|
|
avatarInitials: 'AM',
|
|
rating: 5,
|
|
product: 'Brightening Face Mask',
|
|
text:
|
|
"I bought the Brightening face mask which has natural ingredients like avocado and almond oil along with vitamin c which helps brighten the skin tone. After regular applications I definitely feel my skin has a genuine glow due to which this face mask has become my go to for special occasions. It's a definite repurchase for me as it's effective, easy to use and brightens my skin.",
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Rikita Shah',
|
|
location: '',
|
|
avatarInitials: 'RS',
|
|
rating: 5,
|
|
product: 'Hydrating Moisturizer',
|
|
text:
|
|
'I have used more than 1 product of this brand. I am amazed with the results. I strongly recommend it.',
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Hemali Potdar',
|
|
location: '',
|
|
avatarInitials: 'HP',
|
|
rating: 5,
|
|
product: 'Hydrating Moisturizer',
|
|
text:
|
|
'I used all the products in the experience kit. All products are very high quality. My favorite is the moisturizer. It gives Intense moisturizing with very little cream. Scent is amazing as well. Highly recommended.',
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Juhi Dua',
|
|
location: '',
|
|
avatarInitials: 'JD',
|
|
rating: 5,
|
|
product: 'Hydrating Moisturizer',
|
|
text:
|
|
"I absolutely love ABiiR Skincare products! The texture, fragrance, and overall formulation feel incredibly premium and truly skin-friendly. Within a short time, I noticed a visible improvement in my skin's glow and hydration. My skin feels softer, clearer, and much more refreshed. The products absorb beautifully without feeling heavy or greasy, which makes them perfect for everyday use. You can genuinely tell that a lot of thought, care, and passion has gone into creating them. Highly recommended!",
|
|
verified: true,
|
|
},
|
|
{
|
|
name: 'Neha Nayak',
|
|
location: '',
|
|
avatarInitials: 'NN',
|
|
rating: 5,
|
|
product: 'Hydra Face serum',
|
|
text:
|
|
"This is such a thoughtful skincare set. You can feel the care and intention behind it the moment you hold it.\nThe fragrances are beautiful and instantly transport you somewhere calm and indulgent. It feels like a little moment of self-care in the middle of a busy day.\nWhat I love most is how giftable this is. It's the kind of gift that would make anyone feel truly special and pampered the moment they receive it.",
|
|
verified: true,
|
|
},
|
|
],
|
|
};
|
|
|
|
export function normalizeTestimonialsSanityPayload(
|
|
raw: unknown,
|
|
): TestimonialsSectionCms | null {
|
|
if (raw == null || typeof raw !== 'object') return null;
|
|
const b = raw as SanityTestimonialsPayload;
|
|
if (!b?.title || !b?.testimonials?.length) return null;
|
|
|
|
const testimonials: TestimonialItemCms[] = [];
|
|
for (const row of b.testimonials) {
|
|
if (
|
|
!row?.name ||
|
|
!row?.location ||
|
|
!row?.avatarInitials ||
|
|
!row?.product ||
|
|
!row?.text
|
|
) {
|
|
continue;
|
|
}
|
|
testimonials.push({
|
|
name: row.name,
|
|
location: row.location,
|
|
avatarInitials: row.avatarInitials.trim(),
|
|
rating: clampRating(row.rating ?? 5),
|
|
product: row.product,
|
|
text: row.text,
|
|
verified: Boolean(row.verified),
|
|
});
|
|
}
|
|
if (!testimonials.length) return null;
|
|
|
|
const statRows = b.stats?.filter(
|
|
(s): s is {value: string; label: string; sub: string} =>
|
|
Boolean(s?.value && s?.label && s?.sub),
|
|
);
|
|
if (!statRows || statRows.length !== 3) return null;
|
|
|
|
return {
|
|
title: b.title,
|
|
testimonials,
|
|
stats: [statRows[0], statRows[1], statRows[2]],
|
|
sectionBackground: b.sectionBackground ?? '#ede8e0',
|
|
cardBackground: b.cardBackground ?? '#f8f4ef',
|
|
gold: b.gold ?? '#b39763',
|
|
charcoal: b.charcoal ?? '#1a1a18',
|
|
muted: b.muted ?? '#7a7068',
|
|
verifiedGreen: b.verifiedGreen ?? '#257910',
|
|
gridLine: b.gridLine ?? 'rgba(26, 26, 24, 0.08)',
|
|
dotInactive: b.dotInactive ?? 'rgba(26, 26, 24, 0.2)',
|
|
};
|
|
}
|
|
|
|
export async function loadTestimonialsFromSanity(args: {
|
|
sanity: SanityContext;
|
|
groq: string;
|
|
}): Promise<{testimonialsCms: TestimonialsSectionCms}> {
|
|
const initial: QueryResponseInitial<SanityTestimonialsPayload> = await args.sanity
|
|
.loadQuery<SanityTestimonialsPayload>(args.groq)
|
|
.catch(
|
|
(): QueryResponseInitial<SanityTestimonialsPayload> => ({
|
|
data: null,
|
|
sourceMap: undefined,
|
|
}),
|
|
);
|
|
const normalized = normalizeTestimonialsSanityPayload(initial.data);
|
|
return {
|
|
testimonialsCms: normalized ?? MOCK_TESTIMONIALS_SECTION_CMS,
|
|
};
|
|
}
|