first commit
This commit is contained in:
153
components/layout/Header.tsx
Normal file
153
components/layout/Header.tsx
Normal file
@@ -0,0 +1,153 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from "react"
|
||||
import Link from "next/link"
|
||||
import Image from "next/image"
|
||||
import { X, Menu, Search, Store } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import Logo from "@/public/logo.png"
|
||||
import CategoryMenu from "./ui/CategoryMenu"
|
||||
import SearchBar from "./ui/SearchBar"
|
||||
import AuthDialog from "./ui/AuthDialog"
|
||||
import ActionButtons from "./ui/ActionButtons"
|
||||
import LanguageSelector from "./ui/LanguageSelector"
|
||||
|
||||
interface HeaderProps {
|
||||
locale?: string
|
||||
isAuthenticated?: boolean
|
||||
translations?: {
|
||||
catalog: string
|
||||
search: string
|
||||
orders: string
|
||||
favorites: string
|
||||
cart: string
|
||||
login: string
|
||||
profile: string
|
||||
openStore: string
|
||||
phone: string
|
||||
code: string
|
||||
send: string
|
||||
enterPhone: string
|
||||
weWillSendCode: string
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_TRANSLATIONS = {
|
||||
catalog: "Каталог",
|
||||
search: "Поиск продукта",
|
||||
orders: "Заказы",
|
||||
favorites: "Избранное",
|
||||
cart: "Корзина",
|
||||
login: "Войти",
|
||||
profile: "Профиль",
|
||||
openStore: "Открыть магазин",
|
||||
phone: "Номер телефона",
|
||||
code: "Код",
|
||||
send: "Отправить",
|
||||
enterPhone: "Введите свой номер телефона",
|
||||
weWillSendCode: "Мы вышлем вам код",
|
||||
}
|
||||
|
||||
export default function Header({ locale = "ru", isAuthenticated = false, translations }: HeaderProps) {
|
||||
const [isClient, setIsClient] = useState(false)
|
||||
const [isCategoryOpen, setIsCategoryOpen] = useState(false)
|
||||
const [isMobileSearchOpen, setIsMobileSearchOpen] = useState(false)
|
||||
const [isLoginOpen, setIsLoginOpen] = useState(false)
|
||||
|
||||
const t = translations || DEFAULT_TRANSLATIONS
|
||||
|
||||
useEffect(() => {
|
||||
setIsClient(true)
|
||||
}, [])
|
||||
|
||||
const handleAuthClick = () => {
|
||||
if (isAuthenticated) {
|
||||
window.location.href = `/${locale}/me`
|
||||
} else {
|
||||
setIsLoginOpen(true)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleCategoryMenu = () => setIsCategoryOpen(!isCategoryOpen)
|
||||
const closeCategoryMenu = () => setIsCategoryOpen(false)
|
||||
|
||||
if (!isClient) return null
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="sticky top-0 z-50 w-full border-b bg-white shadow-sm">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="flex h-16 items-center justify-between gap-4">
|
||||
<Link href="/" className="shrink-0">
|
||||
<div className="relative h-8 w-[180px]">
|
||||
<Image src={Logo || "/placeholder.svg"} alt="Logo" fill className="object-contain" priority />
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<Button
|
||||
onClick={toggleCategoryMenu}
|
||||
className="hidden gap-2 rounded-xl font-bold sm:flex hover:bg-[#005bff] bg-[#005bff] text-white"
|
||||
size="lg"
|
||||
>
|
||||
{isCategoryOpen ? <X className="h-5 w-5" /> : <Menu className="h-5 w-5" />}
|
||||
{t.catalog}
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-2 sm:hidden">
|
||||
<Button variant="ghost" size="icon" onClick={() => setIsMobileSearchOpen(true)}>
|
||||
<Search className="h-5 w-5" />
|
||||
</Button>
|
||||
<LanguageSelector />
|
||||
</div>
|
||||
|
||||
<div className="hidden sm:block">
|
||||
<LanguageSelector />
|
||||
</div>
|
||||
|
||||
<SearchBar isMobile={false} searchPlaceholder={t.search} className="hidden flex-1 md:flex" />
|
||||
|
||||
<ActionButtons
|
||||
isAuthenticated={isAuthenticated}
|
||||
onAuthClick={handleAuthClick}
|
||||
translations={{
|
||||
profile: t.profile,
|
||||
login: t.login,
|
||||
orders: t.orders,
|
||||
favorites: t.favorites,
|
||||
cart: t.cart,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Link href="/openStore">
|
||||
<Button variant="ghost" size="sm" className="relative flex gap-0.5 h-auto pb-2">
|
||||
<Store className="h-5 w-5 text-gray-600" />
|
||||
<span className="text-xs text-gray-700">{t.openStore}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<CategoryMenu isOpen={isCategoryOpen} onClose={closeCategoryMenu} />
|
||||
|
||||
<SearchBar
|
||||
isMobile={true}
|
||||
isOpen={isMobileSearchOpen}
|
||||
onClose={() => setIsMobileSearchOpen(false)}
|
||||
searchPlaceholder={t.search}
|
||||
/>
|
||||
|
||||
<AuthDialog
|
||||
isOpen={isLoginOpen}
|
||||
onClose={() => setIsLoginOpen(false)}
|
||||
translations={{
|
||||
enterPhone: t.enterPhone,
|
||||
weWillSendCode: t.weWillSendCode,
|
||||
phone: t.phone,
|
||||
code: t.code,
|
||||
send: t.send,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
177
components/layout/MobileBar.tsx
Normal file
177
components/layout/MobileBar.tsx
Normal file
@@ -0,0 +1,177 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from "react"
|
||||
import Link from "next/link"
|
||||
import { Menu, Heart, Truck, ShoppingCart, User } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useCategories, useCart, useFavorites, useOrders } from "@/lib/hooks"
|
||||
|
||||
interface MobileBottomNavProps {
|
||||
locale?: string
|
||||
isAuthenticated?: boolean
|
||||
translations?: {
|
||||
catalog: string
|
||||
favorites: string
|
||||
orders: string
|
||||
cart: string
|
||||
login: string
|
||||
profile: string
|
||||
}
|
||||
onLoginClick?: () => void
|
||||
}
|
||||
|
||||
export default function MobileBottomNav({
|
||||
locale = "ru",
|
||||
isAuthenticated = false,
|
||||
translations,
|
||||
onLoginClick,
|
||||
}: MobileBottomNavProps) {
|
||||
const [isClient, setIsClient] = useState(false)
|
||||
const [isCategoryOpen, setIsCategoryOpen] = useState(false)
|
||||
|
||||
const { data: categories = [] } = useCategories()
|
||||
const { data: cartData } = useCart()
|
||||
const { data: favoritesData } = useFavorites()
|
||||
const { data: ordersData } = useOrders()
|
||||
|
||||
const t = translations || {
|
||||
catalog: "Каталог",
|
||||
favorites: "Избранное",
|
||||
orders: "Заказы",
|
||||
cart: "Корзина",
|
||||
login: "Войти",
|
||||
profile: "Профиль",
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setIsClient(true)
|
||||
}, [])
|
||||
|
||||
const handleAuthClick = () => {
|
||||
if (isAuthenticated) {
|
||||
window.location.href = `/${locale}/me`
|
||||
} else if (onLoginClick) {
|
||||
onLoginClick()
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClient) return null
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Mobile Bottom Navigation */}
|
||||
<div className="fixed bottom-0 left-0 right-0 z-50 bg-white border-t shadow-lg md:hidden">
|
||||
<div className="flex items-center justify-around h-16 px-2">
|
||||
{/* Catalog Button */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="flex-col gap-0.5 h-auto px-2 py-2"
|
||||
onClick={() => setIsCategoryOpen(true)}
|
||||
>
|
||||
<Menu className="h-5 w-5 text-gray-600" />
|
||||
<span className="text-xs text-gray-700">{t.catalog}</span>
|
||||
</Button>
|
||||
|
||||
{/* Favorites Button */}
|
||||
<Link href="/favorites">
|
||||
<Button variant="ghost" size="sm" className="relative flex-col gap-0.5 h-auto px-2 py-2">
|
||||
<div className="relative">
|
||||
<Heart className="h-5 w-5 text-gray-600" />
|
||||
<Badge
|
||||
variant="destructive"
|
||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||
>
|
||||
{favoritesData?.length || 0}
|
||||
</Badge>
|
||||
</div>
|
||||
<span className="text-xs text-gray-700">{t.favorites}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
{/* Orders Button */}
|
||||
<Link href="/orders">
|
||||
<Button variant="ghost" size="sm" className="relative flex-col gap-0.5 h-auto px-2 py-2">
|
||||
<div className="relative">
|
||||
<Truck className="h-5 w-5 text-gray-600" />
|
||||
<Badge
|
||||
variant="destructive"
|
||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||
>
|
||||
{ordersData?.length || 0}
|
||||
</Badge>
|
||||
</div>
|
||||
<span className="text-xs text-gray-700">{t.orders}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
{/* Cart Button */}
|
||||
<Link href="/cart">
|
||||
<Button variant="ghost" size="sm" className="relative flex-col gap-0.5 h-auto px-2 py-2">
|
||||
<div className="relative">
|
||||
<ShoppingCart className="h-5 w-5 text-gray-600" />
|
||||
<Badge
|
||||
variant="destructive"
|
||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||
>
|
||||
{cartData?.count || 0}
|
||||
</Badge>
|
||||
</div>
|
||||
<span className="text-xs text-gray-700">{t.cart}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
{/* Profile/Login Button */}
|
||||
<Button variant="ghost" size="sm" className="flex-col gap-0.5 h-auto px-2 py-2" onClick={handleAuthClick}>
|
||||
<User className="h-5 w-5 text-gray-600" />
|
||||
<span className="text-xs text-gray-700">{isAuthenticated ? t.profile : t.login}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Category Sheet/Drawer */}
|
||||
<Sheet open={isCategoryOpen} onOpenChange={setIsCategoryOpen}>
|
||||
<SheetContent side="left" className="w-[300px] p-0">
|
||||
<SheetHeader className="p-4 border-b">
|
||||
<SheetTitle>{t.catalog}</SheetTitle>
|
||||
</SheetHeader>
|
||||
<ScrollArea className="h-[calc(100vh-80px)]">
|
||||
<div className="p-4">
|
||||
{categories.map((category) => (
|
||||
<div key={category.id} className="mb-4">
|
||||
<Link
|
||||
href={`/category/${category.slug}?category_id=${category.id}`}
|
||||
onClick={() => setIsCategoryOpen(false)}
|
||||
className="flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-gray-100 transition-colors font-semibold"
|
||||
>
|
||||
{category.icon_class && <i className={`${category.icon_class} text-xl`}></i>}
|
||||
<span>{category.name}</span>
|
||||
</Link>
|
||||
|
||||
{/* Subcategories */}
|
||||
{category.children && category.children.length > 0 && (
|
||||
<div className="ml-8 mt-2 space-y-1">
|
||||
{category.children.map((child: any) => (
|
||||
<Link
|
||||
key={child.id}
|
||||
href={`/category/${child.slug}?category_id=${child.id}`}
|
||||
onClick={() => setIsCategoryOpen(false)}
|
||||
className="block px-3 py-2 text-sm text-gray-600 hover:text-primary hover:bg-gray-50 rounded-lg transition-colors"
|
||||
>
|
||||
{child.name}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</>
|
||||
)
|
||||
}
|
||||
98
components/layout/ui/ActionButtons.tsx
Normal file
98
components/layout/ui/ActionButtons.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
"use client"
|
||||
|
||||
import type React from "react"
|
||||
import Link from "next/link"
|
||||
import { User, Truck, Heart, ShoppingCart } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { useCart, useFavorites, useOrders } from "@/lib/hooks"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
|
||||
interface ActionButtonsProps {
|
||||
isAuthenticated: boolean
|
||||
onAuthClick: () => void
|
||||
translations: {
|
||||
profile: string
|
||||
login: string
|
||||
orders: string
|
||||
favorites: string
|
||||
cart: string
|
||||
}
|
||||
}
|
||||
|
||||
interface ActionButtonData {
|
||||
icon: React.ReactNode
|
||||
label: string
|
||||
href?: string
|
||||
onClick?: () => void
|
||||
badgeCount?: number
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export default function ActionButtons({ isAuthenticated, onAuthClick, translations: t }: ActionButtonsProps) {
|
||||
const { data: cartData, isLoading: cartLoading } = useCart()
|
||||
const { data: favoritesData, isLoading: favoritesLoading } = useFavorites()
|
||||
const { data: ordersData, isLoading: ordersLoading } = useOrders()
|
||||
|
||||
const buttons: ActionButtonData[] = [
|
||||
{
|
||||
icon: <User className="h-5 w-5 text-gray-600" />,
|
||||
label: isAuthenticated ? t.profile : t.login,
|
||||
onClick: onAuthClick,
|
||||
},
|
||||
{
|
||||
icon: <Truck className="h-5 w-5 text-gray-600" />,
|
||||
label: t.orders,
|
||||
href: "/orders",
|
||||
badgeCount: ordersData?.length || 0,
|
||||
isLoading: ordersLoading,
|
||||
},
|
||||
{
|
||||
icon: <Heart className="h-5 w-5 text-gray-600" />,
|
||||
label: t.favorites,
|
||||
href: "/favorites",
|
||||
badgeCount: favoritesData?.length || 0,
|
||||
isLoading: favoritesLoading,
|
||||
},
|
||||
{
|
||||
icon: <ShoppingCart className="h-5 w-5 text-gray-600" />,
|
||||
label: t.cart,
|
||||
href: "/cart",
|
||||
badgeCount: cartData?.count || 0,
|
||||
isLoading: cartLoading,
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="hidden items-center gap-1 md:flex">
|
||||
{buttons.map((button, index) => (
|
||||
<ActionButton key={index} {...button} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ActionButton({ icon, label, href, onClick, badgeCount, isLoading }: ActionButtonData) {
|
||||
const buttonContent = (
|
||||
<Button variant="ghost" size="sm" className="relative flex-col gap-0.5 h-auto px-2 py-2" onClick={onClick}>
|
||||
<div className="relative">
|
||||
{icon}
|
||||
{badgeCount !== undefined && (
|
||||
<Badge
|
||||
variant="destructive"
|
||||
className="absolute -right-2 -top-2 h-4 w-4 flex items-center justify-center p-0 text-[10px]"
|
||||
>
|
||||
{isLoading ? <Skeleton className="h-3 w-3 rounded-full" /> : badgeCount}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-xs text-gray-700">{label}</span>
|
||||
</Button>
|
||||
)
|
||||
|
||||
if (href) {
|
||||
return <Link href={href}>{buttonContent}</Link>
|
||||
}
|
||||
|
||||
return buttonContent
|
||||
}
|
||||
109
components/layout/ui/AuthDialog.tsx
Normal file
109
components/layout/ui/AuthDialog.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
import React, { useState } from "react";
|
||||
import Image from "next/image";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import Logo from "@/public/logo.png";
|
||||
|
||||
interface AuthDialogProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
translations: {
|
||||
enterPhone: string;
|
||||
weWillSendCode: string;
|
||||
phone: string;
|
||||
code: string;
|
||||
send: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default function AuthDialog({
|
||||
isOpen,
|
||||
onClose,
|
||||
translations: t,
|
||||
}: AuthDialogProps) {
|
||||
const [phone, setPhone] = useState("993");
|
||||
const [otp, setOtp] = useState("");
|
||||
const [otpSent, setOtpSent] = useState(false);
|
||||
|
||||
const handleSendOtp = () => {
|
||||
if (phone.length > 3) {
|
||||
setOtpSent(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogin = () => {
|
||||
// Here you can add authentication logic
|
||||
resetDialog();
|
||||
};
|
||||
|
||||
const resetDialog = () => {
|
||||
onClose();
|
||||
setOtpSent(false);
|
||||
setPhone("993");
|
||||
setOtp("");
|
||||
};
|
||||
|
||||
const handleKeyPress = (e: React.KeyboardEvent, action: () => void) => {
|
||||
if (e.key === "Enter") {
|
||||
action();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={resetDialog}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<div className="flex items-center justify-center mb-4">
|
||||
<div className="relative h-8 w-[180px]">
|
||||
<Image src={Logo} alt="Logo" fill className="object-contain" />
|
||||
</div>
|
||||
</div>
|
||||
<DialogTitle className="text-2xl text-center">
|
||||
{t.enterPhone}
|
||||
</DialogTitle>
|
||||
<p className="text-center text-sm text-gray-600">
|
||||
{t.weWillSendCode}
|
||||
</p>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 mt-4">
|
||||
<Input
|
||||
type="tel"
|
||||
placeholder={t.phone}
|
||||
value={phone}
|
||||
onChange={(e) => setPhone(e.target.value)}
|
||||
className="h-12 rounded-xl"
|
||||
onKeyDown={(e) => handleKeyPress(e, handleSendOtp)}
|
||||
disabled={otpSent}
|
||||
/>
|
||||
|
||||
{otpSent && (
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={t.code}
|
||||
value={otp}
|
||||
onChange={(e) => setOtp(e.target.value)}
|
||||
className="h-12 rounded-xl"
|
||||
onKeyDown={(e) => handleKeyPress(e, handleLogin)}
|
||||
autoFocus
|
||||
/>
|
||||
)}
|
||||
|
||||
<Button
|
||||
onClick={otpSent ? handleLogin : handleSendOtp}
|
||||
className="w-full h-12 rounded-xl font-bold text-base"
|
||||
size="lg"
|
||||
>
|
||||
{t.send}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
101
components/layout/ui/CategoryMenu.tsx
Normal file
101
components/layout/ui/CategoryMenu.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import Link from "next/link"
|
||||
import { useCategories } from "@/lib/hooks"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
|
||||
interface Category {
|
||||
id: number
|
||||
name: string
|
||||
slug: string
|
||||
icon_class?: string
|
||||
children?: Category[]
|
||||
}
|
||||
|
||||
interface CategoryMenuProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
export default function CategoryMenu({ isOpen, onClose }: CategoryMenuProps) {
|
||||
const [hoveredCategory, setHoveredCategory] = useState<number | null>(null)
|
||||
const { data: categories, isLoading } = useCategories()
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
const categoryList = categories || []
|
||||
const activeCategory = hoveredCategory !== null ? categoryList[hoveredCategory] : null
|
||||
|
||||
return (
|
||||
<div className="fixed left-0 right-0 top-22 z-40 bg-white border-b shadow-lg">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="flex">
|
||||
<CategoryList
|
||||
categories={categoryList}
|
||||
isLoading={isLoading}
|
||||
onCategoryHover={setHoveredCategory}
|
||||
onCategoryClick={onClose}
|
||||
/>
|
||||
|
||||
{activeCategory?.children && <SubcategoryList category={activeCategory} onSubcategoryClick={onClose} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface CategoryListProps {
|
||||
categories: any[]
|
||||
isLoading: boolean
|
||||
onCategoryHover: (index: number) => void
|
||||
onCategoryClick: () => void
|
||||
}
|
||||
|
||||
function CategoryList({ categories, isLoading, onCategoryHover, onCategoryClick }: CategoryListProps) {
|
||||
return (
|
||||
<div className="w-[280px] border-r">
|
||||
<div className="max-h-[calc(100vh-4rem)] overflow-y-auto py-2">
|
||||
{isLoading
|
||||
? [1, 2, 3, 4, 5].map((i) => <Skeleton key={i} className="h-10 mx-4 my-2 rounded" />)
|
||||
: categories.map((category, index) => (
|
||||
<Link
|
||||
key={category.id}
|
||||
href={`/category/${category.slug}?category_id=${category.id}`}
|
||||
onClick={onCategoryClick}
|
||||
onMouseEnter={() => onCategoryHover(index)}
|
||||
className="flex items-center gap-3 px-4 py-3 rounded-xl hover:bg-gray-100 hover:text-primary transition-colors"
|
||||
>
|
||||
{category.icon_class && <i className={`${category.icon_class} text-xl`}></i>}
|
||||
<span>{category.name}</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface SubcategoryListProps {
|
||||
category: any
|
||||
onSubcategoryClick: () => void
|
||||
}
|
||||
|
||||
function SubcategoryList({ category, onSubcategoryClick }: SubcategoryListProps) {
|
||||
return (
|
||||
<div className="flex-1 p-6">
|
||||
<h3 className="text-xl font-semibold mb-4">{category.name}</h3>
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
{category.children?.map((subCategory: any) => (
|
||||
<Link
|
||||
key={subCategory.id}
|
||||
href={`/category/${subCategory.slug}?category_id=${subCategory.id}`}
|
||||
onClick={onSubcategoryClick}
|
||||
className="text-gray-600 hover:text-black text-sm py-1 hover:underline"
|
||||
>
|
||||
{subCategory.name}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
59
components/layout/ui/LanguageSelector.tsx
Normal file
59
components/layout/ui/LanguageSelector.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
"use client"
|
||||
import { useRouter } from "next/navigation"
|
||||
import Image from "next/image"
|
||||
import { useLocale } from "next-intl"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||
import tm from "@/public/tm.png"
|
||||
import ru from "@/public/ru.png"
|
||||
|
||||
interface Language {
|
||||
code: string
|
||||
name: string
|
||||
flag: any
|
||||
}
|
||||
|
||||
const LANGUAGES: Language[] = [
|
||||
{ code: "ru", name: "Russian", flag: ru },
|
||||
{ code: "tm", name: "Turkmen", flag: tm },
|
||||
]
|
||||
|
||||
export default function LanguageSelector() {
|
||||
const locale = useLocale()
|
||||
const router = useRouter()
|
||||
|
||||
const handleLanguageChange = (newLocale: string) => {
|
||||
router.push(`/${newLocale}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<Select value={locale} onValueChange={handleLanguageChange}>
|
||||
<SelectTrigger className="w-[70px] rounded-xl border-gray-300">
|
||||
<SelectValue>
|
||||
<FlagIcon locale={locale} />
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{LANGUAGES.map((language) => (
|
||||
<SelectItem key={language.code} value={language.code}>
|
||||
<div className="flex items-center gap-2">
|
||||
<FlagIcon locale={language.code} />
|
||||
<span>{language.name}</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
|
||||
function FlagIcon({ locale }: { locale: string }) {
|
||||
const language = LANGUAGES.find((lang) => lang.code === locale)
|
||||
|
||||
if (!language) return null
|
||||
|
||||
return (
|
||||
<div className="relative h-5 w-7">
|
||||
<Image src={language.flag || "/placeholder.svg"} alt={language.name} fill className="object-cover rounded" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
75
components/layout/ui/SearchBar.tsx
Normal file
75
components/layout/ui/SearchBar.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import React, { useState } from "react";
|
||||
import { Search } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
interface SearchBarProps {
|
||||
isMobile: boolean;
|
||||
searchPlaceholder: string;
|
||||
isOpen?: boolean;
|
||||
onClose?: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function SearchBar({
|
||||
isMobile,
|
||||
searchPlaceholder,
|
||||
isOpen,
|
||||
onClose,
|
||||
className = "",
|
||||
}: SearchBarProps) {
|
||||
const [searchValue, setSearchValue] = useState("");
|
||||
|
||||
const handleSearch = (value: string) => {
|
||||
setSearchValue(value);
|
||||
// Here you can add search logic or API call
|
||||
};
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
<DialogContent className="top-4 translate-y-0">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{searchPlaceholder}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="relative">
|
||||
<Input
|
||||
type="search"
|
||||
placeholder={searchPlaceholder}
|
||||
value={searchValue}
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
className="h-10 rounded-xl focus:border-[#005bff] focus-visible:border-[#005bff] focus-visible:ring-0 active:border-[#005bff]"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`bg-[#005bff] rounded-xl ${className}`}>
|
||||
<div className="w-full">
|
||||
<Input
|
||||
type="search"
|
||||
placeholder={searchPlaceholder}
|
||||
value={searchValue}
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
className="border-[#005bff] w-full rounded-xl border-2 focus-visible:ring-0 bg-white px-2"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="icon"
|
||||
className="h-auto hover:bg-[#005bff] cursor-pointer bg-transparent flex items-center mr-1.5 text-white"
|
||||
>
|
||||
<Search className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user