feat: layout and overlays migrated to Next.js
This commit is contained in:
1 parent
c5a1b8e5d2
commit
72d2a5600a
42 files changed
+9064
-42
No files matched your search
@@ -0,0 +1,106 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import Header from "../components/Header";
|
||||
import Footer from "../components/Footer";
|
||||
import { NetworkBanner } from "../components/NetworkBanner";
|
||||
import { Toaster } from "sonner";
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
|
||||
import CartDrawer from "../components/CartDrawer";
|
||||
import LoginModal from "../components/LoginModal";
|
||||
import B2BPortal from "../components/B2BPortal";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
|
||||
export default function ClientLayout({ children }: { children: React.ReactNode }) {
|
||||
const [isCartOpen, setIsCartOpen] = useState(false);
|
||||
const [showB2B, setShowB2B] = useState(false);
|
||||
const [showLoginModal, setShowLoginModal] = useState(false);
|
||||
const [advisorData, setAdvisorData] = useState<any>(null);
|
||||
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
const { fetchProfile } = useUserStore();
|
||||
const fetchSettings = useSettingsStore(state => state.fetchSettings);
|
||||
|
||||
useEffect(() => {
|
||||
fetchSettings();
|
||||
const token = localStorage.getItem('accessToken');
|
||||
if (token) {
|
||||
fetchProfile().catch(e => console.error("Auth init failed:", e));
|
||||
}
|
||||
}, [fetchProfile, fetchSettings]);
|
||||
|
||||
// Derived currentView from pathname for Header
|
||||
let currentView = "home";
|
||||
if (pathname?.includes("/shop")) currentView = "shop";
|
||||
if (pathname?.includes("/wiki")) currentView = "wiki";
|
||||
if (pathname?.includes("/profile")) currentView = "profile";
|
||||
if (pathname?.includes("/checkout")) currentView = "checkout";
|
||||
if (pathname?.includes("/dashboard")) currentView = "user-dashboard";
|
||||
|
||||
const handleNavigate = (v: any) => {
|
||||
if (typeof v === 'object') {
|
||||
if (v.view === 'profile') router.push('/profile');
|
||||
if (v.view === 'order-tracking') router.push('/order/tracking');
|
||||
if (v.view === 'home') router.push('/');
|
||||
} else {
|
||||
if (v === 'home') router.push('/');
|
||||
else if (v === 'user-dashboard') router.push('/dashboard');
|
||||
else router.push(`/${v}`);
|
||||
}
|
||||
};
|
||||
|
||||
const navigateToShop = (category: string = "all", search: string = "") => {
|
||||
const params = new URLSearchParams();
|
||||
if (category && category !== "all") params.set("category", category);
|
||||
if (search) params.set("search", search);
|
||||
const newUrl = params.toString() ? `/shop?${params.toString()}` : "/shop";
|
||||
router.push(newUrl);
|
||||
};
|
||||
|
||||
const handleSearch = (q: string) => {
|
||||
router.push(`/search?q=${encodeURIComponent(q)}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<NetworkBanner />
|
||||
<Header
|
||||
onNavigate={handleNavigate}
|
||||
onShopNavigate={navigateToShop}
|
||||
currentView={currentView}
|
||||
onCartOpen={() => setIsCartOpen(true)}
|
||||
onSearch={handleSearch}
|
||||
onB2BOpen={() => setShowB2B(true)}
|
||||
/>
|
||||
<main className="min-h-screen">
|
||||
{children}
|
||||
</main>
|
||||
<Footer onNavigate={handleNavigate} onShopNavigate={navigateToShop} onB2BOpen={() => setShowB2B(true)} />
|
||||
|
||||
{showB2B && <B2BPortal onClose={() => setShowB2B(false)} />}
|
||||
<CartDrawer
|
||||
isOpen={isCartOpen}
|
||||
onClose={() => setIsCartOpen(false)}
|
||||
onCheckout={() => { setIsCartOpen(false); router.push('/checkout'); }}
|
||||
onShopNavigate={navigateToShop}
|
||||
/>
|
||||
<LoginModal
|
||||
isOpen={showLoginModal}
|
||||
onClose={() => {
|
||||
setShowLoginModal(false);
|
||||
setAdvisorData(null);
|
||||
}}
|
||||
onLogin={() => {
|
||||
setShowLoginModal(false);
|
||||
}}
|
||||
petName={advisorData?.name}
|
||||
isAdvisorContext={!!advisorData}
|
||||
/>
|
||||
<Toaster position="top-center" expand={true} richColors />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,33 +1,24 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
import type { Metadata } from 'next';
|
||||
import './globals.css';
|
||||
import ClientLayout from './ClientLayout';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
title: 'Canina Iran - کانینا ایران',
|
||||
description: 'لابراتوار تخصصی مکملهای حیوانات خانگی کانینا',
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
}) {
|
||||
return (
|
||||
<html
|
||||
lang="en"
|
||||
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
|
||||
>
|
||||
<body className="min-h-full flex flex-col">{children}</body>
|
||||
<html lang="fa" dir="rtl">
|
||||
<body className="min-h-screen bg-medical-gray-50 font-sans">
|
||||
<ClientLayout>
|
||||
{children}
|
||||
</ClientLayout>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user