feat(application): implement Phase 3 strict DTOs, eradicate any types, and add Suspense boundaries
Deploy Canina / deploy (push) Failing after 29s
Deploy Canina / deploy (push) Failing after 29s
This commit is contained in:
1 parent
57596f5aaf
commit
74fcaa6a4e
8 files changed
+82
-24
No files matched your search
@@ -16,6 +16,7 @@ import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import { useUIStore } from "../lib/store/uiStore";
|
||||
|
||||
import MaintenancePage from "../components/MaintenancePage";
|
||||
import { NavigationTarget } from "../lib/types";
|
||||
|
||||
export default function ClientLayout({ children }: { children: React.ReactNode }) {
|
||||
const isCartOpen = useUIStore((state) => state.isCartOpen);
|
||||
@@ -64,12 +65,12 @@ export default function ClientLayout({ children }: { children: React.ReactNode }
|
||||
if (pathname?.includes("/checkout")) currentView = "checkout";
|
||||
if (pathname?.includes("/dashboard")) currentView = "user-dashboard";
|
||||
|
||||
const handleNavigate = (v: any) => {
|
||||
if (typeof v === 'object') {
|
||||
const handleNavigate = (v: NavigationTarget) => {
|
||||
if (typeof v === 'object' && v !== null) {
|
||||
if (v.view === 'profile') router.push('/profile');
|
||||
if (v.view === 'order-tracking') router.push('/order/tracking');
|
||||
if (v.view === 'home') router.push('/');
|
||||
} else {
|
||||
} else if (typeof v === 'string') {
|
||||
if (v === 'home') router.push('/');
|
||||
else if (v === 'user-dashboard') router.push('/dashboard');
|
||||
else router.push(`/${v}`);
|
||||
|
||||
@@ -11,13 +11,15 @@ import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import api from "../lib/services/api";
|
||||
import Image from "next/image";
|
||||
|
||||
import { HomeApiResponse } from "../lib/types";
|
||||
|
||||
interface HomeClientProps {
|
||||
initialData?: any;
|
||||
initialData?: HomeApiResponse | null;
|
||||
}
|
||||
|
||||
export default function HomeClient({ initialData }: HomeClientProps) {
|
||||
const getText = useSettingsStore((state) => state.getText);
|
||||
const [data, setData] = useState<any>(initialData || null);
|
||||
const [data, setData] = useState<HomeApiResponse | null>(initialData || null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!initialData) {
|
||||
|
||||
@@ -31,14 +31,9 @@ export const metadata: Metadata = {
|
||||
}
|
||||
};
|
||||
|
||||
interface HomeData {
|
||||
heroBanners?: any[];
|
||||
vetTestimonials?: any[];
|
||||
smartAdvisorRules?: any[];
|
||||
[key: string]: any;
|
||||
}
|
||||
import { HomeApiResponse } from "../lib/types";
|
||||
|
||||
async function getHomeData(): Promise<HomeData | null> {
|
||||
async function getHomeData(): Promise<HomeApiResponse | null> {
|
||||
try {
|
||||
const apiUrl = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001/api';
|
||||
const res = await fetch(`${apiUrl}/home`, {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import ProductPage from "../../../components/ProductPage";
|
||||
import { productService } from "../../../lib/services/productService";
|
||||
import type { Metadata, ResolvingMetadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params }: { params: Promise<{ slug: string }> },
|
||||
@@ -15,14 +16,12 @@ export async function generateMetadata(
|
||||
};
|
||||
}
|
||||
|
||||
// Get raw data for custom fields if we added them (like metaTitle)
|
||||
// Since we don't have local access to raw DB object without modifying productService,
|
||||
// we can just use the mapped product fields for now.
|
||||
const nameFa = product.nameFa || product.name;
|
||||
const nameEn = product.nameEn || "";
|
||||
const title = nameFa.includes("Canina") ? nameFa : `${nameFa} (${nameEn}) | برند کانینا آلمان`;
|
||||
const description = (product.shortDescription || product.description || '').substring(0, 150).trim();
|
||||
const keywords = (product as any).keywords ? (product as any).keywords.split(',') : product.main_ingredients;
|
||||
const rawKeywords = (product as unknown as Record<string, unknown>).keywords;
|
||||
const keywords = typeof rawKeywords === 'string' ? rawKeywords.split(',') : product.main_ingredients;
|
||||
|
||||
return {
|
||||
title,
|
||||
@@ -106,17 +105,36 @@ export default async function ShopProductPage({ params }: { params: Promise<{ sl
|
||||
]
|
||||
};
|
||||
|
||||
const safeProductJsonLd = JSON.stringify(productJsonLd).replace(/</g, '\\u003c');
|
||||
const safeBreadcrumbJsonLd = JSON.stringify(breadcrumbJsonLd).replace(/</g, '\\u003c');
|
||||
|
||||
return (
|
||||
<>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(productJsonLd) }}
|
||||
dangerouslySetInnerHTML={{ __html: safeProductJsonLd }}
|
||||
/>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbJsonLd) }}
|
||||
dangerouslySetInnerHTML={{ __html: safeBreadcrumbJsonLd }}
|
||||
/>
|
||||
<ProductPage productSlug={resolvedParams.slug} />
|
||||
<Suspense fallback={
|
||||
<div className="min-h-screen bg-medical-gray-50 p-6 max-w-7xl mx-auto font-vazir" dir="rtl">
|
||||
<div className="animate-pulse space-y-6">
|
||||
<div className="h-8 bg-medical-gray-200 rounded-2xl w-48" />
|
||||
<div className="grid md:grid-cols-12 gap-8">
|
||||
<div className="md:col-span-5 h-80 bg-white border border-medical-gray-200 rounded-[2.5rem]" />
|
||||
<div className="md:col-span-7 space-y-4">
|
||||
<div className="h-10 bg-medical-gray-200 rounded-2xl w-3/4" />
|
||||
<div className="h-6 bg-medical-gray-100 rounded-xl w-1/2" />
|
||||
<div className="h-24 bg-medical-gray-100 rounded-2xl w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}>
|
||||
<ProductPage productSlug={resolvedParams.slug} />
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -4,12 +4,14 @@ import { Phone, Mail, MapPin, Instagram, ShieldCheck, Globe, ArrowUp, Download }
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import Link from "next/link";
|
||||
|
||||
import { NavigationTarget } from "../lib/types";
|
||||
|
||||
export default function Footer({
|
||||
onNavigate = () => {},
|
||||
onShopNavigate = () => {},
|
||||
onB2BOpen
|
||||
}: {
|
||||
onNavigate?: (v: any) => void;
|
||||
onNavigate?: (v: NavigationTarget) => void;
|
||||
onShopNavigate?: (c?: string) => void;
|
||||
onB2BOpen?: () => void;
|
||||
}) {
|
||||
|
||||
@@ -22,6 +22,8 @@ const MENU_ICONS: Record<string, React.ReactNode> = {
|
||||
"special-care": <Sparkles className="w-5 h-5" />,
|
||||
};
|
||||
|
||||
import { NavigationTarget } from "../lib/types";
|
||||
|
||||
export default function Header({
|
||||
onNavigate = () => {},
|
||||
onShopNavigate = () => {},
|
||||
@@ -30,7 +32,7 @@ export default function Header({
|
||||
onSearch = () => {},
|
||||
onB2BOpen = () => {}
|
||||
}: {
|
||||
onNavigate?: (v: any) => void;
|
||||
onNavigate?: (v: NavigationTarget) => void;
|
||||
onShopNavigate?: (c?: string, s?: string) => void;
|
||||
currentView?: string;
|
||||
onCartOpen?: () => void;
|
||||
|
||||
@@ -61,12 +61,13 @@ function Typewriter({ text }: { text: string }) {
|
||||
}
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Banner } from "../lib/types";
|
||||
|
||||
export default function Hero({ banners = [] }: { banners?: any[] }) {
|
||||
export default function Hero({ banners = [] }: { banners?: Banner[] }) {
|
||||
const router = useRouter();
|
||||
const getText = useSettingsStore(state => state.getText);
|
||||
const title = getText('hero_title', '') || (banners.length > 0 ? banners[0].title : "تخصص آلمانی در خدمت\nسلامت پتهای خانگی");
|
||||
const subtitle = getText('hero_desc', '') || (banners.length > 0 ? banners[0].subtitle : 'بیش از <span className="font-bold text-canina-blue">۴۰ سال</span> تجربه نوآورانه در تولید مکملهای درمانی با بالاترین استاندارد کیفی «گرید دارویی اختصاصی». راهکار هوشمند برای هر نیاز بالینی.');
|
||||
const title = getText('hero_title', '') || (banners.length > 0 && banners[0].title ? banners[0].title : "تخصص آلمانی در خدمت\nسلامت پتهای خانگی");
|
||||
const subtitle = getText('hero_desc', '') || (banners.length > 0 && banners[0].subtitle ? banners[0].subtitle : 'بیش از <span className="font-bold text-canina-blue">۴۰ سال</span> تجربه نوآورانه در تولید مکملهای درمانی با بالاترین استاندارد کیفی «گرید دارویی اختصاصی». راهکار هوشمند برای هر نیاز بالینی.');
|
||||
const titleParts = title.split('\n');
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
export interface Banner {
|
||||
id?: string;
|
||||
imageUrl?: string;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
link?: string;
|
||||
}
|
||||
|
||||
export interface VetTestimonial {
|
||||
id?: string;
|
||||
name?: string;
|
||||
role?: string;
|
||||
text?: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
|
||||
export interface SmartAdvisorRule {
|
||||
id?: string;
|
||||
condition?: string;
|
||||
recommendation?: string;
|
||||
category?: string;
|
||||
symptom?: string;
|
||||
recommendedProductSlug?: string;
|
||||
}
|
||||
|
||||
export interface HomeApiResponse {
|
||||
heroBanners?: Banner[];
|
||||
vetTestimonials?: VetTestimonial[];
|
||||
smartAdvisorRules?: SmartAdvisorRule[];
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export type NavigationTarget = string | { view: string };
|
||||
|
||||
export interface NavigationHandler {
|
||||
(target: NavigationTarget): void;
|
||||
}
|
||||
Reference in new issue
Block a user