first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { retrieveCart } from "@lib/data/cart"
|
||||
import CartDropdown from "../cart-dropdown"
|
||||
|
||||
export default async function CartButton() {
|
||||
const cart = await retrieveCart().catch(() => null)
|
||||
|
||||
return <CartDropdown cart={cart} />
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
"use client"
|
||||
|
||||
import React, { useEffect, useRef, useState } from "react"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { retrieveCart, updateLineItem, deleteLineItem } from "@lib/data/cart"
|
||||
import { CART_UPDATED_EVENT, notifyCartUpdated } from "@lib/util/cart-events"
|
||||
import { convertToLocale } from "@lib/util/money"
|
||||
import {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
SheetClose,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import Thumbnail from "@modules/products/components/thumbnail"
|
||||
import LineItemOptions from "@modules/common/components/line-item-options"
|
||||
import LineItemPrice from "@modules/common/components/line-item-price"
|
||||
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
||||
import {
|
||||
ShoppingBag,
|
||||
Minus,
|
||||
Plus,
|
||||
Trash2,
|
||||
Loader2,
|
||||
ArrowRight,
|
||||
ShieldCheck,
|
||||
Truck,
|
||||
CheckCircle2,
|
||||
} from "lucide-react"
|
||||
|
||||
const countItems = (cart?: HttpTypes.StoreCart | null) =>
|
||||
cart?.items?.reduce((acc, item) => acc + item.quantity, 0) || 0
|
||||
|
||||
// Komponenta za pojedinačni artikal u korpi sa +/- i brisanjem
|
||||
function CartDrawerItem({
|
||||
item,
|
||||
currencyCode,
|
||||
}: {
|
||||
item: HttpTypes.StoreCartLineItem
|
||||
currencyCode: string
|
||||
}) {
|
||||
const [isUpdating, setIsUpdating] = useState(false)
|
||||
const [isDeleting, setIsDeleting] = useState(false)
|
||||
|
||||
const handleUpdate = async (newQty: number) => {
|
||||
if (newQty < 1 || isUpdating) return
|
||||
setIsUpdating(true)
|
||||
try {
|
||||
await updateLineItem({ lineId: item.id, quantity: newQty })
|
||||
notifyCartUpdated()
|
||||
} catch (_err) {
|
||||
// ignore
|
||||
} finally {
|
||||
setIsUpdating(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (isDeleting) return
|
||||
setIsDeleting(true)
|
||||
try {
|
||||
await deleteLineItem(item.id)
|
||||
notifyCartUpdated()
|
||||
} catch (_err) {
|
||||
setIsDeleting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex gap-3 py-3 border-b border-border/60 last:border-b-0 items-start"
|
||||
data-testid="cart-item"
|
||||
>
|
||||
<LocalizedClientLink
|
||||
href={`/products/${item.product_handle}`}
|
||||
className="w-16 h-16 sm:w-20 sm:h-20 rounded-lg overflow-hidden flex-shrink-0 border border-border bg-muted/20"
|
||||
>
|
||||
<Thumbnail
|
||||
thumbnail={item.thumbnail}
|
||||
images={item.variant?.product?.images}
|
||||
size="square"
|
||||
/>
|
||||
</LocalizedClientLink>
|
||||
|
||||
<div className="flex flex-col flex-1 min-w-0">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<LocalizedClientLink
|
||||
href={`/products/${item.product_handle}`}
|
||||
className="text-sm font-semibold text-foreground hover:text-primary transition-colors line-clamp-1"
|
||||
>
|
||||
{item.title}
|
||||
</LocalizedClientLink>
|
||||
<button
|
||||
onClick={handleDelete}
|
||||
disabled={isDeleting || isUpdating}
|
||||
className="text-muted-foreground hover:text-destructive transition-colors p-1 -mt-1 -mr-1 rounded disabled:opacity-40"
|
||||
aria-label="Ukloni artikal"
|
||||
>
|
||||
{isDeleting ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-destructive" />
|
||||
) : (
|
||||
<Trash2 className="h-4 w-4" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-muted-foreground mt-0.5">
|
||||
<LineItemOptions variant={item.variant} />
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between mt-3 pt-1">
|
||||
{/* Stepper količine */}
|
||||
<div className="inline-flex items-center border border-border rounded-md bg-background">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleUpdate(item.quantity - 1)}
|
||||
disabled={isUpdating || item.quantity <= 1}
|
||||
className="h-7 w-7 flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors disabled:opacity-30 disabled:pointer-events-none rounded-l-md"
|
||||
aria-label="Smanji količinu"
|
||||
>
|
||||
<Minus className="h-3 w-3" />
|
||||
</button>
|
||||
<span className="w-8 text-center text-xs font-semibold tabular-nums">
|
||||
{isUpdating ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin mx-auto text-primary" />
|
||||
) : (
|
||||
item.quantity
|
||||
)}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleUpdate(item.quantity + 1)}
|
||||
disabled={isUpdating}
|
||||
className="h-7 w-7 flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors disabled:opacity-30 disabled:pointer-events-none rounded-r-md"
|
||||
aria-label="Povećaj količinu"
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Cijena stavke */}
|
||||
<div className="text-right">
|
||||
<LineItemPrice
|
||||
item={item}
|
||||
style="tight"
|
||||
currencyCode={currencyCode}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function CartDropdown({
|
||||
cart: serverCart,
|
||||
}: {
|
||||
cart?: HttpTypes.StoreCart | null
|
||||
}) {
|
||||
const [clientCart, setClientCart] = useState<HttpTypes.StoreCart | null>(null)
|
||||
const cartState = clientCart ?? serverCart
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const pathname = usePathname()
|
||||
|
||||
const totalItems = countItems(cartState)
|
||||
const subtotal = cartState?.subtotal ?? 0
|
||||
const prevItemsCount = useRef<number>(totalItems || 0)
|
||||
|
||||
// Osvježavanje korpe na klijentu prilikom CART_UPDATED_EVENT događaja
|
||||
useEffect(() => {
|
||||
const handleCartUpdate = () => {
|
||||
retrieveCart()
|
||||
.then((freshCart) => {
|
||||
setClientCart(freshCart)
|
||||
// Ako smo na stranici proizvoda, automatski otvori drawer da potvrdi unos
|
||||
if (!pathname.includes("/cart") && !pathname.includes("/checkout")) {
|
||||
setIsOpen(true)
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
window.addEventListener(CART_UPDATED_EVENT, handleCartUpdate)
|
||||
return () => window.removeEventListener(CART_UPDATED_EVENT, handleCartUpdate)
|
||||
}, [pathname])
|
||||
|
||||
// PDV specifikacija za BiH (17% uračunat u maloprodajnu cijenu)
|
||||
const taxAmount = (subtotal * 17) / 117
|
||||
const baseAmount = subtotal - taxAmount
|
||||
|
||||
return (
|
||||
<Sheet open={isOpen} onOpenChange={setIsOpen}>
|
||||
{/* Okidač: dugme korpe u navigaciji */}
|
||||
<SheetTrigger asChild>
|
||||
<button
|
||||
className="relative inline-flex items-center gap-2 h-9 px-3 rounded-md text-sm font-medium text-primary-foreground/90 hover:text-white hover:bg-white/10 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
data-testid="nav-cart-link"
|
||||
aria-label={`Korpa sa ${totalItems} artikala`}
|
||||
>
|
||||
<ShoppingBag className="h-4 w-4" />
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="px-1.5 py-0 h-5 text-xs font-semibold bg-[#F8D912] text-[#012555] hover:bg-[#F8D912]"
|
||||
aria-live="polite"
|
||||
>
|
||||
{totalItems}
|
||||
</Badge>
|
||||
</button>
|
||||
</SheetTrigger>
|
||||
|
||||
{/* Slide-in Drawer sa desne strane */}
|
||||
<SheetContent
|
||||
side="right"
|
||||
className="w-full sm:max-w-md p-0 flex flex-col h-full bg-background border-l border-border"
|
||||
data-testid="nav-cart-drawer"
|
||||
>
|
||||
{/* Drawer Header */}
|
||||
<SheetHeader className="px-5 py-4 border-b border-border text-left">
|
||||
<div className="flex items-center justify-between">
|
||||
<SheetTitle className="text-base sm:text-lg font-bold flex items-center gap-2 text-foreground">
|
||||
<ShoppingBag className="h-5 w-5 text-primary" />
|
||||
Vaša Korpa
|
||||
<span className="text-xs font-normal text-muted-foreground ml-1">
|
||||
({totalItems} {totalItems === 1 ? "artikal" : "artikala"})
|
||||
</span>
|
||||
</SheetTitle>
|
||||
</div>
|
||||
{/* Brzi benefit banner */}
|
||||
<div className="mt-2 text-xs bg-muted/50 rounded-lg p-2.5 flex items-center gap-2 text-foreground/80">
|
||||
<Truck className="h-4 w-4 text-primary flex-shrink-0" />
|
||||
<span>
|
||||
Brza dostava <strong>24/48h širom BiH</strong> | Preuzimanje u Gračanici
|
||||
</span>
|
||||
</div>
|
||||
</SheetHeader>
|
||||
|
||||
{/* Drawer Body */}
|
||||
<div className="flex-1 overflow-y-auto px-5 py-3">
|
||||
{cartState && cartState.items && cartState.items.length > 0 ? (
|
||||
<div className="flex flex-col">
|
||||
{cartState.items
|
||||
.sort((a, b) => ((a.created_at ?? "") > (b.created_at ?? "") ? -1 : 1))
|
||||
.map((item) => (
|
||||
<CartDrawerItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
currencyCode={cartState.currency_code}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Preporučeni dodaci (Cross-sell za suncobrane) */}
|
||||
<div className="mt-6 pt-4 border-t border-border">
|
||||
<span className="text-xs font-bold uppercase tracking-wider text-muted-foreground block mb-2.5">
|
||||
Preporučena dodatna oprema:
|
||||
</span>
|
||||
<div className="rounded-xl border border-border bg-muted/20 p-3 flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
<div className="h-10 w-10 rounded-md bg-card border border-border flex items-center justify-center text-primary flex-shrink-0">
|
||||
<ShieldCheck className="h-5 w-5" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-semibold text-foreground truncate">
|
||||
Zaštitna navlaka sa zipom
|
||||
</p>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
Štiti platno od kiše i smoga van sezone
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<LocalizedClientLink
|
||||
href="/store"
|
||||
onClick={() => setIsOpen(false)}
|
||||
className="flex-shrink-0 text-xs font-semibold text-primary hover:underline"
|
||||
>
|
||||
Vidi baze & opremu
|
||||
</LocalizedClientLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center justify-center h-full py-12 text-center gap-3">
|
||||
<div className="h-14 w-14 rounded-full bg-muted flex items-center justify-center text-muted-foreground">
|
||||
<ShoppingBag className="h-7 w-7 stroke-1" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 max-w-[260px]">
|
||||
<h4 className="text-base font-bold text-foreground">
|
||||
Vaša korpa je prazna
|
||||
</h4>
|
||||
<p className="text-xs text-muted-foreground leading-relaxed">
|
||||
Istražite našu ponudu profesionalnih suncobrana, pergola i tendi.
|
||||
</p>
|
||||
</div>
|
||||
<LocalizedClientLink href="/store" className="mt-3">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="default"
|
||||
onClick={() => setIsOpen(false)}
|
||||
className="bg-primary text-white"
|
||||
>
|
||||
Istražite Proizvode
|
||||
</Button>
|
||||
</LocalizedClientLink>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Drawer Footer (Sticky at bottom) */}
|
||||
{cartState && cartState.items && cartState.items.length > 0 && (
|
||||
<div className="px-5 py-4 border-t border-border bg-muted/10 flex flex-col gap-3">
|
||||
{/* Specifikacija cijena sa 17% PDV */}
|
||||
<div className="flex flex-col gap-1 text-xs">
|
||||
<div className="flex justify-between text-muted-foreground">
|
||||
<span>Osnovica bez PDV-a:</span>
|
||||
<span>
|
||||
{convertToLocale({
|
||||
amount: baseAmount,
|
||||
currency_code: cartState.currency_code,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-muted-foreground">
|
||||
<span>PDV (17%):</span>
|
||||
<span>
|
||||
{convertToLocale({
|
||||
amount: taxAmount,
|
||||
currency_code: cartState.currency_code,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<Separator className="my-1" />
|
||||
<div className="flex justify-between text-sm font-bold text-foreground">
|
||||
<span>Ukupno za uplatu:</span>
|
||||
<span className="text-base text-primary">
|
||||
{convertToLocale({
|
||||
amount: subtotal,
|
||||
currency_code: cartState.currency_code,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 text-[11px] text-muted-foreground pt-0.5">
|
||||
<CheckCircle2 className="h-3 w-3 text-emerald-600 flex-shrink-0" />
|
||||
<span>U cijene je uračunat PDV 17% (B2B R1 račun)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dugmad za akciju */}
|
||||
<div className="flex flex-col gap-2 pt-1">
|
||||
<LocalizedClientLink href="/checkout" className="w-full" onClick={() => setIsOpen(false)}>
|
||||
<Button className="w-full h-11 text-sm font-bold bg-[#012555] hover:bg-[#023377] text-white shadow-sm flex items-center justify-center gap-2">
|
||||
Nastavite na Plaćanje
|
||||
<ArrowRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</LocalizedClientLink>
|
||||
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<LocalizedClientLink
|
||||
href="/cart"
|
||||
className="w-full"
|
||||
onClick={() => setIsOpen(false)}
|
||||
>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full text-xs font-medium border-border"
|
||||
>
|
||||
Pregledaj punu korpu
|
||||
</Button>
|
||||
</LocalizedClientLink>
|
||||
<SheetClose asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
Nastavi kupovinu
|
||||
</Button>
|
||||
</SheetClose>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
"use client"
|
||||
|
||||
import { transferCart } from "@lib/data/customer"
|
||||
import { AlertCircle as ExclamationCircleSolid } from "lucide-react"
|
||||
import { StoreCart, StoreCustomer } from "@medusajs/types"
|
||||
import { Button } from "@modules/common/components/ui"
|
||||
import { useState } from "react"
|
||||
function CartMismatchBanner(props: {
|
||||
customer: StoreCustomer
|
||||
cart: StoreCart
|
||||
}) {
|
||||
const { customer, cart } = props
|
||||
const [isPending, setIsPending] = useState(false)
|
||||
const [actionText, setActionText] = useState("Run transfer again")
|
||||
|
||||
if (!customer || !!cart.customer_id) {
|
||||
return
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
setIsPending(true)
|
||||
setActionText("Transferring..")
|
||||
|
||||
await transferCart()
|
||||
} catch {
|
||||
setActionText("Run transfer again")
|
||||
setIsPending(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center small:p-4 p-2 text-center bg-orange-300 small:gap-2 gap-1 text-sm mt-2 text-orange-800">
|
||||
<div className="flex flex-col small:flex-row small:gap-2 gap-1 items-center">
|
||||
<span className="flex items-center gap-1">
|
||||
<ExclamationCircleSolid className="inline" />
|
||||
Something went wrong when we tried to transfer your cart
|
||||
</span>
|
||||
|
||||
<span>·</span>
|
||||
|
||||
<Button
|
||||
variant="transparent"
|
||||
className="hover:bg-transparent active:bg-transparent focus:bg-transparent disabled:text-orange-500 text-orange-950 p-0 bg-transparent"
|
||||
size="medium"
|
||||
disabled={isPending}
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
{actionText}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CartMismatchBanner
|
||||
@@ -0,0 +1,131 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
Listbox,
|
||||
ListboxButton,
|
||||
ListboxOption,
|
||||
ListboxOptions,
|
||||
Transition,
|
||||
} from "@headlessui/react"
|
||||
import { Fragment, useEffect, useMemo, useState } from "react"
|
||||
import ReactCountryFlag from "react-country-flag"
|
||||
|
||||
import { StateType } from "@lib/hooks/use-toggle-state"
|
||||
import { useParams, usePathname } from "next/navigation"
|
||||
import { updateRegion } from "@lib/data/cart"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
type CountryOption = {
|
||||
country: string
|
||||
region: string
|
||||
label: string
|
||||
}
|
||||
|
||||
type CountrySelectProps = {
|
||||
toggleState: StateType
|
||||
regions: HttpTypes.StoreRegion[]
|
||||
}
|
||||
|
||||
const CountrySelect = ({ toggleState, regions }: CountrySelectProps) => {
|
||||
const [current, setCurrent] = useState<CountryOption | undefined>(undefined)
|
||||
|
||||
const { countryCode } = useParams()
|
||||
const currentPath = usePathname().split(`/${countryCode}`)[1]
|
||||
|
||||
const { state, close } = toggleState
|
||||
|
||||
const options = useMemo(() => {
|
||||
return regions
|
||||
?.map((r) => {
|
||||
return r.countries?.map((c) => ({
|
||||
country: c.iso_2 ?? "",
|
||||
region: r.id,
|
||||
label: c.display_name ?? "",
|
||||
}))
|
||||
})
|
||||
.flat()
|
||||
.filter((o): o is CountryOption => !!o)
|
||||
.sort((a, b) => a.label.localeCompare(b.label))
|
||||
}, [regions])
|
||||
|
||||
useEffect(() => {
|
||||
if (countryCode) {
|
||||
const option = options?.find((o) => o?.country === countryCode)
|
||||
setCurrent(option)
|
||||
}
|
||||
}, [options, countryCode])
|
||||
|
||||
const handleChange = (option: CountryOption) => {
|
||||
updateRegion(option.country, currentPath)
|
||||
close()
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Listbox
|
||||
as="span"
|
||||
onChange={handleChange}
|
||||
defaultValue={
|
||||
countryCode
|
||||
? options?.find((o) => o?.country === countryCode)
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<ListboxButton className="py-1 w-full">
|
||||
<div className="txt-compact-small flex items-start gap-x-2">
|
||||
<span>Shipping to:</span>
|
||||
{current && (
|
||||
<span className="txt-compact-small flex items-center gap-x-2">
|
||||
<ReactCountryFlag
|
||||
svg
|
||||
style={{
|
||||
width: "16px",
|
||||
height: "16px",
|
||||
}}
|
||||
countryCode={current.country ?? ""}
|
||||
/>
|
||||
{current.label}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</ListboxButton>
|
||||
<div className="flex relative w-full min-w-[320px]">
|
||||
<Transition
|
||||
show={state}
|
||||
as={Fragment}
|
||||
leave="transition ease-in duration-150"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<ListboxOptions
|
||||
className="absolute -bottom-[calc(100%-36px)] left-0 xsmall:left-auto xsmall:right-0 max-h-[442px] overflow-y-scroll z-[900] bg-white drop-shadow-md text-small-regular uppercase text-black no-scrollbar rounded-rounded w-full"
|
||||
static
|
||||
>
|
||||
{options?.map((o, index) => {
|
||||
return (
|
||||
<ListboxOption
|
||||
key={index}
|
||||
value={o}
|
||||
className="py-2 hover:bg-gray-200 px-3 cursor-pointer flex items-center gap-x-2"
|
||||
>
|
||||
<ReactCountryFlag
|
||||
svg
|
||||
style={{
|
||||
width: "16px",
|
||||
height: "16px",
|
||||
}}
|
||||
countryCode={o?.country ?? ""}
|
||||
/>{" "}
|
||||
{o?.label}
|
||||
</ListboxOption>
|
||||
)
|
||||
})}
|
||||
</ListboxOptions>
|
||||
</Transition>
|
||||
</div>
|
||||
</Listbox>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CountrySelect
|
||||
@@ -0,0 +1,192 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
Listbox,
|
||||
ListboxButton,
|
||||
ListboxOption,
|
||||
ListboxOptions,
|
||||
Transition,
|
||||
} from "@headlessui/react"
|
||||
import { Fragment, useEffect, useMemo, useState, useTransition } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import ReactCountryFlag from "react-country-flag"
|
||||
|
||||
import { StateType } from "@lib/hooks/use-toggle-state"
|
||||
import { updateLocale } from "@lib/data/locale-actions"
|
||||
import { Locale } from "@lib/data/locales"
|
||||
|
||||
type LanguageOption = {
|
||||
code: string
|
||||
name: string
|
||||
localizedName: string
|
||||
countryCode: string
|
||||
}
|
||||
|
||||
const getCountryCodeFromLocale = (localeCode: string): string => {
|
||||
try {
|
||||
const locale = new Intl.Locale(localeCode)
|
||||
if (locale.region) {
|
||||
return locale.region.toUpperCase()
|
||||
}
|
||||
const maximized = locale.maximize()
|
||||
return maximized.region?.toUpperCase() ?? localeCode.toUpperCase()
|
||||
} catch {
|
||||
const parts = localeCode.split(/[-_]/)
|
||||
return parts.length > 1 ? parts[1].toUpperCase() : parts[0].toUpperCase()
|
||||
}
|
||||
}
|
||||
|
||||
type LanguageSelectProps = {
|
||||
toggleState: StateType
|
||||
locales: Locale[]
|
||||
currentLocale: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the localized display name for a language code using Intl API.
|
||||
* Falls back to the provided name if Intl is unavailable.
|
||||
*/
|
||||
const getLocalizedLanguageName = (
|
||||
code: string,
|
||||
fallbackName: string,
|
||||
displayLocale: string = "en-US"
|
||||
): string => {
|
||||
try {
|
||||
const displayNames = new Intl.DisplayNames([displayLocale], {
|
||||
type: "language",
|
||||
})
|
||||
return displayNames.of(code) ?? fallbackName
|
||||
} catch {
|
||||
return fallbackName
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_OPTION: LanguageOption = {
|
||||
code: "",
|
||||
name: "Default",
|
||||
localizedName: "Default",
|
||||
countryCode: "",
|
||||
}
|
||||
|
||||
const LanguageSelect = ({
|
||||
toggleState,
|
||||
locales,
|
||||
currentLocale,
|
||||
}: LanguageSelectProps) => {
|
||||
const [current, setCurrent] = useState<LanguageOption | undefined>(undefined)
|
||||
const [isPending, startTransition] = useTransition()
|
||||
const router = useRouter()
|
||||
|
||||
const { state, close } = toggleState
|
||||
|
||||
const options = useMemo(() => {
|
||||
const localeOptions = locales.map((locale) => ({
|
||||
code: locale.code,
|
||||
name: locale.name,
|
||||
localizedName: getLocalizedLanguageName(
|
||||
locale.code,
|
||||
locale.name,
|
||||
currentLocale ?? "en-US"
|
||||
),
|
||||
countryCode: getCountryCodeFromLocale(locale.code),
|
||||
}))
|
||||
return [DEFAULT_OPTION, ...localeOptions]
|
||||
}, [locales, currentLocale])
|
||||
|
||||
useEffect(() => {
|
||||
if (currentLocale) {
|
||||
const option = options.find(
|
||||
(o) => o.code.toLowerCase() === currentLocale.toLowerCase()
|
||||
)
|
||||
setCurrent(option ?? DEFAULT_OPTION)
|
||||
} else {
|
||||
setCurrent(DEFAULT_OPTION)
|
||||
}
|
||||
}, [options, currentLocale])
|
||||
|
||||
const handleChange = (option: LanguageOption) => {
|
||||
startTransition(async () => {
|
||||
await updateLocale(option.code)
|
||||
close()
|
||||
router.refresh()
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Listbox
|
||||
as="span"
|
||||
onChange={handleChange}
|
||||
defaultValue={
|
||||
currentLocale
|
||||
? options.find(
|
||||
(o) => o.code.toLowerCase() === currentLocale.toLowerCase()
|
||||
) ?? DEFAULT_OPTION
|
||||
: DEFAULT_OPTION
|
||||
}
|
||||
disabled={isPending}
|
||||
>
|
||||
<ListboxButton className="py-1 w-full">
|
||||
<div className="txt-compact-small flex items-start gap-x-2">
|
||||
<span>Language:</span>
|
||||
{current && (
|
||||
<span className="txt-compact-small flex items-center gap-x-2">
|
||||
{current.countryCode && (
|
||||
/* @ts-ignore */
|
||||
<ReactCountryFlag
|
||||
svg
|
||||
style={{
|
||||
width: "16px",
|
||||
height: "16px",
|
||||
}}
|
||||
countryCode={current.countryCode}
|
||||
/>
|
||||
)}
|
||||
{isPending ? "..." : current.localizedName}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</ListboxButton>
|
||||
<div className="flex relative w-full min-w-[320px]">
|
||||
<Transition
|
||||
show={state}
|
||||
as={Fragment}
|
||||
leave="transition ease-in duration-150"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<ListboxOptions
|
||||
className="absolute -bottom-[calc(100%-36px)] left-0 xsmall:left-auto xsmall:right-0 max-h-[442px] overflow-y-scroll z-[900] bg-white drop-shadow-md text-small-regular uppercase text-black no-scrollbar rounded-rounded w-full"
|
||||
static
|
||||
>
|
||||
{options.map((o) => (
|
||||
<ListboxOption
|
||||
key={o.code || "default"}
|
||||
value={o}
|
||||
className="py-2 hover:bg-gray-200 px-3 cursor-pointer flex items-center gap-x-2"
|
||||
>
|
||||
{o.countryCode ? (
|
||||
/* @ts-ignore */
|
||||
<ReactCountryFlag
|
||||
svg
|
||||
style={{
|
||||
width: "16px",
|
||||
height: "16px",
|
||||
}}
|
||||
countryCode={o.countryCode}
|
||||
/>
|
||||
) : (
|
||||
<span style={{ width: "16px", height: "16px" }} />
|
||||
)}
|
||||
{o.localizedName}
|
||||
</ListboxOption>
|
||||
))}
|
||||
</ListboxOptions>
|
||||
</Transition>
|
||||
</div>
|
||||
</Listbox>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LanguageSelect
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Text } from "@modules/common/components/ui"
|
||||
|
||||
import Medusa from "../../../common/icons/medusa"
|
||||
import NextJs from "../../../common/icons/nextjs"
|
||||
|
||||
const MedusaCTA = () => {
|
||||
return (
|
||||
<Text className="flex gap-x-2 txt-compact-small-plus items-center">
|
||||
Powered by
|
||||
<a href="https://www.medusajs.com" target="_blank" rel="noreferrer">
|
||||
<Medusa fill="#9ca3af" className="fill-[#9ca3af]" />
|
||||
</a>
|
||||
&
|
||||
<a href="https://nextjs.org" target="_blank" rel="noreferrer">
|
||||
<NextJs fill="#9ca3af" />
|
||||
</a>
|
||||
</Text>
|
||||
)
|
||||
}
|
||||
|
||||
export default MedusaCTA
|
||||
@@ -0,0 +1,70 @@
|
||||
"use client"
|
||||
|
||||
import { Dialog, Transition } from "@headlessui/react"
|
||||
import { X } from "lucide-react"
|
||||
import React, { Fragment } from "react"
|
||||
|
||||
type SearchDrawerProps = {
|
||||
isOpen: boolean
|
||||
close: () => void
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
const SearchDrawer = ({ isOpen, close, children }: SearchDrawerProps) => {
|
||||
return (
|
||||
<Transition appear show={isOpen} as={Fragment}>
|
||||
<Dialog as="div" className="relative z-[75]" onClose={close}>
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm" />
|
||||
</Transition.Child>
|
||||
|
||||
<div className="fixed inset-0 overflow-hidden">
|
||||
<div className="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10">
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="transform transition ease-in-out duration-300"
|
||||
enterFrom="translate-x-full"
|
||||
enterTo="translate-x-0"
|
||||
leave="transform transition ease-in-out duration-200"
|
||||
leaveFrom="translate-x-0"
|
||||
leaveTo="translate-x-full"
|
||||
>
|
||||
<Dialog.Panel
|
||||
className="pointer-events-auto w-screen max-w-md"
|
||||
data-testid="search-drawer"
|
||||
>
|
||||
<div className="flex h-full flex-col border-l border-border bg-background shadow-2xl">
|
||||
<div className="flex items-center justify-between border-b border-border px-5 py-4">
|
||||
<Dialog.Title className="text-base font-semibold text-foreground">
|
||||
Pretraga Suman Asortimana
|
||||
</Dialog.Title>
|
||||
<button
|
||||
type="button"
|
||||
onClick={close}
|
||||
aria-label="Zatvori pretragu"
|
||||
className="text-muted-foreground hover:text-foreground transition-colors p-1"
|
||||
data-testid="close-search-drawer"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
</Dialog.Panel>
|
||||
</Transition.Child>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
)
|
||||
}
|
||||
|
||||
export default SearchDrawer
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client"
|
||||
|
||||
import Image from "next/image"
|
||||
import type { Hit as HitType } from "instantsearch.js"
|
||||
|
||||
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
||||
import { ImageIcon } from "lucide-react"
|
||||
|
||||
export type ProductHit = HitType<{
|
||||
title: string | null
|
||||
handle: string | null
|
||||
thumbnail: string | null
|
||||
}>
|
||||
|
||||
type SearchHitProps = {
|
||||
hit: ProductHit
|
||||
onNavigate?: () => void
|
||||
}
|
||||
|
||||
const SearchHit = ({ hit, onNavigate }: SearchHitProps) => {
|
||||
if (!hit.handle) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<li>
|
||||
<LocalizedClientLink
|
||||
href={`/products/${hit.handle}`}
|
||||
onClick={onNavigate}
|
||||
className="flex items-center gap-3.5 px-3 py-2.5 rounded-lg hover:bg-accent transition-colors"
|
||||
data-testid="search-hit-link"
|
||||
>
|
||||
<div className="relative h-14 w-14 shrink-0 overflow-hidden rounded-md border border-border bg-muted/30">
|
||||
{hit.thumbnail ? (
|
||||
<Image
|
||||
src={hit.thumbnail}
|
||||
alt={hit.title ?? ""}
|
||||
fill
|
||||
sizes="56px"
|
||||
className="object-contain p-1"
|
||||
draggable={false}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center text-muted-foreground/60">
|
||||
<ImageIcon className="h-5 w-5" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-sm font-medium text-foreground line-clamp-2">
|
||||
{hit.title}
|
||||
</span>
|
||||
</LocalizedClientLink>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
export default SearchHit
|
||||
150
apps/suman-bosna/src/modules/layout/components/search/index.tsx
Normal file
150
apps/suman-bosna/src/modules/layout/components/search/index.tsx
Normal file
@@ -0,0 +1,150 @@
|
||||
"use client"
|
||||
|
||||
import { Search as SearchIcon } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { useParams } from "next/navigation"
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
import type { SearchClient } from "instantsearch.js"
|
||||
import {
|
||||
Configure,
|
||||
InstantSearch,
|
||||
useHits,
|
||||
useInstantSearch,
|
||||
useSearchBox,
|
||||
} from "react-instantsearch"
|
||||
|
||||
import useSearchSettled from "@lib/hooks/use-search-settled"
|
||||
import useToggleState from "@lib/hooks/use-toggle-state"
|
||||
import { PRODUCT_INDEX_NAME, searchClient } from "@lib/search-client"
|
||||
import SearchDrawer from "./drawer"
|
||||
import SearchHit, { ProductHit } from "./hit"
|
||||
|
||||
const HITS_PER_PAGE = 12
|
||||
const DEBOUNCE_MS = 250
|
||||
|
||||
const SearchPanel = ({ onNavigate }: { onNavigate: () => void }) => {
|
||||
const timer = useRef<number | undefined>(undefined)
|
||||
|
||||
const queryHook = useCallback(
|
||||
(nextQuery: string, search: (value: string) => void) => {
|
||||
window.clearTimeout(timer.current)
|
||||
timer.current = window.setTimeout(() => search(nextQuery), DEBOUNCE_MS)
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
const { query, refine } = useSearchBox({ queryHook })
|
||||
const { items } = useHits<ProductHit>()
|
||||
const { status, error } = useInstantSearch()
|
||||
const { isSettled } = useSearchSettled()
|
||||
|
||||
const [inputValue, setInputValue] = useState(query)
|
||||
|
||||
useEffect(() => () => window.clearTimeout(timer.current), [])
|
||||
|
||||
const hasInput = Boolean(inputValue.trim())
|
||||
const isPending = inputValue.trim() !== query.trim()
|
||||
const hasResults = Boolean(query.trim()) && items.length > 0
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center gap-x-3 border-b border-border px-5 py-2">
|
||||
<SearchIcon className="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
<input
|
||||
type="search"
|
||||
value={inputValue}
|
||||
onChange={(event) => {
|
||||
setInputValue(event.target.value)
|
||||
refine(event.target.value)
|
||||
}}
|
||||
placeholder="Unesite pojam za pretragu..."
|
||||
aria-label="Pretraži proizvode"
|
||||
autoFocus
|
||||
className="w-full bg-transparent py-3 text-sm text-foreground outline-none placeholder:text-muted-foreground"
|
||||
data-testid="search-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-4">
|
||||
{!hasInput ? (
|
||||
<p
|
||||
className="py-12 text-center text-sm text-muted-foreground"
|
||||
data-testid="search-empty"
|
||||
>
|
||||
Počnite tipkati da pretražite suncobrane, pergole i dodatke.
|
||||
</p>
|
||||
) : status === "error" ? (
|
||||
<p
|
||||
className="py-12 text-center text-sm text-destructive"
|
||||
data-testid="search-error"
|
||||
>
|
||||
Greška pri pretrazi
|
||||
{error?.message ? `: ${error.message}` : "."}
|
||||
</p>
|
||||
) : !isSettled ? (
|
||||
<p
|
||||
className="py-12 text-center text-sm text-muted-foreground"
|
||||
data-testid="search-loading"
|
||||
>
|
||||
Pretražujem…
|
||||
</p>
|
||||
) : hasResults ? (
|
||||
<ul className="divide-y divide-border/60" data-testid="search-results">
|
||||
{items.map((hit) => (
|
||||
<SearchHit key={hit.objectID} hit={hit} onNavigate={onNavigate} />
|
||||
))}
|
||||
</ul>
|
||||
) : isPending || !query.trim() ? (
|
||||
<p
|
||||
className="py-12 text-center text-sm text-muted-foreground"
|
||||
data-testid="search-loading"
|
||||
>
|
||||
Pretražujem…
|
||||
</p>
|
||||
) : (
|
||||
<p
|
||||
className="py-12 text-center text-sm text-muted-foreground"
|
||||
data-testid="search-no-results"
|
||||
>
|
||||
Nema rezultata za upit "{query}"
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const Search = () => {
|
||||
const { state: isOpen, open, close } = useToggleState()
|
||||
const { countryCode } = useParams<{ countryCode: string }>()
|
||||
|
||||
return (
|
||||
<>
|
||||
<Link
|
||||
href={`/${countryCode}/search`}
|
||||
onClick={(event) => {
|
||||
event.preventDefault()
|
||||
open()
|
||||
}}
|
||||
aria-label="Pretraga"
|
||||
className="inline-flex items-center justify-center h-9 w-9 rounded-md text-primary-foreground/90 hover:text-white hover:bg-white/10 transition-colors"
|
||||
data-testid="nav-search-button"
|
||||
>
|
||||
<SearchIcon className="h-4 w-4" />
|
||||
</Link>
|
||||
|
||||
<SearchDrawer isOpen={isOpen} close={close}>
|
||||
<InstantSearch
|
||||
indexName={PRODUCT_INDEX_NAME}
|
||||
searchClient={searchClient as unknown as SearchClient}
|
||||
future={{ preserveSharedStateOnUnmount: true }}
|
||||
>
|
||||
<Configure hitsPerPage={HITS_PER_PAGE} />
|
||||
<SearchPanel onNavigate={close} />
|
||||
</InstantSearch>
|
||||
</SearchDrawer>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Search
|
||||
@@ -0,0 +1,108 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Locale } from "@lib/data/locales"
|
||||
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
||||
import CountrySelect from "../country-select"
|
||||
import LanguageSelect from "../language-select"
|
||||
import useToggleState from "@lib/hooks/use-toggle-state"
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
SheetTrigger,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Menu, ChevronRight } from "lucide-react"
|
||||
import navigationConfig from "@/config/navigation.json"
|
||||
|
||||
type SideMenuProps = {
|
||||
regions: HttpTypes.StoreRegion[] | null
|
||||
locales: Locale[] | null
|
||||
currentLocale: string | null
|
||||
}
|
||||
|
||||
const SideMenu = ({ regions, locales, currentLocale }: SideMenuProps) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
const countryToggleState = useToggleState()
|
||||
const languageToggleState = useToggleState()
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
<SheetTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-9 w-9 text-primary-foreground/90 hover:text-white hover:bg-white/10"
|
||||
aria-label="Otvori navigaciju"
|
||||
data-testid="nav-menu-button"
|
||||
>
|
||||
<Menu className="h-5 w-5" />
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="right" className="w-[300px] sm:w-[360px] flex flex-col justify-between p-6">
|
||||
<div className="flex flex-col gap-6">
|
||||
<SheetHeader className="text-left space-y-1">
|
||||
<SheetTitle className="text-xl font-bold tracking-tight text-foreground flex items-center gap-2">
|
||||
<span>{navigationConfig.brand.name}</span>
|
||||
{navigationConfig.brand.badge ? (
|
||||
<span className="text-xs uppercase tracking-widest font-semibold px-1.5 py-0.5 rounded border border-border bg-muted text-muted-foreground">
|
||||
{navigationConfig.brand.badge}
|
||||
</span>
|
||||
) : null}
|
||||
</SheetTitle>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{navigationConfig.brand.tagline}
|
||||
</p>
|
||||
</SheetHeader>
|
||||
|
||||
<Separator />
|
||||
|
||||
<nav className="flex flex-col gap-1">
|
||||
{navigationConfig.mobileMenu.map((item) => (
|
||||
<LocalizedClientLink
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
onClick={() => setOpen(false)}
|
||||
className="flex items-center justify-between rounded-md px-3 py-2 text-base font-medium text-foreground hover:bg-accent hover:text-accent-foreground transition-colors"
|
||||
>
|
||||
<span>{item.title}</span>
|
||||
<ChevronRight className="h-4 w-4 text-muted-foreground" />
|
||||
</LocalizedClientLink>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4 pt-4 border-t border-border">
|
||||
{!!locales?.length && (
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-muted-foreground">Jezik:</span>
|
||||
<LanguageSelect
|
||||
toggleState={languageToggleState}
|
||||
locales={locales}
|
||||
currentLocale={currentLocale}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{regions && (
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-muted-foreground">Država:</span>
|
||||
<CountrySelect
|
||||
toggleState={countryToggleState}
|
||||
regions={regions}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground pt-2">
|
||||
© {new Date().getFullYear()} {navigationConfig.brand.name} {navigationConfig.brand.badge}. Sva prava zadržana.
|
||||
</p>
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
|
||||
export default SideMenu
|
||||
175
apps/suman-bosna/src/modules/layout/templates/footer/index.tsx
Normal file
175
apps/suman-bosna/src/modules/layout/templates/footer/index.tsx
Normal file
@@ -0,0 +1,175 @@
|
||||
import Image from "next/image"
|
||||
import { Phone, Mail, MapPin, ArrowRight } from "lucide-react"
|
||||
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
||||
import footerConfig from "@/config/footer.json"
|
||||
|
||||
function SocialIcon({ name }: { name: string }) {
|
||||
switch (name.toLowerCase()) {
|
||||
case "instagram":
|
||||
return (
|
||||
<svg className="h-5 w-5 fill-none stroke-current stroke-2" viewBox="0 0 24 24">
|
||||
<rect x="2" y="2" width="20" height="20" rx="5" ry="5" />
|
||||
<path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z" />
|
||||
<circle cx="17.5" cy="6.5" r="1.5" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
)
|
||||
case "facebook":
|
||||
return (
|
||||
<svg className="h-5 w-5 fill-none stroke-current stroke-2" viewBox="0 0 24 24">
|
||||
<path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z" />
|
||||
</svg>
|
||||
)
|
||||
case "x":
|
||||
case "twitter":
|
||||
return (
|
||||
<svg className="h-4.5 w-4.5 fill-current" viewBox="0 0 24 24">
|
||||
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
|
||||
</svg>
|
||||
)
|
||||
case "linkedin":
|
||||
return (
|
||||
<svg className="h-5 w-5 fill-none stroke-current stroke-2" viewBox="0 0 24 24">
|
||||
<path d="M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z" />
|
||||
<rect x="2" y="9" width="4" height="12" />
|
||||
<circle cx="4" cy="4" r="2" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default async function Footer() {
|
||||
const { banner, brand, columns, contact, bottomBar } = footerConfig
|
||||
|
||||
return (
|
||||
<footer className="bg-primary text-primary-foreground w-full pt-14 sm:pt-18 pb-8 border-t border-primary/20">
|
||||
<div className="content-container">
|
||||
{/* Top Banner Card matching user reference image */}
|
||||
<div className="relative rounded-[28px] sm:rounded-[36px] overflow-hidden min-h-[320px] sm:min-h-[380px] lg:min-h-[420px] flex items-center p-8 sm:p-12 lg:p-16 mb-12 sm:mb-16 shadow-2xl group">
|
||||
{/* Background image */}
|
||||
<Image
|
||||
src={banner.image}
|
||||
alt={banner.title}
|
||||
fill
|
||||
className="object-cover group-hover:scale-105 transition-transform duration-700 ease-out"
|
||||
sizes="(max-width: 1536px) 100vw, 1536px"
|
||||
/>
|
||||
|
||||
{/* Dark gradient overlay on the left */}
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-black/85 via-black/55 to-transparent" />
|
||||
<div className="absolute inset-0 bg-black/20" />
|
||||
|
||||
{/* Banner content */}
|
||||
<div className="relative z-10 max-w-lg sm:max-w-xl space-y-4">
|
||||
<h2 className="text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight text-white leading-[1.15]">
|
||||
{banner.title}
|
||||
</h2>
|
||||
<p className="text-sm sm:text-base text-white/85 leading-relaxed">
|
||||
{banner.subtitle}
|
||||
</p>
|
||||
<div className="pt-2">
|
||||
<LocalizedClientLink
|
||||
href={banner.cta.href}
|
||||
className="group/btn inline-flex items-center gap-3.5 pl-6 pr-1.5 py-1.5 rounded-full bg-[#012555] hover:bg-[#001736] text-white border border-white/15 shadow-xl transition-all duration-300 hover:scale-105"
|
||||
>
|
||||
<span className="font-medium text-sm text-white tracking-wide">
|
||||
{banner.cta.label}
|
||||
</span>
|
||||
<div className="h-9 w-9 rounded-full bg-white text-primary flex items-center justify-center transition-transform duration-300 group-hover/btn:translate-x-0.5 shadow-sm">
|
||||
<ArrowRight className="h-4 w-4" />
|
||||
</div>
|
||||
</LocalizedClientLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 4-Columns Main Footer Grid matching screenshot */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-10 sm:gap-12 pb-14 sm:pb-16 text-sm">
|
||||
{/* Column 1: Brand description and social media icons */}
|
||||
<div className="space-y-6">
|
||||
<p className="text-white/75 leading-relaxed text-sm max-w-xs">
|
||||
{brand.description}
|
||||
</p>
|
||||
<div className="flex items-center gap-5 text-white/70">
|
||||
{brand.socials.map((social) => (
|
||||
<a
|
||||
key={social.name}
|
||||
href={social.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="hover:text-secondary transition-colors"
|
||||
aria-label={social.name}
|
||||
>
|
||||
<SocialIcon name={social.name} />
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Column 2 & 3: Configurable Navigation Columns */}
|
||||
{columns.map((col, idx) => (
|
||||
<div key={idx} className="space-y-4">
|
||||
<h3 className="font-semibold text-base text-white tracking-tight">
|
||||
{col.title}
|
||||
</h3>
|
||||
<ul className="space-y-2.5 text-white/75">
|
||||
{col.links.map((link) => (
|
||||
<li key={link.href}>
|
||||
<LocalizedClientLink
|
||||
href={link.href}
|
||||
className="hover:text-secondary hover:translate-x-0.5 inline-block transition-all"
|
||||
>
|
||||
{link.title}
|
||||
</LocalizedClientLink>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Column 4: Contact details with icons */}
|
||||
<div className="space-y-4">
|
||||
<h3 className="font-semibold text-base text-white tracking-tight">
|
||||
{contact.title}
|
||||
</h3>
|
||||
<ul className="space-y-3.5 text-white/75">
|
||||
<li className="flex items-center gap-3">
|
||||
<Phone className="h-4 w-4 shrink-0 text-secondary" />
|
||||
<a href={`tel:${contact.phone}`} className="hover:text-white transition-colors">
|
||||
{contact.phone}
|
||||
</a>
|
||||
</li>
|
||||
<li className="flex items-center gap-3">
|
||||
<Mail className="h-4 w-4 shrink-0 text-secondary" />
|
||||
<a href={`mailto:${contact.email}`} className="hover:text-white transition-colors">
|
||||
{contact.email}
|
||||
</a>
|
||||
</li>
|
||||
<li className="flex items-start gap-3">
|
||||
<MapPin className="h-4 w-4 shrink-0 text-secondary mt-0.5" />
|
||||
<span>{contact.address}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom Bar: Copyright & Policy Links */}
|
||||
<div className="pt-8 border-t border-white/10 flex flex-col sm:flex-row items-center justify-between gap-4 text-xs text-white/60">
|
||||
<p>© {new Date().getFullYear()} {bottomBar.copyright}</p>
|
||||
<div className="flex items-center gap-6">
|
||||
{bottomBar.links.map((link) => (
|
||||
<LocalizedClientLink
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className="hover:text-white transition-colors"
|
||||
>
|
||||
{link.title}
|
||||
</LocalizedClientLink>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
)
|
||||
}
|
||||
109
apps/suman-bosna/src/modules/layout/templates/nav/index.tsx
Normal file
109
apps/suman-bosna/src/modules/layout/templates/nav/index.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
import { Suspense } from "react"
|
||||
import { listLocales } from "@lib/data/locales"
|
||||
import { getLocale } from "@lib/data/locale-actions"
|
||||
import { listRegions } from "@lib/data/regions"
|
||||
import { StoreRegion } from "@medusajs/types"
|
||||
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
||||
import CartButton from "@modules/layout/components/cart-button"
|
||||
import Search from "@modules/layout/components/search"
|
||||
import SideMenu from "@modules/layout/components/side-menu"
|
||||
import { User, ShoppingBag } from "lucide-react"
|
||||
import navigationConfig from "@/config/navigation.json"
|
||||
import { Logo } from "@/components/ui/logo"
|
||||
|
||||
interface NavProps {
|
||||
variant?: "floating" | "classic"
|
||||
}
|
||||
|
||||
export default async function Nav({ variant }: NavProps) {
|
||||
const [regions, locales, currentLocale] = await Promise.all([
|
||||
listRegions().then((regions: StoreRegion[]) => regions),
|
||||
listLocales(),
|
||||
getLocale(),
|
||||
])
|
||||
|
||||
const effectiveVariant =
|
||||
variant || (navigationConfig as { headerVersion?: "floating" | "classic" }).headerVersion || "floating"
|
||||
|
||||
const navContent = (
|
||||
<>
|
||||
{/* Left: Brand Logo */}
|
||||
<LocalizedClientLink
|
||||
href="/"
|
||||
className="flex items-center group py-1 shrink-0"
|
||||
data-testid="nav-store-link"
|
||||
>
|
||||
<Logo className="h-8 sm:h-9 md:h-10 w-auto" />
|
||||
</LocalizedClientLink>
|
||||
|
||||
{/* Center: Desktop Navigation Links from navigation.json */}
|
||||
<nav className="hidden md:flex items-center gap-6 lg:gap-8 text-sm font-semibold tracking-wide text-primary-foreground/90">
|
||||
{navigationConfig.desktopNav.map((item) => (
|
||||
<LocalizedClientLink
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className="transition-colors hover:text-secondary py-1"
|
||||
>
|
||||
{item.title}
|
||||
</LocalizedClientLink>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* Right: Search, Account, Cart, Mobile Menu */}
|
||||
<div className="flex items-center gap-2 sm:gap-3">
|
||||
<Search />
|
||||
<LocalizedClientLink
|
||||
href="/account"
|
||||
className="hidden sm:inline-flex items-center justify-center h-9 w-9 rounded-md text-primary-foreground/90 hover:text-white hover:bg-white/10 transition-colors"
|
||||
data-testid="nav-account-link"
|
||||
aria-label="Korisnički račun"
|
||||
>
|
||||
<User className="h-4 w-4" />
|
||||
</LocalizedClientLink>
|
||||
<Suspense
|
||||
fallback={
|
||||
<LocalizedClientLink
|
||||
className="inline-flex items-center gap-2 h-9 px-3 rounded-md text-sm font-medium text-primary-foreground/90 hover:text-white hover:bg-white/10 transition-colors"
|
||||
href="/cart"
|
||||
data-testid="nav-cart-link"
|
||||
>
|
||||
<ShoppingBag className="h-4 w-4" />
|
||||
<span>0</span>
|
||||
</LocalizedClientLink>
|
||||
}
|
||||
>
|
||||
<CartButton />
|
||||
</Suspense>
|
||||
|
||||
{/* Mobile menu trigger - only visible on small screens */}
|
||||
<div className="md:hidden">
|
||||
<SideMenu
|
||||
regions={regions}
|
||||
locales={locales}
|
||||
currentLocale={currentLocale}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
// Version 1: Floating with border radius, detached from top, left, and right
|
||||
if (effectiveVariant === "floating") {
|
||||
return (
|
||||
<div className="sticky top-3 sm:top-5 inset-x-0 z-50 w-full px-3 sm:px-6 lg:px-8 max-w-[1536px] mx-auto pointer-events-none transition-all duration-300">
|
||||
<header className="pointer-events-auto h-16 sm:h-18 px-4 sm:px-7 rounded-2xl sm:rounded-3xl bg-primary/95 backdrop-blur-md text-primary-foreground shadow-2xl border border-white/15 flex items-center justify-between gap-4 transition-all duration-300">
|
||||
{navContent}
|
||||
</header>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Version 2: Classic edge-to-edge full width sticky header
|
||||
return (
|
||||
<div className="sticky top-0 inset-x-0 z-40 bg-primary text-primary-foreground shadow-md border-b border-primary/20">
|
||||
<header className="content-container flex h-16 items-center justify-between gap-4">
|
||||
{navContent}
|
||||
</header>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user