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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user