291 lines
14 KiB
TypeScript
291 lines
14 KiB
TypeScript
'use client';
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
import {
|
|
ShoppingBag,
|
|
CheckCircle2,
|
|
ExternalLink,
|
|
Copy,
|
|
RefreshCw,
|
|
AlertCircle,
|
|
FileCode,
|
|
Layers,
|
|
Image as ImageIcon,
|
|
Tag,
|
|
ArrowUpRight,
|
|
ShieldCheck
|
|
} from 'lucide-react';
|
|
import { apiFetch } from '@/services/api/client';
|
|
import { API_ENDPOINTS } from '@/services/api/config';
|
|
import { toast } from 'sonner';
|
|
|
|
interface MerchantFeedStats {
|
|
total_products: number;
|
|
eligible_products: number;
|
|
missing_images: number;
|
|
missing_prices: number;
|
|
generated_at: string;
|
|
store_name: string;
|
|
store_url: string;
|
|
feed_url: string;
|
|
}
|
|
|
|
export default function GoogleMerchantCenterPage() {
|
|
const [stats, setStats] = useState<MerchantFeedStats | null>(null);
|
|
const [loading, setLoading] = useState<boolean>(true);
|
|
const [regenerating, setRegenerating] = useState<boolean>(false);
|
|
const [copied, setCopied] = useState<boolean>(false);
|
|
|
|
const fetchStatus = async (forceRefresh: boolean = false) => {
|
|
try {
|
|
if (forceRefresh) setRegenerating(true);
|
|
else setLoading(true);
|
|
|
|
const endpoint = forceRefresh
|
|
? `${API_ENDPOINTS.GOOGLE_MERCHANT_STATUS}?force_refresh=true`
|
|
: API_ENDPOINTS.GOOGLE_MERCHANT_STATUS;
|
|
|
|
const res = await apiFetch<{ status: string; data: MerchantFeedStats }>(endpoint);
|
|
if (res && res.data) {
|
|
setStats(res.data);
|
|
if (forceRefresh) {
|
|
toast.success('Google Merchant RSS Feed regenerated successfully!');
|
|
}
|
|
}
|
|
} catch (err: unknown) {
|
|
console.error('Failed to load merchant status:', err);
|
|
toast.error('Failed to load Google Merchant Center status');
|
|
} finally {
|
|
setLoading(false);
|
|
setRegenerating(false);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
fetchStatus(false);
|
|
}, []);
|
|
|
|
const copyFeedUrl = () => {
|
|
if (!stats?.feed_url) return;
|
|
navigator.clipboard.writeText(stats.feed_url);
|
|
setCopied(true);
|
|
toast.success('Feed URL copied to clipboard!');
|
|
setTimeout(() => setCopied(false), 2500);
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-6 pb-12">
|
|
{/* Top Header */}
|
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-border/60 pb-5">
|
|
<div>
|
|
<div className="flex items-center gap-2 text-xs font-semibold uppercase tracking-wider text-primary mb-1">
|
|
<ShoppingBag className="w-4 h-4 text-primary" />
|
|
<span>Google Shopping Integration</span>
|
|
</div>
|
|
<h1 className="text-2xl sm:text-3xl font-extrabold tracking-tight text-foreground">
|
|
Google Merchant Center
|
|
</h1>
|
|
<p className="text-sm text-muted-foreground mt-1">
|
|
Automated RSS 2.0 XML product feed for Google Shopping Ads, Free Listings, and Merchant Center sync.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-3">
|
|
<button
|
|
onClick={() => fetchStatus(true)}
|
|
disabled={regenerating}
|
|
className="inline-flex items-center gap-2 px-4 py-2 text-sm font-semibold rounded-xl bg-card border border-border shadow-xs hover:bg-muted/60 transition disabled:opacity-50"
|
|
>
|
|
<RefreshCw className={`w-4 h-4 ${regenerating ? 'animate-spin text-primary' : 'text-muted-foreground'}`} />
|
|
<span>{regenerating ? 'Regenerating Feed...' : 'Sync & Regenerate'}</span>
|
|
</button>
|
|
|
|
<a
|
|
href={stats?.feed_url || '/api/v1/storefront/feed/google-merchant.xml'}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="inline-flex items-center gap-2 px-4 py-2 text-sm font-semibold rounded-xl bg-primary text-primary-foreground shadow hover:opacity-95 transition"
|
|
>
|
|
<span>Inspect XML Feed</span>
|
|
<ExternalLink className="w-4 h-4" />
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Metric Cards Grid */}
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
|
<div className="rounded-2xl border border-border/80 bg-card p-5 shadow-xs transition hover:shadow-md">
|
|
<div className="flex items-center justify-between text-muted-foreground mb-3">
|
|
<span className="text-xs font-medium uppercase tracking-wider">Eligible Products</span>
|
|
<div className="p-2 rounded-xl bg-emerald-500/10 text-emerald-500">
|
|
<CheckCircle2 className="w-5 h-5" />
|
|
</div>
|
|
</div>
|
|
<div className="text-3xl font-black text-foreground">
|
|
{loading ? '...' : (stats?.eligible_products ?? 0).toLocaleString()}
|
|
</div>
|
|
<p className="text-xs text-muted-foreground mt-2 flex items-center gap-1">
|
|
<span className="text-emerald-500 font-semibold">100% catalog compliance</span>
|
|
</p>
|
|
</div>
|
|
|
|
<div className="rounded-2xl border border-border/80 bg-card p-5 shadow-xs transition hover:shadow-md">
|
|
<div className="flex items-center justify-between text-muted-foreground mb-3">
|
|
<span className="text-xs font-medium uppercase tracking-wider">Feed Standards</span>
|
|
<div className="p-2 rounded-xl bg-blue-500/10 text-blue-500">
|
|
<FileCode className="w-5 h-5" />
|
|
</div>
|
|
</div>
|
|
<div className="text-3xl font-black text-foreground">
|
|
RSS 2.0
|
|
</div>
|
|
<p className="text-xs text-muted-foreground mt-2">
|
|
Google Base Namespace <span className="font-mono text-primary">(xmlns:g)</span>
|
|
</p>
|
|
</div>
|
|
|
|
<div className="rounded-2xl border border-border/80 bg-card p-5 shadow-xs transition hover:shadow-md">
|
|
<div className="flex items-center justify-between text-muted-foreground mb-3">
|
|
<span className="text-xs font-medium uppercase tracking-wider">Store Domain</span>
|
|
<div className="p-2 rounded-xl bg-amber-500/10 text-amber-500">
|
|
<Layers className="w-5 h-5" />
|
|
</div>
|
|
</div>
|
|
<div className="text-xl font-bold truncate text-foreground">
|
|
{stats?.store_name || 'iFixKart'}
|
|
</div>
|
|
<p className="text-xs text-muted-foreground mt-2 truncate">
|
|
{stats?.store_url || 'https://ifixkart.trionixsolution.com'}
|
|
</p>
|
|
</div>
|
|
|
|
<div className="rounded-2xl border border-border/80 bg-card p-5 shadow-xs transition hover:shadow-md">
|
|
<div className="flex items-center justify-between text-muted-foreground mb-3">
|
|
<span className="text-xs font-medium uppercase tracking-wider">Last Generated</span>
|
|
<div className="p-2 rounded-xl bg-purple-500/10 text-purple-500">
|
|
<ShieldCheck className="w-5 h-5" />
|
|
</div>
|
|
</div>
|
|
<div className="text-sm font-bold text-foreground truncate">
|
|
{stats?.generated_at ? new Date(stats.generated_at).toLocaleTimeString() : 'Real-time Cached'}
|
|
</div>
|
|
<p className="text-xs text-muted-foreground mt-2">
|
|
{stats?.generated_at ? new Date(stats.generated_at).toLocaleDateString() : 'Auto-refreshed'}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Feed URL Copy Card */}
|
|
<div className="rounded-2xl border border-primary/20 bg-gradient-to-br from-card to-primary/5 p-6 shadow-sm">
|
|
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
<div className="space-y-1">
|
|
<h3 className="text-lg font-bold text-foreground flex items-center gap-2">
|
|
<span>Merchant Center Feed URL</span>
|
|
<span className="px-2 py-0.5 text-[10px] font-bold uppercase rounded-full bg-emerald-500/15 text-emerald-600 dark:text-emerald-400">
|
|
Live Active
|
|
</span>
|
|
</h3>
|
|
<p className="text-xs text-muted-foreground">
|
|
Paste this URL into your Google Merchant Center account under <span className="font-semibold text-foreground">Products > Feeds > Scheduled Fetch</span>.
|
|
</p>
|
|
</div>
|
|
|
|
<button
|
|
onClick={copyFeedUrl}
|
|
className="inline-flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl bg-primary text-primary-foreground font-semibold text-sm shadow hover:opacity-95 transition"
|
|
>
|
|
{copied ? <CheckCircle2 className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
|
|
<span>{copied ? 'Copied Link!' : 'Copy Feed Link'}</span>
|
|
</button>
|
|
</div>
|
|
|
|
<div className="mt-4 p-3.5 rounded-xl bg-muted/60 border border-border/80 font-mono text-xs text-foreground flex items-center justify-between break-all">
|
|
<span>{stats?.feed_url || 'https://ifixkart.trionixsolution.com/api/v1/storefront/feed/google-merchant.xml'}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Feed Compliance Checklist & Schema Information */}
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
<div className="rounded-2xl border border-border/80 bg-card p-6 shadow-xs">
|
|
<h3 className="text-base font-bold text-foreground mb-4 flex items-center gap-2">
|
|
<ShieldCheck className="w-5 h-5 text-emerald-500" />
|
|
<span>Google Shopping Quality Assurance</span>
|
|
</h3>
|
|
<div className="space-y-3.5">
|
|
<div className="flex items-start gap-3 p-3 rounded-xl bg-muted/40 border border-border/60">
|
|
<CheckCircle2 className="w-5 h-5 text-emerald-500 shrink-0 mt-0.5" />
|
|
<div>
|
|
<p className="text-sm font-semibold text-foreground">Mandatory Attributes Standard</p>
|
|
<p className="text-xs text-muted-foreground mt-0.5">
|
|
Includes <code className="text-primary font-mono">g:id</code>, <code className="text-primary font-mono">g:title</code>, <code className="text-primary font-mono">g:description</code>, <code className="text-primary font-mono">g:link</code>, and <code className="text-primary font-mono">g:image_link</code>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-start gap-3 p-3 rounded-xl bg-muted/40 border border-border/60">
|
|
<CheckCircle2 className="w-5 h-5 text-emerald-500 shrink-0 mt-0.5" />
|
|
<div>
|
|
<p className="text-sm font-semibold text-foreground">Pricing & Currency (INR)</p>
|
|
<p className="text-xs text-muted-foreground mt-0.5">
|
|
All active items are formatted with ISO-4217 compliant <code className="text-primary font-mono">1299.00 INR</code> price specifications.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-start gap-3 p-3 rounded-xl bg-muted/40 border border-border/60">
|
|
<CheckCircle2 className="w-5 h-5 text-emerald-500 shrink-0 mt-0.5" />
|
|
<div>
|
|
<p className="text-sm font-semibold text-foreground">Stock Availability Sync</p>
|
|
<p className="text-xs text-muted-foreground mt-0.5">
|
|
Maps real-time warehouse inventory to Google tags: <code className="text-primary font-mono">in_stock</code> or <code className="text-primary font-mono">out_of_stock</code>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-start gap-3 p-3 rounded-xl bg-muted/40 border border-border/60">
|
|
<CheckCircle2 className="w-5 h-5 text-emerald-500 shrink-0 mt-0.5" />
|
|
<div>
|
|
<p className="text-sm font-semibold text-foreground">Brand & Identifier Match</p>
|
|
<p className="text-xs text-muted-foreground mt-0.5">
|
|
Transmits brand metadata (<code className="text-primary font-mono">iFixKart</code>, Apple, Samsung, OnePlus, etc.) and SKU identifiers.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Integration Instructions */}
|
|
<div className="rounded-2xl border border-border/80 bg-card p-6 shadow-xs flex flex-col justify-between">
|
|
<div>
|
|
<h3 className="text-base font-bold text-foreground mb-4 flex items-center gap-2">
|
|
<ArrowUpRight className="w-5 h-5 text-primary" />
|
|
<span>How to Setup in Google Merchant Center</span>
|
|
</h3>
|
|
<ol className="space-y-3.5 text-xs text-muted-foreground list-decimal list-inside leading-relaxed">
|
|
<li className="p-2.5 rounded-lg bg-muted/30">
|
|
Log into your account at <a href="https://merchants.google.com" target="_blank" rel="noreferrer" className="text-primary font-medium underline inline-flex items-center gap-1">merchants.google.com <ExternalLink className="w-3 h-3 inline" /></a>.
|
|
</li>
|
|
<li className="p-2.5 rounded-lg bg-muted/30">
|
|
Navigate to <span className="font-semibold text-foreground">Products</span> → <span className="font-semibold text-foreground">Feeds</span> → Click <span className="font-semibold text-foreground">Add primary feed (+)</span>.
|
|
</li>
|
|
<li className="p-2.5 rounded-lg bg-muted/30">
|
|
Select your target country (<span className="font-semibold text-foreground">India</span>) and language (<span className="font-semibold text-foreground">English</span>).
|
|
</li>
|
|
<li className="p-2.5 rounded-lg bg-muted/30">
|
|
Select <span className="font-semibold text-foreground">Scheduled fetch</span> and paste the feed URL copied above.
|
|
</li>
|
|
<li className="p-2.5 rounded-lg bg-muted/30">
|
|
Set fetch frequency to <span className="font-semibold text-foreground">Daily</span> at 04:00 AM IST for automatic product updates.
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div className="mt-5 p-3 rounded-xl bg-blue-500/10 border border-blue-500/20 text-xs text-blue-600 dark:text-blue-400 flex items-center gap-2">
|
|
<CheckCircle2 className="w-4 h-4 shrink-0" />
|
|
<span>Google Shopping Free Listings and Performance Max Ads are fully supported.</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|