fix(frontend): remove static fallback data and mock fallbacks across storefront
This commit is contained in:
1 parent
6b4a746f72
commit
5e0541c739
11 files changed
+28
-68
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { productService } from '../../../../lib/services/productService';
|
||||
import { PRODUCTS } from '../../../../lib/data/products';
|
||||
import { getMediaUrl } from '../../../../lib/media';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -112,9 +111,10 @@ export async function GET(request: NextRequest) {
|
||||
let allProducts: any[] = [];
|
||||
try {
|
||||
const res = await productService.getProducts({ limit: 999 });
|
||||
allProducts = res.data && res.data.length > 0 ? res.data : PRODUCTS;
|
||||
} catch {
|
||||
allProducts = PRODUCTS;
|
||||
allProducts = res.data || [];
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch products for Torob:", err);
|
||||
allProducts = [];
|
||||
}
|
||||
|
||||
// Filter indexable active products
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { productService } from '../../../lib/services/productService';
|
||||
import { PRODUCTS } from '../../../lib/data/products';
|
||||
import { getMediaUrl } from '../../../lib/media';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -12,9 +11,10 @@ export async function GET() {
|
||||
let productsList: any[] = [];
|
||||
try {
|
||||
const res = await productService.getProducts({ limit: 999 });
|
||||
productsList = res.data && res.data.length > 0 ? res.data : PRODUCTS;
|
||||
} catch {
|
||||
productsList = PRODUCTS;
|
||||
productsList = res.data || [];
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch products for feed.xml:", err);
|
||||
productsList = [];
|
||||
}
|
||||
|
||||
// Only active, indexable products
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { productService } from '../../lib/services/productService';
|
||||
import { PRODUCTS } from '../../lib/data/products';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const revalidate = 3600; // Revalidate every hour
|
||||
@@ -11,9 +10,10 @@ export async function GET() {
|
||||
let productsList: any[] = [];
|
||||
try {
|
||||
const res = await productService.getProducts({ limit: 999 });
|
||||
productsList = res.data && res.data.length > 0 ? res.data : PRODUCTS;
|
||||
} catch {
|
||||
productsList = PRODUCTS;
|
||||
productsList = res.data || [];
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch products for sitemap-products.xml:", err);
|
||||
productsList = [];
|
||||
}
|
||||
|
||||
// Filter out noIndex products
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MetadataRoute } from 'next';
|
||||
import { productService } from '../lib/services/productService';
|
||||
import { PRODUCTS } from '../lib/data/products';
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://canina.ir';
|
||||
@@ -55,7 +54,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
let productRoutes: MetadataRoute.Sitemap = [];
|
||||
try {
|
||||
const res = await productService.getProducts({ limit: 999 });
|
||||
const products = res.data && res.data.length > 0 ? res.data : PRODUCTS;
|
||||
const products = res.data || [];
|
||||
|
||||
productRoutes = products
|
||||
.filter((product) => !product.noIndex)
|
||||
@@ -65,13 +64,9 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.9,
|
||||
}));
|
||||
} catch {
|
||||
productRoutes = PRODUCTS.map((product) => ({
|
||||
url: `${baseUrl}/shop/${product.slug || product.artNo || product.id}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.9,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch products for sitemap:", error);
|
||||
productRoutes = [];
|
||||
}
|
||||
|
||||
// Dynamic shop categories
|
||||
|
||||
@@ -76,7 +76,7 @@ const CATEGORY_MAP: Record<string, { category?: string; query?: string; symptoms
|
||||
"شستشوی چشم": { category: "special-care", query: "چشم" },
|
||||
};
|
||||
|
||||
const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
export const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
const { addItem } = useCartStore();
|
||||
const cartItem = useCartStore((s) => s.items.find(i => i.product.id === product.id));
|
||||
const [isAdding, setIsAdding] = useState(false);
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
Edit2
|
||||
} from "lucide-react";
|
||||
import { toPersian, cn } from "../lib/utils";
|
||||
import { PRODUCTS } from "../lib/data/products";
|
||||
import { useCartStore } from "../lib/store/cartStore";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
|
||||
@@ -16,7 +16,7 @@ import { toast } from "sonner";
|
||||
import { useCatalogMode } from "../lib/useCatalogMode";
|
||||
import { isSuitableForDog, isSuitableForCat, isSuitableForBoth, isSpeciesCompatible, matchesMedicalSymptom } from "../lib/petCompatibility";
|
||||
|
||||
function ProductCard({ product, priority = false }: { product: Product; priority?: boolean }) {
|
||||
export function ProductCard({ product, priority = false }: { product: Product; priority?: boolean }) {
|
||||
const router = useRouter();
|
||||
const { getText } = useSettingsStore();
|
||||
const { getActivePet } = usePetStore();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Product, IngredientInfo, PRODUCTS, INGREDIENTS_WIKI } from "../lib/data/products";
|
||||
import { Product, IngredientInfo } from "../lib/data/products";
|
||||
import { motion } from "motion/react";
|
||||
import { FlaskConical, CheckCircle2, ChevronRight, ChevronLeft, Beaker, Search } from "lucide-react";
|
||||
import { productService } from "../lib/services/productService";
|
||||
@@ -64,8 +64,8 @@ export default function IngredientWiki() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const termParam = searchParams.get('term');
|
||||
const [ingredientsWiki, setIngredientsWiki] = useState<IngredientInfo[]>(INGREDIENTS_WIKI);
|
||||
const [products, setProducts] = useState<Product[]>(PRODUCTS);
|
||||
const [ingredientsWiki, setIngredientsWiki] = useState<IngredientInfo[]>([]);
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -76,7 +76,7 @@ export default function IngredientWiki() {
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.warn('[IngredientWiki] Using static fallback products:', err);
|
||||
console.warn('[IngredientWiki] Products fetch failed:', err); setProducts([]);
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -95,7 +95,7 @@ export default function IngredientWiki() {
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('[IngredientWiki] Using static INGREDIENTS_WIKI fallback:', err);
|
||||
console.warn('[IngredientWiki] Ingredients fetch failed:', err); setIngredientsWiki([]);
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
Download
|
||||
} from "lucide-react";
|
||||
import { cn } from "../lib/utils";
|
||||
import { PRODUCTS } from "../lib/data/products";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -177,14 +176,11 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
matchedProd = (found || liveRes.data[0]) as unknown as Record<string, unknown>;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[SmartAdvisor] Dynamic product fetch failed, using fallback", e);
|
||||
console.error("[SmartAdvisor] Dynamic product fetch failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchedProd) {
|
||||
const fallback = PRODUCTS.find(p => p.suitableFor === "هر دو" || p.suitableFor === type) || PRODUCTS[0];
|
||||
matchedProd = fallback as unknown as Record<string, unknown>;
|
||||
}
|
||||
// No fallback to static PRODUCTS: matchedProd remains null if not found
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
|
||||
@@ -25,36 +25,6 @@ export interface TestimonialItem {
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
const FALLBACK_VIDEOS = [
|
||||
{
|
||||
id: "v1",
|
||||
title: "نحوه آمادهسازی کانیهیدروکس GAG",
|
||||
doctor: "دکتر کلاوس هنینگ",
|
||||
duration: "۰۱:۴۵",
|
||||
thumbnail: "https://images.unsplash.com/photo-1576091160550-217359f42f8c?auto=format&fit=crop&q=80&w=400",
|
||||
videoUrl: "https://www.w3schools.com/html/mov_bbb.mp4",
|
||||
description: "آموزش گام به گام آمادهسازی پودر Canhydrox GAG برای جذب حداکثری در دستگاه گوارش."
|
||||
},
|
||||
{
|
||||
id: "v2",
|
||||
title: "اهمیت صدف لبسبز",
|
||||
doctor: "دکتر النا اشمیت",
|
||||
duration: "۰۲:۲۰",
|
||||
thumbnail: "https://images.unsplash.com/photo-1599443015574-be5fe8a05783?auto=format&fit=crop&q=80&w=400",
|
||||
videoUrl: "https://www.w3schools.com/html/movie.mp4",
|
||||
description: "چرا صدف لبسبز نیوزیلندی نایابترین و موثرترین ماده برای بازسازی مفصل است؟"
|
||||
},
|
||||
{
|
||||
id: "v3",
|
||||
title: "تغذیه هوشمند تولهسگها",
|
||||
doctor: "دکتر هلگا فیشر",
|
||||
duration: "۰۳:۱۰",
|
||||
thumbnail: "/assets/images/regenerated_image_1779109861747.png",
|
||||
videoUrl: "https://www.w3schools.com/html/mov_bbb.mp4",
|
||||
description: "دوز مصرفی مکملهای کلسیم در نژادهای بزرگ برای جلوگیری از بدشکلیهای استخوانی."
|
||||
}
|
||||
];
|
||||
|
||||
interface DisplayVideoItem {
|
||||
id: string;
|
||||
title?: string;
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('IngredientWiki Component', () => {
|
||||
mockSearchParamsGet.mockReturnValue(null);
|
||||
});
|
||||
|
||||
it('renders default static wiki content when api call fails or returns empty', async () => {
|
||||
it('renders empty state without static fallback when api call fails or returns empty', async () => {
|
||||
(productService.getProducts as any).mockRejectedValueOnce(new Error('fail'));
|
||||
(api.get as any).mockRejectedValueOnce(new Error('fail'));
|
||||
|
||||
@@ -71,9 +71,9 @@ describe('IngredientWiki Component', () => {
|
||||
expect(screen.getByText(/۱۰۰٪ فاقد قند افزوده/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/مطابق استانداردهای دارویی و بالینی آلمان/)).toBeInTheDocument();
|
||||
|
||||
// Default static wiki ingredient should be rendered (e.g. green-mussel / صدف لبسبز)
|
||||
// Verify empty state is rendered (no static fallback data shown)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/صدف لبسبز/)).toBeInTheDocument();
|
||||
expect(screen.getByText('مادهای یافت نشد')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user