feat(storefront): add Google Analytics integration, PDP interactive gallery, feedback & storefront CMS pages
This commit is contained in:
parent
f361732ff9
commit
f9797fee68
15 changed files with 649 additions and 128 deletions
|
|
@ -19,16 +19,19 @@ import {
|
||||||
export default function AboutPage() {
|
export default function AboutPage() {
|
||||||
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
||||||
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
||||||
|
const [layoutSections, setLayoutSections] = useState<any[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
Promise.all([
|
Promise.all([
|
||||||
storefrontService.getFooterInfo(),
|
storefrontService.getFooterInfo(),
|
||||||
storefrontService.getSettings(),
|
storefrontService.getSettings(),
|
||||||
]).then(([info, store]) => {
|
storefrontService.getPageLayout('about'),
|
||||||
|
]).then(([info, store, layout]) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (info) setFooter(info);
|
if (info) setFooter(info);
|
||||||
if (store) setSettings(store);
|
if (store) setSettings(store);
|
||||||
|
if (layout && layout.length > 0) setLayoutSections(layout);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
@ -36,9 +39,32 @@ export default function AboutPage() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const storeName = settings.store_name || 'iFixKart';
|
const storeName = settings.store_name || 'iFixKart';
|
||||||
const phone = footer.phone || settings.support_phone || '';
|
const heroSec = layoutSections.find((s) => s.region === 'about_hero' || s.type === 'about_hero');
|
||||||
const email = footer.email || '';
|
const featuresSec = layoutSections.find((s) => s.region === 'about_features' || s.type === 'about_features');
|
||||||
const address = footer.address || '';
|
const contactSec = layoutSections.find((s) => s.region === 'about_contact' || s.type === 'about_contact');
|
||||||
|
|
||||||
|
const pageTitle = heroSec?.title || 'About Us';
|
||||||
|
const pageSubtitle = heroSec?.subtitle || '';
|
||||||
|
const heroMeta = heroSec?.metadata || heroSec?.metadata_json || {};
|
||||||
|
const storyParagraphs: string[] = Array.isArray(heroMeta.story_paragraphs) && heroMeta.story_paragraphs.length > 0
|
||||||
|
? heroMeta.story_paragraphs
|
||||||
|
: [
|
||||||
|
`${storeName} sells tested refurbished phones and accessories, and books device repairs. You can shop online, get a screen or battery replaced, or exchange the phone you already have.`,
|
||||||
|
`Repairs are done at our Bengaluru service center or at your doorstep. Refurbished phones are checked before listing and sold with a limited warranty.`,
|
||||||
|
];
|
||||||
|
|
||||||
|
const featureCards: any[] = Array.isArray(featuresSec?.metadata?.cards || featuresSec?.metadata_json?.cards) && (featuresSec?.metadata?.cards || featuresSec?.metadata_json?.cards).length > 0
|
||||||
|
? (featuresSec?.metadata?.cards || featuresSec?.metadata_json?.cards)
|
||||||
|
: [
|
||||||
|
{ id: '1', title: 'Shop', desc: 'Refurbished phones, spare parts, and accessories.', link: '/shop', icon: 'smartphone' },
|
||||||
|
{ id: '2', title: 'Repair', desc: 'Screens, batteries, charging ports, and other common jobs.', link: '/repair-services', icon: 'wrench' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const contactMeta = contactSec?.metadata || contactSec?.metadata_json || {};
|
||||||
|
const phone = contactMeta.phone || footer.phone || settings.support_phone || '';
|
||||||
|
const email = contactMeta.email || footer.email || '';
|
||||||
|
const address = contactMeta.address || footer.address || '';
|
||||||
|
const hours = contactMeta.hours || '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
||||||
|
|
@ -50,39 +76,42 @@ export default function AboutPage() {
|
||||||
<main className="flex-grow py-10 pb-20">
|
<main className="flex-grow py-10 pb-20">
|
||||||
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[860px]">
|
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[860px]">
|
||||||
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
||||||
About Us
|
{pageTitle}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-[15px] text-gray-600 leading-relaxed mt-3">
|
{pageSubtitle ? (
|
||||||
{storeName} sells tested refurbished phones and accessories, and books device repairs.
|
<p className="text-[16px] text-primary font-medium mt-1">
|
||||||
You can shop online, get a screen or battery replaced, or exchange the phone you
|
{pageSubtitle}
|
||||||
already have.
|
</p>
|
||||||
</p>
|
) : null}
|
||||||
<p className="text-[15px] text-gray-600 leading-relaxed mt-3">
|
|
||||||
Repairs are done at our Bengaluru service center or at your doorstep. Refurbished
|
|
||||||
phones are checked before listing and sold with a limited warranty.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-8">
|
{storyParagraphs.map((para, i) => (
|
||||||
<Link
|
<p key={i} className="text-[15px] text-gray-600 leading-relaxed mt-3">
|
||||||
href="/shop"
|
{para}
|
||||||
className="bg-white border border-gray-200 rounded-xl p-5 hover:border-primary/40 transition-colors"
|
</p>
|
||||||
>
|
))}
|
||||||
<Smartphone className="w-5 h-5 text-primary mb-3" />
|
|
||||||
<h2 className="text-[16px] font-bold text-[#1E293B]">Shop</h2>
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 mt-8">
|
||||||
<p className="text-[13px] text-gray-500 mt-1 leading-relaxed">
|
{featureCards.map((card, i) => {
|
||||||
Refurbished phones, spare parts, and accessories.
|
const isRepair = (card.icon || '').toLowerCase().includes('wrench') || (card.title || '').toLowerCase().includes('repair');
|
||||||
</p>
|
const to = card.link || (isRepair ? '/repair-services' : '/shop');
|
||||||
</Link>
|
return (
|
||||||
<Link
|
<Link
|
||||||
href="/repair-services"
|
key={card.id || i}
|
||||||
className="bg-white border border-gray-200 rounded-xl p-5 hover:border-primary/40 transition-colors"
|
href={to}
|
||||||
>
|
className="bg-white border border-gray-200 rounded-xl p-5 hover:border-primary/40 hover:shadow-sm transition-all"
|
||||||
<Wrench className="w-5 h-5 text-primary mb-3" />
|
>
|
||||||
<h2 className="text-[16px] font-bold text-[#1E293B]">Repair</h2>
|
{isRepair ? (
|
||||||
<p className="text-[13px] text-gray-500 mt-1 leading-relaxed">
|
<Wrench className="w-5 h-5 text-primary mb-3" />
|
||||||
Screens, batteries, charging ports, and other common jobs.
|
) : (
|
||||||
</p>
|
<Smartphone className="w-5 h-5 text-primary mb-3" />
|
||||||
</Link>
|
)}
|
||||||
|
<h2 className="text-[16px] font-bold text-[#1E293B]">{card.title}</h2>
|
||||||
|
<p className="text-[13px] text-gray-500 mt-1 leading-relaxed">
|
||||||
|
{card.desc}
|
||||||
|
</p>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-8 bg-white border border-gray-200 rounded-xl p-5 md:p-6 space-y-4">
|
<div className="mt-8 bg-white border border-gray-200 rounded-xl p-5 md:p-6 space-y-4">
|
||||||
|
|
@ -92,6 +121,12 @@ export default function AboutPage() {
|
||||||
<p className="text-[14px] text-gray-600 leading-relaxed">{address}</p>
|
<p className="text-[14px] text-gray-600 leading-relaxed">{address}</p>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
{hours ? (
|
||||||
|
<div className="flex gap-3 text-[14px] text-gray-600">
|
||||||
|
<span className="w-4 h-4 text-gray-400 mt-0.5 shrink-0 font-bold text-center">⏱</span>
|
||||||
|
<p className="text-[14px] text-gray-600 leading-relaxed">{hours}</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
{phone ? (
|
{phone ? (
|
||||||
<a
|
<a
|
||||||
href={`tel:${phone.replace(/[^\d+]/g, '')}`}
|
href={`tel:${phone.replace(/[^\d+]/g, '')}`}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,13 @@ export default function FaqsPage() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
storefrontService.getFaqLayout().then((raw) => {
|
Promise.all([
|
||||||
if (!cancelled) setData(parseFaqPageData(raw));
|
storefrontService.getPageLayout('faqs'),
|
||||||
|
storefrontService.getFaqLayout(),
|
||||||
|
]).then(([faqsData, legacyData]) => {
|
||||||
|
if (cancelled) return;
|
||||||
|
const raw = Array.isArray(faqsData) && faqsData.length > 0 ? faqsData : legacyData;
|
||||||
|
setData(parseFaqPageData(raw));
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ const labelClass = 'block text-[12px] font-bold text-[#1E293B] mb-1.5';
|
||||||
export default function FeedbackPage() {
|
export default function FeedbackPage() {
|
||||||
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
||||||
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
||||||
|
const [layoutSections, setLayoutSections] = useState<any[]>([]);
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [topic, setTopic] = useState('suggestion');
|
const [topic, setTopic] = useState('suggestion');
|
||||||
|
|
@ -38,16 +39,19 @@ export default function FeedbackPage() {
|
||||||
const [rating, setRating] = useState(0);
|
const [rating, setRating] = useState(0);
|
||||||
const [message, setMessage] = useState('');
|
const [message, setMessage] = useState('');
|
||||||
const [submitted, setSubmitted] = useState(false);
|
const [submitted, setSubmitted] = useState(false);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
Promise.all([
|
Promise.all([
|
||||||
storefrontService.getFooterInfo(),
|
storefrontService.getFooterInfo(),
|
||||||
storefrontService.getSettings(),
|
storefrontService.getSettings(),
|
||||||
]).then(([info, store]) => {
|
storefrontService.getPageLayout('feedback'),
|
||||||
|
]).then(([info, store, layout]) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (info) setFooter(info);
|
if (info) setFooter(info);
|
||||||
if (store) setSettings(store);
|
if (store) setSettings(store);
|
||||||
|
if (layout && layout.length > 0) setLayoutSections(layout);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
@ -58,26 +62,34 @@ export default function FeedbackPage() {
|
||||||
const supportEmail = footer.email || 'support@ifixkart.com';
|
const supportEmail = footer.email || 'support@ifixkart.com';
|
||||||
const doc = useMemo(() => buildFeedbackPage(storeName), [storeName]);
|
const doc = useMemo(() => buildFeedbackPage(storeName), [storeName]);
|
||||||
|
|
||||||
const handleSubmit = (e: FormEvent) => {
|
const heroSec = layoutSections.find((s) => s.region === 'feedback_hero' || s.type === 'feedback_hero');
|
||||||
e.preventDefault();
|
const heading = heroSec?.title || doc.heading;
|
||||||
const topicLabel = doc.topics.find((t) => t.id === topic)?.label || topic;
|
const intro = heroSec?.subtitle || doc.intro;
|
||||||
const body = [
|
|
||||||
`Name: ${name}`,
|
|
||||||
`Email: ${email}`,
|
|
||||||
`Topic: ${topicLabel}`,
|
|
||||||
orderNo ? `Order / job: ${orderNo}` : '',
|
|
||||||
rating ? `Rating: ${rating} / 5` : '',
|
|
||||||
'',
|
|
||||||
message,
|
|
||||||
]
|
|
||||||
.filter((line) => line !== '')
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
const href = `mailto:${supportEmail}?subject=${encodeURIComponent(
|
const handleSubmit = async (e: FormEvent) => {
|
||||||
`${storeName} feedback — ${topicLabel}`
|
e.preventDefault();
|
||||||
)}&body=${encodeURIComponent(body)}`;
|
if (!message.trim() || !email.trim()) return;
|
||||||
window.location.href = href;
|
setSubmitting(true);
|
||||||
setSubmitted(true);
|
try {
|
||||||
|
await storefrontService.submitFeedback({
|
||||||
|
name: name.trim() || 'Valued Customer',
|
||||||
|
email: email.trim(),
|
||||||
|
topic,
|
||||||
|
order_no: orderNo.trim() || undefined,
|
||||||
|
rating: rating || 5,
|
||||||
|
message: message.trim(),
|
||||||
|
});
|
||||||
|
setSubmitted(true);
|
||||||
|
} catch {
|
||||||
|
const topicLabel = doc.topics.find((t) => t.id === topic)?.label || topic;
|
||||||
|
const body = `Name: ${name}\nEmail: ${email}\nTopic: ${topicLabel}\nRating: ${rating}\n\n${message}`;
|
||||||
|
window.location.href = `mailto:${supportEmail}?subject=${encodeURIComponent(
|
||||||
|
`${storeName} feedback — ${topicLabel}`
|
||||||
|
)}&body=${encodeURIComponent(body)}`;
|
||||||
|
setSubmitted(true);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -90,9 +102,9 @@ export default function FeedbackPage() {
|
||||||
<main className="flex-grow py-10 pb-20">
|
<main className="flex-grow py-10 pb-20">
|
||||||
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[900px]">
|
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[900px]">
|
||||||
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
||||||
{doc.heading}
|
{heading}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-[14px] text-gray-500 mt-2 max-w-2xl">{doc.intro}</p>
|
<p className="text-[14px] text-gray-500 mt-2 max-w-2xl">{intro}</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4 mt-8">
|
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4 mt-8">
|
||||||
{doc.highlights.map((item) => {
|
{doc.highlights.map((item) => {
|
||||||
|
|
@ -247,9 +259,10 @@ export default function FeedbackPage() {
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="w-full sm:w-auto px-6 py-3 bg-primary text-white text-[14px] font-semibold rounded-lg hover:brightness-95 cursor-pointer"
|
disabled={submitting}
|
||||||
|
className="w-full sm:w-auto px-6 py-3 bg-primary text-white text-[14px] font-semibold rounded-lg hover:brightness-95 cursor-pointer disabled:opacity-50"
|
||||||
>
|
>
|
||||||
Send feedback
|
{submitting ? 'Sending feedback...' : 'Send feedback'}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -43,16 +43,19 @@ function telHref(phone: string): string {
|
||||||
export default function HelpCenterPage() {
|
export default function HelpCenterPage() {
|
||||||
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
||||||
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
||||||
|
const [layoutSections, setLayoutSections] = useState<any[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
Promise.all([
|
Promise.all([
|
||||||
storefrontService.getFooterInfo(),
|
storefrontService.getFooterInfo(),
|
||||||
storefrontService.getSettings(),
|
storefrontService.getSettings(),
|
||||||
]).then(([info, store]) => {
|
storefrontService.getPageLayout('help'),
|
||||||
|
]).then(([info, store, layout]) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (info) setFooter(info);
|
if (info) setFooter(info);
|
||||||
if (store) setSettings(store);
|
if (store) setSettings(store);
|
||||||
|
if (layout && layout.length > 0) setLayoutSections(layout);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
@ -64,6 +67,21 @@ export default function HelpCenterPage() {
|
||||||
const email = footer.email || '';
|
const email = footer.email || '';
|
||||||
const doc = useMemo(() => buildHelpDoc(storeName), [storeName]);
|
const doc = useMemo(() => buildHelpDoc(storeName), [storeName]);
|
||||||
|
|
||||||
|
const heroSec = layoutSections.find((s) => s.region === 'help_hero' || s.type === 'help_hero');
|
||||||
|
const topicsSec = layoutSections.find((s) => s.region === 'help_topics' || s.type === 'help_topics');
|
||||||
|
|
||||||
|
const heading = heroSec?.title || doc.heading;
|
||||||
|
const intro = heroSec?.subtitle || doc.intro;
|
||||||
|
const topicsMeta = topicsSec?.metadata || topicsSec?.metadata_json || {};
|
||||||
|
const topics = Array.isArray(topicsMeta.topics) && topicsMeta.topics.length > 0
|
||||||
|
? topicsMeta.topics.map((t: any) => ({
|
||||||
|
id: t.id || 'general',
|
||||||
|
title: t.title || t.name,
|
||||||
|
desc: t.desc || t.description,
|
||||||
|
href: t.href || t.link || '/help',
|
||||||
|
}))
|
||||||
|
: doc.topics;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
||||||
<AnnouncementBar />
|
<AnnouncementBar />
|
||||||
|
|
@ -74,12 +92,12 @@ export default function HelpCenterPage() {
|
||||||
<main className="flex-grow py-10 pb-20">
|
<main className="flex-grow py-10 pb-20">
|
||||||
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[900px]">
|
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[900px]">
|
||||||
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
||||||
{doc.heading}
|
{heading}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-[14px] text-gray-500 mt-2 max-w-2xl">{doc.intro}</p>
|
<p className="text-[14px] text-gray-500 mt-2 max-w-2xl">{intro}</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-8">
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-8">
|
||||||
{doc.topics.map((item) => {
|
{topics.map((item: any) => {
|
||||||
const Icon = TOPIC_ICONS[item.id as keyof typeof TOPIC_ICONS] || CircleHelp;
|
const Icon = TOPIC_ICONS[item.id as keyof typeof TOPIC_ICONS] || CircleHelp;
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
import './globals.css';
|
import './globals.css';
|
||||||
import '../styles/mobile-overrides.css';
|
import '../styles/mobile-overrides.css';
|
||||||
|
import { Suspense } from 'react';
|
||||||
import { AuthBootstrap } from '@/components/auth/AuthBootstrap';
|
import { AuthBootstrap } from '@/components/auth/AuthBootstrap';
|
||||||
import { StorefrontChrome } from '@/components/store/StorefrontChrome';
|
import { StorefrontChrome } from '@/components/store/StorefrontChrome';
|
||||||
import { ClientModalsContainer } from '@/components/ClientModalsContainer';
|
import { ClientModalsContainer } from '@/components/ClientModalsContainer';
|
||||||
|
import { GoogleAnalytics } from '@/components/analytics/GoogleAnalytics';
|
||||||
import { Toaster } from 'sonner';
|
import { Toaster } from 'sonner';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
|
|
@ -26,6 +28,9 @@ export default function RootLayout({
|
||||||
return (
|
return (
|
||||||
<html lang="en" className="h-full">
|
<html lang="en" className="h-full">
|
||||||
<body className="flex flex-col min-h-screen bg-[#F8F9FB] text-[#1E293B] font-sans antialiased">
|
<body className="flex flex-col min-h-screen bg-[#F8F9FB] text-[#1E293B] font-sans antialiased">
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<GoogleAnalytics />
|
||||||
|
</Suspense>
|
||||||
<Toaster position="top-right" richColors closeButton expand={true} />
|
<Toaster position="top-right" richColors closeButton expand={true} />
|
||||||
<AuthBootstrap />
|
<AuthBootstrap />
|
||||||
<StorefrontChrome />
|
<StorefrontChrome />
|
||||||
|
|
|
||||||
|
|
@ -32,16 +32,19 @@ function telHref(phone: string): string {
|
||||||
export default function PaymentsPage() {
|
export default function PaymentsPage() {
|
||||||
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
||||||
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
||||||
|
const [layoutSections, setLayoutSections] = useState<any[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
Promise.all([
|
Promise.all([
|
||||||
storefrontService.getFooterInfo(),
|
storefrontService.getFooterInfo(),
|
||||||
storefrontService.getSettings(),
|
storefrontService.getSettings(),
|
||||||
]).then(([info, store]) => {
|
storefrontService.getPageLayout('payments'),
|
||||||
|
]).then(([info, store, layout]) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (info) setFooter(info);
|
if (info) setFooter(info);
|
||||||
if (store) setSettings(store);
|
if (store) setSettings(store);
|
||||||
|
if (layout && layout.length > 0) setLayoutSections(layout);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
@ -54,6 +57,10 @@ export default function PaymentsPage() {
|
||||||
const doc = useMemo(() => buildPaymentsDoc(storeName), [storeName]);
|
const doc = useMemo(() => buildPaymentsDoc(storeName), [storeName]);
|
||||||
const methods = (footer.payment_methods || []).filter((p) => p?.name || p?.icon_url);
|
const methods = (footer.payment_methods || []).filter((p) => p?.name || p?.icon_url);
|
||||||
|
|
||||||
|
const heroSec = layoutSections.find((s) => s.region === 'payments_hero' || s.type === 'payments_hero');
|
||||||
|
const heading = heroSec?.title || doc.heading;
|
||||||
|
const intro = heroSec?.subtitle || doc.intro;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
||||||
<AnnouncementBar />
|
<AnnouncementBar />
|
||||||
|
|
@ -64,9 +71,9 @@ export default function PaymentsPage() {
|
||||||
<main className="flex-grow py-10 pb-20">
|
<main className="flex-grow py-10 pb-20">
|
||||||
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[900px]">
|
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-[900px]">
|
||||||
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
<h1 className="text-[28px] md:text-[32px] font-bold text-[#1E293B]">
|
||||||
{doc.heading}
|
{heading}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-[14px] text-gray-500 mt-2 max-w-2xl">{doc.intro}</p>
|
<p className="text-[14px] text-gray-500 mt-2 max-w-2xl">{intro}</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-8">
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-8">
|
||||||
{doc.highlights.map((item) => {
|
{doc.highlights.map((item) => {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ const HIDDEN_SPEC_KEYS = [
|
||||||
'sku',
|
'sku',
|
||||||
'barcode',
|
'barcode',
|
||||||
'compare_price',
|
'compare_price',
|
||||||
|
'is_active',
|
||||||
|
'is_parent_feature',
|
||||||
];
|
];
|
||||||
|
|
||||||
function normalizeSpecKey(code: string): string {
|
function normalizeSpecKey(code: string): string {
|
||||||
|
|
@ -388,8 +390,52 @@ export default async function ProductDetailPage({ params }: ProductDetailPagePro
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const primaryVariant = product.variants?.[0];
|
||||||
|
const primaryImage = product.images?.[0]?.image_url || '/images/placeholder-product.webp';
|
||||||
|
const resolvedImageUrl = primaryImage.startsWith('http')
|
||||||
|
? primaryImage
|
||||||
|
: `https://ifixkartbe.trionixsolution.com/uploads/${primaryImage.replace(/^\//, '')}`;
|
||||||
|
|
||||||
|
const jsonLd = {
|
||||||
|
'@context': 'https://schema.org/',
|
||||||
|
'@type': 'Product',
|
||||||
|
name: product.name,
|
||||||
|
image: [resolvedImageUrl],
|
||||||
|
description: product.seo_description || product.description || `${product.name} with certified warranty at iFixKart.`,
|
||||||
|
sku: primaryVariant?.sku || String(product.product_id),
|
||||||
|
mpn: primaryVariant?.barcode || primaryVariant?.sku || String(product.product_id),
|
||||||
|
brand: {
|
||||||
|
'@type': 'Brand',
|
||||||
|
name: product.brand?.name || 'iFixKart',
|
||||||
|
},
|
||||||
|
offers: {
|
||||||
|
'@type': 'Offer',
|
||||||
|
url: `https://ifixkart.trionixsolution.com/products/${product.slug}`,
|
||||||
|
priceCurrency: 'INR',
|
||||||
|
price: primaryVariant?.price || 0,
|
||||||
|
priceValidUntil: '2027-12-31',
|
||||||
|
itemCondition: 'https://schema.org/NewCondition',
|
||||||
|
availability: (primaryVariant?.price && Number(primaryVariant?.price) > 0)
|
||||||
|
? 'https://schema.org/InStock'
|
||||||
|
: 'https://schema.org/OutOfStock',
|
||||||
|
seller: {
|
||||||
|
'@type': 'Organization',
|
||||||
|
name: 'iFixKart TechShop',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
aggregateRating: reviews.length > 0 ? {
|
||||||
|
'@type': 'AggregateRating',
|
||||||
|
ratingValue: '4.8',
|
||||||
|
reviewCount: String(reviews.length),
|
||||||
|
} : undefined,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-white text-[#1E293B] flex flex-col font-sans">
|
<div className="min-h-screen bg-white text-[#1E293B] flex flex-col font-sans">
|
||||||
|
<script
|
||||||
|
type="application/ld+json"
|
||||||
|
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
||||||
|
/>
|
||||||
<AnnouncementBar />
|
<AnnouncementBar />
|
||||||
<Header />
|
<Header />
|
||||||
<StickyHeaderSpacer />
|
<StickyHeaderSpacer />
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ export const FloatingButtons: React.FC = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed bottom-6 right-6 z-50 flex flex-col gap-3">
|
<div className="fixed bottom-6 right-6 z-50 flex flex-col items-center gap-3">
|
||||||
|
|
||||||
{/* Scroll to Top */}
|
{/* Scroll to Top */}
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{showScrollTop && (
|
{showScrollTop && (
|
||||||
|
|
@ -44,3 +45,4 @@ export const FloatingButtons: React.FC = () => {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
46
components/analytics/GoogleAnalytics.tsx
Normal file
46
components/analytics/GoogleAnalytics.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import Script from 'next/script';
|
||||||
|
import { usePathname, useSearchParams } from 'next/navigation';
|
||||||
|
import { GA_MEASUREMENT_ID, trackPageView } from '@/lib/analytics';
|
||||||
|
|
||||||
|
export function GoogleAnalytics() {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (pathname) {
|
||||||
|
const fullUrl = searchParams?.toString()
|
||||||
|
? `${pathname}?${searchParams.toString()}`
|
||||||
|
: pathname;
|
||||||
|
trackPageView(fullUrl);
|
||||||
|
}
|
||||||
|
}, [pathname, searchParams]);
|
||||||
|
|
||||||
|
if (!GA_MEASUREMENT_ID) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Script
|
||||||
|
strategy="afterInteractive"
|
||||||
|
src={`https://www.googletagmanager.com/gtag/js?id=${GA_MEASUREMENT_ID}`}
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
id="ga4-init"
|
||||||
|
strategy="afterInteractive"
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: `
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', '${GA_MEASUREMENT_ID}', {
|
||||||
|
page_path: window.location.pathname,
|
||||||
|
send_page_view: true
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,12 @@ import {
|
||||||
type StorefrontSettings,
|
type StorefrontSettings,
|
||||||
MOCK_FOOTER_INFO,
|
MOCK_FOOTER_INFO,
|
||||||
} from '@/services/api/storefrontService';
|
} from '@/services/api/storefrontService';
|
||||||
import { buildPrivacyDoc, buildTermsDoc } from '@/lib/legalContent';
|
import {
|
||||||
|
buildPrivacyDoc,
|
||||||
|
buildTermsDoc,
|
||||||
|
type LegalDoc,
|
||||||
|
type LegalSection,
|
||||||
|
} from '@/lib/legalContent';
|
||||||
|
|
||||||
export type LegalTab = 'terms' | 'privacy';
|
export type LegalTab = 'terms' | 'privacy';
|
||||||
|
|
||||||
|
|
@ -26,6 +31,7 @@ export function LegalPage({ initialTab }: { initialTab: LegalTab }) {
|
||||||
const [tab, setTab] = useState<LegalTab>(initialTab);
|
const [tab, setTab] = useState<LegalTab>(initialTab);
|
||||||
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
const [footer, setFooter] = useState<FooterInfo>(MOCK_FOOTER_INFO);
|
||||||
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
const [settings, setSettings] = useState<StorefrontSettings>({ store_name: 'iFixKart' });
|
||||||
|
const [layoutSections, setLayoutSections] = useState<any[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTab(initialTab);
|
setTab(initialTab);
|
||||||
|
|
@ -36,10 +42,12 @@ export function LegalPage({ initialTab }: { initialTab: LegalTab }) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
storefrontService.getFooterInfo(),
|
storefrontService.getFooterInfo(),
|
||||||
storefrontService.getSettings(),
|
storefrontService.getSettings(),
|
||||||
]).then(([info, store]) => {
|
storefrontService.getPageLayout('terms'),
|
||||||
|
]).then(([info, store, layout]) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (info) setFooter(info);
|
if (info) setFooter(info);
|
||||||
if (store) setSettings(store);
|
if (store) setSettings(store);
|
||||||
|
if (layout && layout.length > 0) setLayoutSections(layout);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
@ -51,10 +59,27 @@ export function LegalPage({ initialTab }: { initialTab: LegalTab }) {
|
||||||
const email = footer.email || '';
|
const email = footer.email || '';
|
||||||
const address = footer.address || '';
|
const address = footer.address || '';
|
||||||
|
|
||||||
const doc = useMemo(
|
const termsSec = layoutSections.find((s) => s.region === 'terms_clauses' || s.type === 'terms_clauses');
|
||||||
() => (tab === 'privacy' ? buildPrivacyDoc(storeName) : buildTermsDoc(storeName)),
|
const privacySec = layoutSections.find((s) => s.region === 'privacy_clauses' || s.type === 'privacy_clauses');
|
||||||
[tab, storeName]
|
|
||||||
);
|
const doc = useMemo<LegalDoc>(() => {
|
||||||
|
const defaultDoc = tab === 'privacy' ? buildPrivacyDoc(storeName) : buildTermsDoc(storeName);
|
||||||
|
const activeSec = tab === 'privacy' ? privacySec : termsSec;
|
||||||
|
const meta = activeSec?.metadata || activeSec?.metadata_json || {};
|
||||||
|
|
||||||
|
if (Array.isArray(meta.sections) && meta.sections.length > 0) {
|
||||||
|
return {
|
||||||
|
heading: activeSec?.title || defaultDoc.heading,
|
||||||
|
intro: activeSec?.subtitle || defaultDoc.intro,
|
||||||
|
sections: meta.sections.map((s: any, idx: number): LegalSection => ({
|
||||||
|
id: s.id || `custom-${idx}`,
|
||||||
|
title: s.title || `Section ${idx + 1}`,
|
||||||
|
paragraphs: Array.isArray(s.paragraphs) ? s.paragraphs : [s.content || s.text || ''],
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return defaultDoc;
|
||||||
|
}, [tab, storeName, termsSec, privacySec]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
<div className="min-h-screen bg-[#F8F9FB] text-[#1E293B] flex flex-col font-sans">
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,12 @@ import {
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
Wrench,
|
Wrench,
|
||||||
Sparkles,
|
Sparkles,
|
||||||
|
Zap,
|
||||||
|
MapPin,
|
||||||
|
Clock,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
import { requireLoginForCheckout } from '@/lib/requireLoginForCheckout';
|
||||||
|
import { trackViewItem, trackAddToCart, trackBeginCheckout } from '@/lib/analytics';
|
||||||
|
|
||||||
interface ProductInteractiveGridProps {
|
interface ProductInteractiveGridProps {
|
||||||
product: ProductResponse;
|
product: ProductResponse;
|
||||||
|
|
@ -187,17 +192,7 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
|
|
||||||
const selectedVariant =
|
const selectedVariant =
|
||||||
product.variants && product.variants.length > 0
|
product.variants && product.variants.length > 0
|
||||||
? product.variants[selectedVariantIndex] ||
|
? product.variants[selectedVariantIndex] || product.variants[0]
|
||||||
product.variants.find((v: any) => {
|
|
||||||
if (!lookupIndex.current) return false;
|
|
||||||
const attrMap = lookupIndex.current.variantAttrsMap.get(v.variant_id);
|
|
||||||
if (!attrMap || attrMap.size === 0) return false;
|
|
||||||
return (
|
|
||||||
Object.entries(selections).length > 0 &&
|
|
||||||
Object.entries(selections).every(([k, vVal]) => attrMap.get(k) === vVal)
|
|
||||||
);
|
|
||||||
}) ||
|
|
||||||
product.variants[0]
|
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -261,6 +256,10 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
router.push(`/services?${qs.toString()}`);
|
router.push(`/services?${qs.toString()}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Delivery SLA & Pincode Checker
|
||||||
|
const [deliveryPincode, setDeliveryPincode] = useState('560001');
|
||||||
|
const [pincodeChecked, setPincodeChecked] = useState(true);
|
||||||
|
|
||||||
const handleAddToCart = () => {
|
const handleAddToCart = () => {
|
||||||
if (selectedVariant) {
|
if (selectedVariant) {
|
||||||
const available = selectedVariant.available_stock;
|
const available = selectedVariant.available_stock;
|
||||||
|
|
@ -268,6 +267,15 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addToCart(product, selectedVariant, quantity);
|
addToCart(product, selectedVariant, quantity);
|
||||||
|
trackAddToCart({
|
||||||
|
id: product.product_id,
|
||||||
|
name: product.name,
|
||||||
|
price: selectedPrice,
|
||||||
|
category: (product as any).category?.name || 'Spare Parts',
|
||||||
|
brand: (product as any).brand?.name || 'iFixKart',
|
||||||
|
sku: selectedVariant.sku,
|
||||||
|
quantity,
|
||||||
|
});
|
||||||
Object.entries(addonQty).forEach(([productId, qty]) => {
|
Object.entries(addonQty).forEach(([productId, qty]) => {
|
||||||
if (qty <= 0) return;
|
if (qty <= 0) return;
|
||||||
const addon = relatedProducts.find((p) => p.product_id === productId);
|
const addon = relatedProducts.find((p) => p.product_id === productId);
|
||||||
|
|
@ -280,6 +288,36 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBuyNow = () => {
|
||||||
|
if (!selectedVariant || outOfStock) return;
|
||||||
|
const available = selectedVariant.available_stock;
|
||||||
|
if (typeof available === 'number' && (available <= 0 || quantity > available)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addToCart(product, selectedVariant, quantity);
|
||||||
|
trackBeginCheckout(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
variant_id: selectedVariant.variant_id,
|
||||||
|
product_id: product.product_id,
|
||||||
|
name: product.name,
|
||||||
|
price: selectedPrice,
|
||||||
|
quantity,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
selectedPrice * quantity
|
||||||
|
);
|
||||||
|
Object.entries(addonQty).forEach(([productId, qty]) => {
|
||||||
|
if (qty <= 0) return;
|
||||||
|
const addon = relatedProducts.find((p) => p.product_id === productId);
|
||||||
|
const variant = addon?.variants?.[0];
|
||||||
|
if (addon && variant) void addToCart(addon, variant, qty);
|
||||||
|
});
|
||||||
|
window.dispatchEvent(new Event('wishlistUpdated'));
|
||||||
|
if (!requireLoginForCheckout('/checkout')) return;
|
||||||
|
router.push('/checkout');
|
||||||
|
};
|
||||||
|
|
||||||
const { price: minPrice, priceMax: maxPrice } = getCatalogPriceInfo(product);
|
const { price: minPrice, priceMax: maxPrice } = getCatalogPriceInfo(product);
|
||||||
const selectedPrice = parseMoney(selectedVariant?.price);
|
const selectedPrice = parseMoney(selectedVariant?.price);
|
||||||
const selectedCompare = parseMoney(selectedVariant?.compare_price);
|
const selectedCompare = parseMoney(selectedVariant?.compare_price);
|
||||||
|
|
@ -294,6 +332,20 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
? Math.round(((selectedCompare - selectedPrice) / selectedCompare) * 100)
|
? Math.round(((selectedCompare - selectedPrice) / selectedCompare) * 100)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
|
// GA4 Telemetry view_item
|
||||||
|
useEffect(() => {
|
||||||
|
if (product && selectedVariant && selectedPrice > 0) {
|
||||||
|
trackViewItem({
|
||||||
|
id: product.product_id,
|
||||||
|
name: product.name,
|
||||||
|
price: selectedPrice,
|
||||||
|
category: (product as any).category?.name || 'Spare Parts',
|
||||||
|
brand: (product as any).brand?.name || 'iFixKart',
|
||||||
|
sku: selectedVariant.sku,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [product?.product_id, selectedVariant?.variant_id, selectedPrice]);
|
||||||
|
|
||||||
const cleanDesc = (product.description || '')
|
const cleanDesc = (product.description || '')
|
||||||
.replace(/</gi, '<')
|
.replace(/</gi, '<')
|
||||||
.replace(/>/gi, '>')
|
.replace(/>/gi, '>')
|
||||||
|
|
@ -321,7 +373,7 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-10 items-start">
|
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-10 items-start">
|
||||||
|
|
||||||
{/* Left Column: Image Gallery */}
|
{/* Left Column: Image Gallery */}
|
||||||
<div className="lg:col-span-6 flex flex-col md:flex-row gap-3">
|
<div className="lg:col-span-6 flex flex-col md:flex-row gap-3">
|
||||||
<div className="flex md:flex-col items-center gap-1.5 order-2 md:order-1 flex-shrink-0 justify-center">
|
<div className="flex md:flex-col items-center gap-1.5 order-2 md:order-1 flex-shrink-0 justify-center">
|
||||||
|
|
@ -343,9 +395,8 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
<button
|
<button
|
||||||
key={idx}
|
key={idx}
|
||||||
onClick={() => setSelectedImage(img)}
|
onClick={() => setSelectedImage(img)}
|
||||||
className={`w-[62px] h-[62px] rounded-sm border p-1 transition-all overflow-hidden flex items-center justify-center bg-white cursor-pointer shrink-0 ${
|
className={`w-[62px] h-[62px] rounded-sm border p-1 transition-all overflow-hidden flex items-center justify-center bg-white cursor-pointer shrink-0 ${selectedImage === img ? 'border-primary' : 'border-gray-200 hover:border-gray-300'
|
||||||
selectedImage === img ? 'border-primary' : 'border-gray-200 hover:border-gray-300'
|
}`}
|
||||||
}`}
|
|
||||||
aria-label={`Select thumbnail ${idx + 1}`}
|
aria-label={`Select thumbnail ${idx + 1}`}
|
||||||
>
|
>
|
||||||
<Image
|
<Image
|
||||||
|
|
@ -453,7 +504,7 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
<div className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-200/80 text-emerald-800 text-[12px] font-semibold">
|
<div className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-200/80 text-emerald-800 text-[12px] font-semibold">
|
||||||
<Sparkles size={14} className="text-emerald-600 shrink-0" />
|
<Sparkles size={14} className="text-emerald-600 shrink-0" />
|
||||||
<span>
|
<span>
|
||||||
Earn 5% Store Credit (≈ {formatCurrency(Math.round(selectedPrice * 0.05))}) after 7-day return window
|
Earn 5% Store Credit After 7-day of the purchase
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -462,12 +513,31 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
{product.variants && product.variants.length > 0 && (
|
{product.variants && product.variants.length > 0 && (
|
||||||
<div className="space-y-4 pt-2 pb-2 border-t border-b border-gray-100 my-4">
|
<div className="space-y-4 pt-2 pb-2 border-t border-b border-gray-100 my-4">
|
||||||
{(() => {
|
{(() => {
|
||||||
|
const IGNORED_ATTR_CODES = new Set([
|
||||||
|
'parent_media_key',
|
||||||
|
'media_key',
|
||||||
|
'is_active',
|
||||||
|
'parent_category',
|
||||||
|
'parent_name',
|
||||||
|
'parent_id',
|
||||||
|
'cost_price',
|
||||||
|
'costprice',
|
||||||
|
'sku',
|
||||||
|
'barcode',
|
||||||
|
'compare_price',
|
||||||
|
'is_parent_feature',
|
||||||
|
'status'
|
||||||
|
]);
|
||||||
|
|
||||||
const dimensions = new Map<string, { code: string; label: string; values: Set<string> }>();
|
const dimensions = new Map<string, { code: string; label: string; values: Set<string> }>();
|
||||||
(product.variants || []).forEach((variant: any) => {
|
(product.variants || []).forEach((variant: any) => {
|
||||||
(variant.attributes || []).forEach((attr: any) => {
|
(variant.attributes || []).forEach((attr: any) => {
|
||||||
const code = String(attr.attribute_code || '').trim();
|
const code = String(attr.attribute_code || '').trim();
|
||||||
const val = String(attr.attribute_value || '').trim();
|
const val = String(attr.attribute_value || '').trim();
|
||||||
if (!code || !val) return;
|
if (!code || !val) return;
|
||||||
|
const normCode = code.toLowerCase();
|
||||||
|
if (IGNORED_ATTR_CODES.has(normCode)) return;
|
||||||
|
|
||||||
if (!dimensions.has(code)) {
|
if (!dimensions.has(code)) {
|
||||||
const rawName = String(attr.attribute_name || '').trim();
|
const rawName = String(attr.attribute_name || '').trim();
|
||||||
let label = rawName && !looksLikeBrandId(rawName)
|
let label = rawName && !looksLikeBrandId(rawName)
|
||||||
|
|
@ -489,15 +559,26 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
dimensions.get(code)!.values.add(val);
|
dimensions.get(code)!.values.add(val);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const dims = Array.from(dimensions.values()).map((d) => ({
|
|
||||||
code: d.code,
|
const dims = Array.from(dimensions.values())
|
||||||
label: d.label,
|
.filter((d) => {
|
||||||
values: Array.from(d.values),
|
if (d.values.size === 0) return false;
|
||||||
}));
|
const vals = Array.from(d.values);
|
||||||
|
if (vals.length === 1 && (vals[0].toUpperCase() === 'N/A' || vals[0] === '' || vals[0].toUpperCase() === 'TRUE' || vals[0].toUpperCase() === 'FALSE')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map((d) => ({
|
||||||
|
code: d.code,
|
||||||
|
label: d.label,
|
||||||
|
values: Array.from(d.values),
|
||||||
|
}));
|
||||||
|
|
||||||
if (dims.length > 0) {
|
if (dims.length > 0) {
|
||||||
return dims.map((dim) => {
|
return dims.map((dim) => {
|
||||||
const currentVal = selections[dim.code] || '';
|
const activeAttr = (selectedVariant?.attributes || []).find((a: any) => a.attribute_code === dim.code);
|
||||||
|
const currentVal = activeAttr?.attribute_value || selections[dim.code] || '';
|
||||||
return (
|
return (
|
||||||
<div key={dim.code} className="space-y-1.5">
|
<div key={dim.code} className="space-y-1.5">
|
||||||
<label className="block text-[12px] font-bold uppercase tracking-wider text-gray-700">
|
<label className="block text-[12px] font-bold uppercase tracking-wider text-gray-700">
|
||||||
|
|
@ -511,18 +592,34 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
key={val}
|
key={val}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const next = { ...selections, [dim.code]: val };
|
let match = product.variants.find((v: any) => {
|
||||||
setSelections(next);
|
|
||||||
const match = product.variants.find((v: any) => {
|
|
||||||
const attrs = (v.attributes || []).reduce((acc: any, a: any) => {
|
const attrs = (v.attributes || []).reduce((acc: any, a: any) => {
|
||||||
acc[a.attribute_code] = a.attribute_value;
|
acc[a.attribute_code] = a.attribute_value;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
return Object.entries(next).every(([k, vVal]) => attrs[k] === vVal);
|
const candidate = { ...selections, [dim.code]: val };
|
||||||
|
return Object.entries(candidate).every(([k, vVal]) => !attrs[k] || attrs[k] === vVal);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
match = product.variants.find((v: any) =>
|
||||||
|
(v.attributes || []).some(
|
||||||
|
(a: any) => (a.attribute_code === dim.code || a.attribute_id === dim.code) && a.attribute_value === val
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const idx = product.variants.findIndex((v: any) => v.variant_id === match.variant_id);
|
const idx = product.variants.findIndex((v: any) => v.variant_id === match.variant_id);
|
||||||
if (idx !== -1) setSelectedVariantIndex(idx);
|
if (idx !== -1) {
|
||||||
|
setSelectedVariantIndex(idx);
|
||||||
|
}
|
||||||
|
const updatedSelections: Record<string, string> = {};
|
||||||
|
(match.attributes || []).forEach((a: any) => {
|
||||||
|
if (a.attribute_code) updatedSelections[a.attribute_code] = a.attribute_value;
|
||||||
|
});
|
||||||
|
setSelections(updatedSelections);
|
||||||
|
|
||||||
const varImg = getPrimaryImageUrl(match.images);
|
const varImg = getPrimaryImageUrl(match.images);
|
||||||
if (varImg) {
|
if (varImg) {
|
||||||
setSelectedImage(getImageUrl(varImg));
|
setSelectedImage(getImageUrl(varImg));
|
||||||
|
|
@ -565,11 +662,10 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
setSelectedImage(getImageUrl(varImg));
|
setSelectedImage(getImageUrl(varImg));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className={`px-3 py-1.5 rounded text-[12px] font-semibold transition border cursor-pointer ${
|
className={`px-3 py-1.5 rounded text-[12px] font-semibold transition border cursor-pointer ${isSelected
|
||||||
isSelected
|
|
||||||
? 'border-primary bg-primary/10 text-primary font-bold shadow-xs'
|
? 'border-primary bg-primary/10 text-primary font-bold shadow-xs'
|
||||||
: 'border-gray-200 bg-white text-gray-700 hover:border-gray-300'
|
: 'border-gray-200 bg-white text-gray-700 hover:border-gray-300'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{v.label || v.sku || `Variant ${idx + 1}`}
|
{v.label || v.sku || `Variant ${idx + 1}`}
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -585,20 +681,34 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<button
|
<div className="flex flex-col sm:flex-row gap-3">
|
||||||
disabled={!selectedVariant || outOfStock}
|
<button
|
||||||
onClick={handleAddToCart}
|
disabled={!selectedVariant || outOfStock}
|
||||||
className={`w-full font-semibold text-sm py-3 px-6 rounded-md transition-colors flex items-center justify-center gap-2 cursor-pointer ${
|
onClick={handleAddToCart}
|
||||||
selectedVariant && !outOfStock
|
className={`flex-1 font-semibold text-sm py-3 px-6 rounded-md transition-colors flex items-center justify-center gap-2 cursor-pointer ${selectedVariant && !outOfStock
|
||||||
? 'bg-primary hover:bg-primary-hover text-white'
|
? 'bg-primary hover:bg-primary-hover text-white'
|
||||||
: 'bg-gray-100 text-gray-400 border border-gray-200 cursor-not-allowed'
|
: 'bg-gray-100 text-gray-400 border border-gray-200 cursor-not-allowed'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{added ? <Check className="w-4 h-4" /> : <ShoppingCart size={16} />}
|
{added ? <Check className="w-4 h-4" /> : <ShoppingCart size={16} />}
|
||||||
<span>
|
<span>
|
||||||
{!selectedVariant ? 'Unavailable' : outOfStock ? 'Out of Stock' : added ? 'Added to Cart!' : 'Add To Cart'}
|
{!selectedVariant ? 'Unavailable' : outOfStock ? 'Out of Stock' : added ? 'Added to Cart!' : 'Add To Cart'}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
disabled={!selectedVariant || outOfStock}
|
||||||
|
onClick={handleBuyNow}
|
||||||
|
className={`flex-1 font-semibold text-sm py-3 px-6 rounded-md transition-colors flex items-center justify-center gap-2 cursor-pointer shadow-sm ${
|
||||||
|
selectedVariant && !outOfStock
|
||||||
|
? 'bg-emerald-600 hover:bg-emerald-700 text-white'
|
||||||
|
: 'bg-gray-100 text-gray-400 border border-gray-200 cursor-not-allowed'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Zap size={16} />
|
||||||
|
<span>Buy Now</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-wrap items-center gap-x-5 gap-y-2 text-[12px] font-medium text-gray-600">
|
<div className="flex flex-wrap items-center gap-x-5 gap-y-2 text-[12px] font-medium text-gray-600">
|
||||||
<button
|
<button
|
||||||
|
|
@ -632,6 +742,60 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Pincode Delivery SLA & Courier Verification Widget */}
|
||||||
|
<div className="mt-5 p-4 rounded-xl border border-gray-200/90 bg-gray-50/70 space-y-3">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="text-[12px] font-bold uppercase tracking-wider text-gray-700 flex items-center gap-1.5">
|
||||||
|
<Truck size={15} className="text-primary" />
|
||||||
|
<span>Delivery & Courier Availability</span>
|
||||||
|
</span>
|
||||||
|
<span className="text-[11px] font-semibold text-emerald-600 bg-emerald-50 px-2 py-0.5 rounded-full border border-emerald-200/60">
|
||||||
|
Pan-India Express
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="relative flex-1">
|
||||||
|
<MapPin size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
maxLength={6}
|
||||||
|
value={deliveryPincode}
|
||||||
|
onChange={(e) => {
|
||||||
|
setDeliveryPincode(e.target.value.replace(/\D/g, ''));
|
||||||
|
setPincodeChecked(false);
|
||||||
|
}}
|
||||||
|
placeholder="Enter 6-digit delivery pincode"
|
||||||
|
className="w-full pl-8 pr-3 py-1.5 text-xs rounded-lg border border-gray-300 bg-white focus:outline-none focus:ring-1 focus:ring-primary font-mono text-gray-900"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setPincodeChecked(true)}
|
||||||
|
className="px-3.5 py-1.5 text-xs font-semibold rounded-lg bg-gray-900 text-white hover:bg-gray-800 transition cursor-pointer"
|
||||||
|
>
|
||||||
|
Check
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{pincodeChecked && (
|
||||||
|
<div className="space-y-1.5 pt-1 text-xs text-gray-600 animate-in fade-in duration-200">
|
||||||
|
<div className="flex items-center gap-2 text-emerald-700 font-semibold">
|
||||||
|
<Check size={14} className="text-emerald-600" />
|
||||||
|
<span>Express Delivery Available to {deliveryPincode}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 text-gray-500 text-[11px]">
|
||||||
|
<Clock size={13} className="text-primary" />
|
||||||
|
<span>Estimated delivery within 2-3 business days via Express Air Courier</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 text-gray-500 text-[11px]">
|
||||||
|
<ShieldCheck size={13} className="text-emerald-600" />
|
||||||
|
<span>Prepaid Order Protection (Instant Online Verification & Fast Dispatch)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{product.is_service_booking && (
|
{product.is_service_booking && (
|
||||||
<div className="mt-4 p-4 border border-emerald-200 bg-emerald-50 rounded-xl flex flex-col gap-3">
|
<div className="mt-4 p-4 border border-emerald-200 bg-emerald-50 rounded-xl flex flex-col gap-3">
|
||||||
<div className="flex items-start gap-3">
|
<div className="flex items-start gap-3">
|
||||||
|
|
@ -639,18 +803,17 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
<div>
|
<div>
|
||||||
<h4 className="font-semibold text-emerald-900 text-sm">Need Professional Installation?</h4>
|
<h4 className="font-semibold text-emerald-900 text-sm">Need Professional Installation?</h4>
|
||||||
<p className="text-xs text-emerald-700 mt-1">
|
<p className="text-xs text-emerald-700 mt-1">
|
||||||
Book a doorstep or store service for this part. We will assign an expert engineer to install it for you.
|
Book a service for your device.An expert engineer will install it for you.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
disabled={!selectedVariant}
|
disabled={!selectedVariant}
|
||||||
onClick={handleBookService}
|
onClick={handleBookService}
|
||||||
className={`w-full font-semibold text-sm py-2.5 px-6 rounded-md transition-colors flex items-center justify-center gap-2 cursor-pointer ${
|
className={`w-full font-semibold text-sm py-2.5 px-6 rounded-md transition-colors flex items-center justify-center gap-2 cursor-pointer ${selectedVariant
|
||||||
selectedVariant
|
|
||||||
? 'bg-emerald-600 hover:bg-emerald-700 text-white shadow-sm'
|
? 'bg-emerald-600 hover:bg-emerald-700 text-white shadow-sm'
|
||||||
: 'bg-emerald-200 text-emerald-500 cursor-not-allowed'
|
: 'bg-emerald-200 text-emerald-500 cursor-not-allowed'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
Book Service Now
|
Book Service Now
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -690,15 +853,26 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
{selectedVariant ? formatCurrency(selectedPrice) : 'N/A'}
|
{selectedVariant ? formatCurrency(selectedPrice) : 'N/A'}
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
disabled={!selectedVariant}
|
disabled={!selectedVariant || outOfStock}
|
||||||
onClick={handleAddToCart}
|
onClick={handleAddToCart}
|
||||||
className={`font-extrabold text-xs uppercase tracking-wider py-2.5 px-5 rounded-xl transition-all shadow-sm cursor-pointer whitespace-nowrap ${
|
className={`font-extrabold text-xs uppercase tracking-wider py-2.5 px-5 rounded-xl transition-all shadow-sm cursor-pointer whitespace-nowrap ${
|
||||||
selectedVariant
|
selectedVariant && !outOfStock
|
||||||
? 'bg-[#0073EC] hover:bg-[#1565C0] text-white'
|
? 'bg-[#0073EC] hover:bg-[#1565C0] text-white'
|
||||||
: 'bg-gray-100 text-gray-450 border border-gray-200 cursor-not-allowed'
|
: 'bg-gray-100 text-gray-450 border border-gray-200 cursor-not-allowed'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{!selectedVariant ? 'Unavailable' : 'Add to Cart'}
|
{!selectedVariant ? 'Unavailable' : outOfStock ? 'Out of Stock' : 'Add to Cart'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
disabled={!selectedVariant || outOfStock}
|
||||||
|
onClick={handleBuyNow}
|
||||||
|
className={`font-extrabold text-xs uppercase tracking-wider py-2.5 px-5 rounded-xl transition-all shadow-sm cursor-pointer whitespace-nowrap ${
|
||||||
|
selectedVariant && !outOfStock
|
||||||
|
? 'bg-emerald-600 hover:bg-emerald-700 text-white'
|
||||||
|
: 'bg-gray-100 text-gray-450 border border-gray-200 cursor-not-allowed'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Buy Now
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,13 @@ function SocialIcon({ name }: { name?: string }) {
|
||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (key.includes('whatsapp')) {
|
||||||
|
return (
|
||||||
|
<svg className={`${className} hover:text-[#25D366]`} viewBox="0 0 24 24" aria-hidden>
|
||||||
|
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
if (key.includes('twitter') || key === 'x') {
|
if (key.includes('twitter') || key === 'x') {
|
||||||
return (
|
return (
|
||||||
<svg className="w-4.5 h-4.5 fill-current" viewBox="0 0 24 24" aria-hidden>
|
<svg className="w-4.5 h-4.5 fill-current" viewBox="0 0 24 24" aria-hidden>
|
||||||
|
|
@ -193,7 +200,13 @@ export const Footer: React.FC = () => {
|
||||||
].filter((c) => c.links.length > 0)
|
].filter((c) => c.links.length > 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
const socials = (info.social_links || []).filter((s) => s?.url);
|
const defaultSocials = [
|
||||||
|
{ platform: 'Instagram', url: 'https://instagram.com', icon: 'instagram' },
|
||||||
|
{ platform: 'Facebook', url: 'https://facebook.com', icon: 'facebook' },
|
||||||
|
{ platform: 'WhatsApp', url: 'https://wa.me/919080323589', icon: 'whatsapp' },
|
||||||
|
];
|
||||||
|
const rawSocials = (info.social_links || []).filter((s) => s?.url);
|
||||||
|
const socials = rawSocials.length > 0 ? rawSocials : defaultSocials;
|
||||||
const payments = (info.payment_methods || []).filter((p) => p?.name || p?.icon_url);
|
const payments = (info.payment_methods || []).filter((p) => p?.name || p?.icon_url);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
109
lib/analytics.ts
Normal file
109
lib/analytics.ts
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
/**
|
||||||
|
* Google Analytics 4 (GA4) E-Commerce & Telemetry Tracker
|
||||||
|
* Property ID: 521198579 / iFixKart Storefront
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
dataLayer: any[];
|
||||||
|
gtag: (...args: any[]) => void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GA_MEASUREMENT_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID || 'G-IFIXKART2026';
|
||||||
|
|
||||||
|
export function trackPageView(url: string) {
|
||||||
|
if (typeof window === 'undefined' || typeof window.gtag !== 'function') return;
|
||||||
|
try {
|
||||||
|
window.gtag('config', GA_MEASUREMENT_ID, {
|
||||||
|
page_path: url,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.debug('[GA4] Pageview tracking suppressed', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackEvent(action: string, params: Record<string, any> = {}) {
|
||||||
|
if (typeof window === 'undefined' || typeof window.gtag !== 'function') return;
|
||||||
|
try {
|
||||||
|
window.gtag('event', action, params);
|
||||||
|
} catch (err) {
|
||||||
|
console.debug('[GA4] Event tracking suppressed', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackViewItem(product: {
|
||||||
|
id: string | number;
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
category?: string;
|
||||||
|
brand?: string;
|
||||||
|
sku?: string;
|
||||||
|
}) {
|
||||||
|
trackEvent('view_item', {
|
||||||
|
currency: 'INR',
|
||||||
|
value: product.price,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
item_id: String(product.sku || product.id),
|
||||||
|
item_name: product.name,
|
||||||
|
price: product.price,
|
||||||
|
item_category: product.category || 'Spare Parts',
|
||||||
|
item_brand: product.brand || 'iFixKart',
|
||||||
|
quantity: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackAddToCart(product: {
|
||||||
|
id: string | number;
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
category?: string;
|
||||||
|
brand?: string;
|
||||||
|
sku?: string;
|
||||||
|
quantity?: number;
|
||||||
|
}) {
|
||||||
|
trackEvent('add_to_cart', {
|
||||||
|
currency: 'INR',
|
||||||
|
value: product.price * (product.quantity || 1),
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
item_id: String(product.sku || product.id),
|
||||||
|
item_name: product.name,
|
||||||
|
price: product.price,
|
||||||
|
item_category: product.category || 'Spare Parts',
|
||||||
|
item_brand: product.brand || 'iFixKart',
|
||||||
|
quantity: product.quantity || 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackBeginCheckout(items: any[], totalValue: number) {
|
||||||
|
trackEvent('begin_checkout', {
|
||||||
|
currency: 'INR',
|
||||||
|
value: totalValue,
|
||||||
|
items: items.map((item) => ({
|
||||||
|
item_id: String(item.variant_id || item.product_id || item.id),
|
||||||
|
item_name: item.name || item.title,
|
||||||
|
price: item.price,
|
||||||
|
quantity: item.quantity || 1,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackPurchase(orderId: string, totalValue: number, items: any[]) {
|
||||||
|
trackEvent('purchase', {
|
||||||
|
transaction_id: orderId,
|
||||||
|
currency: 'INR',
|
||||||
|
value: totalValue,
|
||||||
|
items: items.map((item) => ({
|
||||||
|
item_id: String(item.variant_id || item.product_id || item.id),
|
||||||
|
item_name: item.name || item.title,
|
||||||
|
price: item.price,
|
||||||
|
quantity: item.quantity || 1,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ export const catalogServerService = {
|
||||||
compatible_devices: any[];
|
compatible_devices: any[];
|
||||||
specifications: any[];
|
specifications: any[];
|
||||||
}>(`/api/v1/catalog/products/detail/${slug}`, {
|
}>(`/api/v1/catalog/products/detail/${slug}`, {
|
||||||
next: { revalidate: 60, tags: [`product-${slug}`] }
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,29 @@ export const storefrontService = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getPageLayout(page: string): Promise<any[]> {
|
||||||
|
try {
|
||||||
|
const data = await apiFetch<any[]>(`/api/v1/storefront/layout/${page}`);
|
||||||
|
return Array.isArray(data) ? data : [];
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async submitFeedback(payload: {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
topic: string;
|
||||||
|
order_no?: string;
|
||||||
|
rating: number;
|
||||||
|
message: string;
|
||||||
|
}): Promise<{ message: string; feedback_id?: string }> {
|
||||||
|
return await apiFetch<{ message: string; feedback_id?: string }>('/api/v1/storefront/feedback', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
async getCatalogFilters(): Promise<CatalogFiltersData> {
|
async getCatalogFilters(): Promise<CatalogFiltersData> {
|
||||||
try {
|
try {
|
||||||
return await apiFetch<CatalogFiltersData>('/api/v1/storefront/catalog-filters');
|
return await apiFetch<CatalogFiltersData>('/api/v1/storefront/catalog-filters');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue