feat: core pages and components migrated to Next.js (Home, Shop, Product)
This commit is contained in:
1 parent
72d2a5600a
commit
3de0408e6f
11 files changed
+246
-138
No files matched your search
@@ -162,19 +162,16 @@ const ArchiveProductCard: React.FC<{ product: Product, onClick: (p: Product) =>
|
||||
);
|
||||
}
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function ArchivePage({
|
||||
onProductClick,
|
||||
onBack,
|
||||
onShopNavigate,
|
||||
initialCategory = "all",
|
||||
initialSearch = ""
|
||||
}: {
|
||||
onProductClick: (p: Product) => void,
|
||||
onBack?: () => void,
|
||||
onShopNavigate?: (c?: string, s?: string) => void,
|
||||
initialCategory?: string,
|
||||
initialSearch?: string
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [selectedCategory, setSelectedCategory] = useState(initialCategory);
|
||||
const [selectedPet, setSelectedPet] = useState<PetType | "all">("all");
|
||||
const [activeSymptoms, setActiveSymptoms] = useState<string[]>([]);
|
||||
@@ -262,7 +259,7 @@ export default function ArchivePage({
|
||||
{/* Mobile Navigation & Breadcrumbs */}
|
||||
<div className="lg:hidden mb-10 space-y-4">
|
||||
<button
|
||||
onClick={onBack}
|
||||
onClick={() => router.back()}
|
||||
className="flex items-center gap-2 text-medical-gray-500 font-bold hover:text-canina-blue transition-colors"
|
||||
>
|
||||
<ChevronRight className="w-5 h-5 font-vazir" />
|
||||
@@ -270,7 +267,7 @@ export default function ArchivePage({
|
||||
</button>
|
||||
|
||||
<div className="flex items-center gap-2 text-[10px] font-black text-medical-gray-400 uppercase tracking-widest overflow-x-auto whitespace-nowrap pb-2">
|
||||
<span className="cursor-pointer hover:text-canina-blue" onClick={onBack}>کانینا</span>
|
||||
<span className="cursor-pointer hover:text-canina-blue" onClick={() => router.push('/')}>کانینا</span>
|
||||
<ChevronLeft className="w-2.5 h-2.5" />
|
||||
<span className="text-canina-blue">فروشگاه تخصصی</span>
|
||||
</div>
|
||||
@@ -278,7 +275,7 @@ export default function ArchivePage({
|
||||
|
||||
{/* Desktop Breadcrumbs */}
|
||||
<div className="hidden lg:flex items-center gap-2 text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-10">
|
||||
<span className="cursor-pointer hover:text-canina-blue" onClick={onBack}>خانه</span>
|
||||
<span className="cursor-pointer hover:text-canina-blue" onClick={() => router.push('/')}>خانه</span>
|
||||
<ChevronLeft className="w-2.5 h-2.5" />
|
||||
<span className="text-canina-blue">کاتالوگ کامل محصولات</span>
|
||||
</div>
|
||||
@@ -386,7 +383,7 @@ export default function ArchivePage({
|
||||
<div key="grid" className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">
|
||||
<AnimatePresence mode="popLayout">
|
||||
{filteredProducts.map((p: Product) => (
|
||||
<ArchiveProductCard key={p.id} product={p} onClick={onProductClick} />
|
||||
<ArchiveProductCard key={p.id} product={p} onClick={(p) => router.push(`/shop/${p.id}`)} />
|
||||
))}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
@@ -399,14 +396,11 @@ export default function ArchivePage({
|
||||
<p className="text-medical-gray-400 max-w-sm mb-8 font-bold">با فیلترهای فعلی محصولی مطابق با نیاز شما پیدا نکردیم. لطفاً فیلترها را گستردهتر کنید یا دکمه ریست را بزنید.</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (onShopNavigate) {
|
||||
onShopNavigate("all");
|
||||
} else {
|
||||
setSelectedCategory("all");
|
||||
setSelectedPet("all");
|
||||
setActiveSymptoms([]);
|
||||
setSearchQuery("");
|
||||
}
|
||||
router.push('/shop');
|
||||
setSelectedCategory("all");
|
||||
setSelectedPet("all");
|
||||
setActiveSymptoms([]);
|
||||
setSearchQuery("");
|
||||
}}
|
||||
className="bg-canina-blue text-white px-8 py-3 rounded-xl font-black text-sm hover:scale-105 transition-transform shadow-lg shadow-canina-blue/20"
|
||||
>
|
||||
|
||||
@@ -92,7 +92,10 @@ function ProductCard({ product, onClick }: { product: Product; key?: string | nu
|
||||
);
|
||||
}
|
||||
|
||||
export default function FeaturedProducts({ onProductClick, onShopNavigate }: { onProductClick: (p: Product) => void, onShopNavigate: () => void }) {
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function FeaturedProducts() {
|
||||
const router = useRouter();
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
@@ -124,7 +127,7 @@ export default function FeaturedProducts({ onProductClick, onShopNavigate }: { o
|
||||
محصولات دارویی کانینا با استفاده از دانش پیشرفته بیوتکنولوژی و مواد اولیه ارگانیک نایاب فرآوری شدهاند.
|
||||
</p>
|
||||
<button
|
||||
onClick={onShopNavigate}
|
||||
onClick={() => router.push('/shop')}
|
||||
className="inline-flex items-center gap-2 text-canina-blue font-bold text-sm hover:translate-x-1 transition-transform rtl:hover:-translate-x-1"
|
||||
>
|
||||
مشاهده تمامی محصولات
|
||||
@@ -138,7 +141,7 @@ export default function FeaturedProducts({ onProductClick, onShopNavigate }: { o
|
||||
Array.from({ length: 3 }).map((_, i) => <ProductCardSkeleton key={i} />)
|
||||
) : (
|
||||
products.map((p) => (
|
||||
<ProductCard key={p.id} onClick={onProductClick} product={p} />
|
||||
<ProductCard key={p.id} onClick={(p) => router.push(`/shop/${p.id}`)} product={p} />
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -60,7 +60,10 @@ function Typewriter({ text }: { text: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
export default function Hero({ onProfileClick, onShopNavigate }: { onProfileClick?: () => void, onShopNavigate?: () => void }) {
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function Hero() {
|
||||
const router = useRouter();
|
||||
const getText = useSettingsStore(state => state.getText);
|
||||
const title = getText('hero_title', "تخصص آلمانی در خدمت\nسلامت پتهای خانگی");
|
||||
const titleParts = title.split('\n');
|
||||
@@ -115,7 +118,7 @@ export default function Hero({ onProfileClick, onShopNavigate }: { onProfileClic
|
||||
<ChevronLeft className="w-5 h-5 group-hover:-translate-x-1 transition-transform" />
|
||||
</button>
|
||||
<button
|
||||
onClick={onShopNavigate}
|
||||
onClick={() => router.push('/shop')}
|
||||
className="bg-white border-2 border-medical-gray-200 text-medical-gray-700 px-10 py-5 rounded-full font-bold text-lg hover:border-canina-blue hover:text-canina-blue transition-all font-vazir"
|
||||
>
|
||||
{getText('hero_btn_products', "مشاهده محصولات")}
|
||||
|
||||
@@ -67,13 +67,12 @@ const useCalculatorStore = create<CalculatorState>((set) => ({
|
||||
import Tooltip from "./Tooltip";
|
||||
import SafeImage from "./SafeImage";
|
||||
|
||||
export default function ProductPage({ product, onBack, onProductClick, onWikiNavigate, onShopNavigate }: {
|
||||
product: Product;
|
||||
onBack: () => void;
|
||||
onProductClick: (p: Product) => void;
|
||||
onWikiNavigate?: (id: string) => void;
|
||||
onShopNavigate?: (category?: string) => void;
|
||||
}) {
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function ProductPage({ productId }: { productId: string }) {
|
||||
const router = useRouter();
|
||||
const [product, setProduct] = useState<Product | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<"specs" | "feeding" | "notes">("specs");
|
||||
const [showRefillModal, setShowRefillModal] = useState(false);
|
||||
const [itemQuantity, setItemQuantity] = useState(1);
|
||||
@@ -81,9 +80,14 @@ export default function ProductPage({ product, onBack, onProductClick, onWikiNav
|
||||
|
||||
useEffect(() => {
|
||||
productService.getProducts()
|
||||
.then(setAllProducts)
|
||||
.catch(err => console.error("Error fetching products in ProductPage:", err));
|
||||
}, []);
|
||||
.then((products) => {
|
||||
setAllProducts(products);
|
||||
const found = products.find(p => p.id === productId);
|
||||
setProduct(found || null);
|
||||
})
|
||||
.catch(err => console.error("Error fetching products in ProductPage:", err))
|
||||
.finally(() => setIsLoading(false));
|
||||
}, [productId]);
|
||||
const { pets, getActivePet } = usePetStore();
|
||||
const activePet = getActivePet();
|
||||
const { petType, weight, setPetType, setWeight } = useCalculatorStore();
|
||||
@@ -142,9 +146,12 @@ export default function ProductPage({ product, onBack, onProductClick, onWikiNav
|
||||
|
||||
// Suggest quantity inside useEffect to avoid render-phase state update
|
||||
useEffect(() => {
|
||||
const suggestedQty = (calculation.duration < 30 && calculation.duration > 0) ? 2 : 1;
|
||||
const suggestedQty = (calculation?.duration < 30 && calculation?.duration > 0) ? 2 : 1;
|
||||
setItemQuantity(suggestedQty);
|
||||
}, [calculation.duration]);
|
||||
}, [calculation?.duration]);
|
||||
|
||||
if (isLoading) return <div className="min-h-screen flex items-center justify-center">Loading...</div>;
|
||||
if (!product || !fullProduct || !calculation) return <div className="min-h-screen flex items-center justify-center">محصول یافت نشد</div>;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-medical-gray-50 pt-2 pb-20 px-4 md:px-0" dir="rtl">
|
||||
@@ -152,7 +159,7 @@ export default function ProductPage({ product, onBack, onProductClick, onWikiNav
|
||||
{/* Mobile Header with Back Button */}
|
||||
<div className="flex items-center justify-between mb-6 md:hidden">
|
||||
<button
|
||||
onClick={onBack}
|
||||
onClick={() => router.back()}
|
||||
className="p-3 bg-white border border-medical-gray-200 rounded-2xl text-medical-gray-700 shadow-sm flex items-center gap-2 font-vazir text-sm font-bold"
|
||||
>
|
||||
<ChevronRight className="w-5 h-5" />
|
||||
@@ -166,14 +173,14 @@ export default function ProductPage({ product, onBack, onProductClick, onWikiNav
|
||||
{/* Breadcrumbs */}
|
||||
<nav className="hidden md:flex items-center gap-2 text-xs font-bold text-medical-gray-400 mb-8 overflow-x-auto whitespace-nowrap py-2">
|
||||
<button
|
||||
onClick={() => onBack()}
|
||||
onClick={() => router.push('/')}
|
||||
className="hover:text-canina-blue transition-colors font-vazir cursor-pointer"
|
||||
>
|
||||
خانه
|
||||
</button>
|
||||
<ChevronLeft className="w-3 h-3 flex-shrink-0" />
|
||||
<button
|
||||
onClick={() => onShopNavigate?.(product.category)}
|
||||
onClick={() => router.push(`/shop?category=${product.category}`)}
|
||||
className="hover:text-canina-blue cursor-pointer font-vazir"
|
||||
>
|
||||
{product.category}
|
||||
@@ -281,7 +288,7 @@ export default function ProductPage({ product, onBack, onProductClick, onWikiNav
|
||||
<div key={idx} className="bg-medical-gray-50 border border-medical-gray-100 px-5 py-3 rounded-2xl flex items-center gap-3 group hover:border-canina-blue/30 transition-all">
|
||||
<span className="text-sm font-bold text-medical-gray-700 font-vazir">
|
||||
{termKey ? (
|
||||
<Tooltip termKey={termKey} onWikiNavigate={onWikiNavigate}>
|
||||
<Tooltip termKey={termKey} onWikiNavigate={(id) => router.push(`/wiki?term=${id}`)}>
|
||||
{ing}
|
||||
</Tooltip>
|
||||
) : ing}
|
||||
@@ -530,7 +537,7 @@ export default function ProductPage({ product, onBack, onProductClick, onWikiNav
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
className="bg-white rounded-[3rem] p-8 border border-medical-gray-200 flex flex-col md:flex-row gap-8 items-center cursor-pointer hover:shadow-2xl transition-all"
|
||||
onClick={() => onProductClick(relProduct)}
|
||||
onClick={() => router.push(`/shop/${relProduct.id}`)}
|
||||
>
|
||||
<div className="w-40 h-40 bg-medical-gray-50 rounded-[2rem] p-4 flex items-center justify-center">
|
||||
<SafeImage src={relProduct.image} alt={relProduct.name} className="w-full h-full object-contain drop-shadow-xl" />
|
||||
|
||||
@@ -16,16 +16,13 @@ import {
|
||||
} from "lucide-react";
|
||||
import { toPersian, cn } from "../lib/utils";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
import { useUIStore } from "../lib/store/uiStore";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
|
||||
interface SmartAdvisorProps {
|
||||
onComplete: (data: {
|
||||
name: string,
|
||||
type: "سگ" | "گربه",
|
||||
breed: string,
|
||||
age: number,
|
||||
weight: number,
|
||||
activityLevel: "کم" | "متوسط" | "زیاد",
|
||||
medicalConditions: string[]
|
||||
}) => void;
|
||||
onComplete?: (data: any) => void;
|
||||
}
|
||||
|
||||
const MEDICAL_OPTIONS = [
|
||||
@@ -37,7 +34,11 @@ const MEDICAL_OPTIONS = [
|
||||
{ id: "appetite", label: "بیاشتهایی", condition: "بیاشتهایی" },
|
||||
];
|
||||
|
||||
export default function SmartAdvisor({ onComplete }: SmartAdvisorProps) {
|
||||
export default function SmartAdvisor({ onComplete }: SmartAdvisorProps = {}) {
|
||||
const router = useRouter();
|
||||
const { isLoggedIn } = useUserStore();
|
||||
const setLoginModalOpen = useUIStore(state => state.setLoginModalOpen);
|
||||
const { addPet, setActivePet } = usePetStore();
|
||||
const texts = useSettingsStore(state => state.texts);
|
||||
const medicalOptions = React.useMemo(() => {
|
||||
const jsonStr = texts['medical_options'];
|
||||
@@ -70,15 +71,21 @@ export default function SmartAdvisor({ onComplete }: SmartAdvisorProps) {
|
||||
const handleBack = () => setStep(s => s - 1);
|
||||
|
||||
const handleSubmit = () => {
|
||||
onComplete({
|
||||
name,
|
||||
type,
|
||||
breed,
|
||||
age,
|
||||
weight,
|
||||
activityLevel,
|
||||
medicalConditions
|
||||
});
|
||||
const data = {
|
||||
name, type, breed, age, weight, activityLevel, medicalConditions
|
||||
};
|
||||
if (onComplete) {
|
||||
onComplete(data);
|
||||
} else {
|
||||
if (!isLoggedIn) {
|
||||
setLoginModalOpen(true, data);
|
||||
} else {
|
||||
const newPet = { ...data, id: Date.now().toString() };
|
||||
addPet(newPet);
|
||||
setActivePet(newPet.id);
|
||||
router.push('/profile');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -33,7 +33,8 @@ const VIDEOS = [
|
||||
}
|
||||
];
|
||||
|
||||
export default function VetGallery({ onNavigate }: { onNavigate?: (v: any) => void }) {
|
||||
export default function VetGallery() {
|
||||
const router = useRouter();
|
||||
const [selectedVideo, setSelectedVideo] = useState<typeof VIDEOS[0] | null>(null);
|
||||
|
||||
return (
|
||||
@@ -53,8 +54,8 @@ export default function VetGallery({ onNavigate }: { onNavigate?: (v: any) => vo
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => onNavigate?.('videos')}
|
||||
className="flex items-center gap-2 text-canina-blue font-black border-b-2 border-canina-blue pb-1 hover:gap-4 transition-all whitespace-nowrap"
|
||||
onClick={() => router.push('/videos')}
|
||||
className="inline-flex items-center gap-2 text-canina-blue font-bold text-sm hover:translate-x-1 transition-transform rtl:hover:-translate-x-1"
|
||||
>
|
||||
مشاهده همه ویدئوها
|
||||
<Play className="w-4 h-4" />
|
||||
@@ -80,9 +81,9 @@ export default function VetGallery({ onNavigate }: { onNavigate?: (v: any) => vo
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-black/30 group-hover:bg-black/20 transition-colors flex items-center justify-center">
|
||||
<div className="w-16 h-16 bg-white/90 rounded-full flex items-center justify-center text-canina-blue shadow-2xl group-hover:scale-110 transition-transform">
|
||||
<button onClick={() => router.push('/videos')} className="w-16 h-16 rounded-full bg-white/10 backdrop-blur-md flex items-center justify-center group-hover:scale-110 transition-transform border border-white/20 relative z-10">
|
||||
<PlayCircle className="w-10 h-10" />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div className="absolute bottom-4 right-4 bg-black/60 backdrop-blur-md text-white px-3 py-1 rounded-lg text-[10px] font-black">
|
||||
{video.duration}
|
||||
|
||||
Reference in new issue
Block a user