design upgrade

This commit is contained in:
Nermin Karic
2026-11-23 00:59:47 +01:00
parent 9e84140474
commit ada6fd857c
198 changed files with 6626 additions and 2539 deletions

View File

@@ -1,167 +1,96 @@
import { Container } from "@modules/common/components/ui"
import ChevronDown from "@modules/common/icons/chevron-down"
import LocalizedClientLink from "@modules/common/components/localized-client-link"
import { convertToLocale } from "@lib/util/money"
import { HttpTypes } from "@medusajs/types"
import { ArrowRight } from "lucide-react"
type OverviewProps = {
customer: HttpTypes.StoreCustomer | null
orders: HttpTypes.StoreOrder[] | null
}
const formatDate = (value: string | Date) =>
new Date(value).toLocaleDateString("bs-BA", { day: "numeric", month: "long", year: "numeric" })
const Overview = ({ customer, orders }: OverviewProps) => {
const stats = [
{ value: `${getProfileCompletion(customer)}%`, label: "Profil popunjen", href: "/account/profile", testId: "customer-profile-completion" },
{ value: String(customer?.addresses?.length ?? 0), label: "Sačuvane adrese", href: "/account/addresses", testId: "addresses-count" },
{ value: String(orders?.length ?? 0), label: "Narudžbe", href: "/account/orders", testId: "orders-count" },
]
return (
<div data-testid="overview-page-wrapper">
<div className="hidden small:block">
<div className="text-xl-semi flex justify-between items-center mb-4">
<span data-testid="welcome-message" data-value={customer?.first_name}>
Hello {customer?.first_name}
</span>
<span className="text-small-regular text-ui-fg-base">
Signed in as:{" "}
<span
className="font-semibold"
data-testid="customer-email"
data-value={customer?.email}
>
{customer?.email}
</span>
</span>
</div>
<div className="flex flex-col py-8 border-t border-gray-200">
<div className="flex flex-col gap-y-4 h-full col-span-1 row-span-2 flex-1">
<div className="flex items-start gap-x-16 mb-6">
<div className="flex flex-col gap-y-4">
<h3 className="text-large-semi">Profile</h3>
<div className="flex items-end gap-x-2">
<span
className="text-3xl-semi leading-none"
data-testid="customer-profile-completion"
data-value={getProfileCompletion(customer)}
>
{getProfileCompletion(customer)}%
</span>
<span className="uppercase text-base-regular text-ui-fg-subtle">
Completed
</span>
</div>
</div>
<span className="sr-only" data-testid="welcome-message" data-value={customer?.first_name}>
Pozdrav {customer?.first_name}
</span>
<span className="sr-only" data-testid="customer-email" data-value={customer?.email}>
{customer?.email}
</span>
<div className="flex flex-col gap-y-4">
<h3 className="text-large-semi">Addresses</h3>
<div className="flex items-end gap-x-2">
<span
className="text-3xl-semi leading-none"
data-testid="addresses-count"
data-value={customer?.addresses?.length || 0}
>
{customer?.addresses?.length || 0}
</span>
<span className="uppercase text-base-regular text-ui-fg-subtle">
Saved
</span>
</div>
</div>
</div>
<div className="flex flex-col gap-y-4">
<div className="flex items-center gap-x-2">
<h3 className="text-large-semi">Recent orders</h3>
</div>
<ul
className="flex flex-col gap-y-4"
data-testid="orders-wrapper"
>
{orders && orders.length > 0 ? (
orders.slice(0, 5).map((order) => {
return (
<li
key={order.id}
data-testid="order-wrapper"
data-value={order.id}
>
<LocalizedClientLink
href={`/account/orders/details/${order.id}`}
>
<Container className="bg-gray-50 flex justify-between items-center p-4">
<div className="grid grid-cols-3 grid-rows-2 text-small-regular gap-x-4 flex-1">
<span className="font-semibold">Date placed</span>
<span className="font-semibold">
Order number
</span>
<span className="font-semibold">
Total amount
</span>
<span data-testid="order-created-date">
{new Date(order.created_at).toDateString()}
</span>
<span
data-testid="order-id"
data-value={order.display_id}
>
#{order.display_id}
</span>
<span data-testid="order-amount">
{convertToLocale({
amount: order.total,
currency_code: order.currency_code,
})}
</span>
</div>
<button
className="flex items-center justify-between"
data-testid="open-order-button"
>
<span className="sr-only">
Go to order #{order.display_id}
</span>
<ChevronDown className="-rotate-90" />
</button>
</Container>
</LocalizedClientLink>
</li>
)
})
) : (
<span data-testid="no-orders-message">No recent orders</span>
)}
</ul>
</div>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 rounded-2xl border border-border/80 divide-y sm:divide-y-0 sm:divide-x divide-border/80">
{stats.map((s) => (
<LocalizedClientLink key={s.label} href={s.href} className="group flex flex-col justify-between gap-10 p-6 transition-colors hover:bg-muted/60">
<p className="font-display text-5xl text-primary" data-testid={s.testId} data-value={s.value}>
{s.value}
</p>
<p className="flex items-center justify-between text-sm text-muted-foreground">
{s.label}
<ArrowRight className="h-4 w-4 transition-transform group-hover:translate-x-0.5" />
</p>
</LocalizedClientLink>
))}
</div>
<section className="mt-14">
<div className="mb-5 flex items-baseline justify-between">
<h3 className="font-display text-2xl text-foreground">Nedavne narudžbe</h3>
<LocalizedClientLink href="/account/orders" className="text-sm text-primary underline-offset-4 hover:underline">
Sve narudžbe
</LocalizedClientLink>
</div>
<ul className="divide-y divide-border/70 border-y border-border/70" data-testid="orders-wrapper">
{orders && orders.length > 0 ? (
orders.slice(0, 5).map((order) => (
<li key={order.id} data-testid="order-wrapper" data-value={order.id}>
<LocalizedClientLink
href={`/account/orders/details/${order.id}`}
className="group grid grid-cols-[1fr_auto] items-center gap-4 py-4 sm:grid-cols-[120px_1fr_auto_auto]"
data-testid="open-order-button"
>
<span className="text-sm text-foreground" data-testid="order-id" data-value={order.display_id}>
#{order.display_id}
</span>
<span className="hidden text-sm text-muted-foreground sm:block" data-testid="order-created-date">
{formatDate(order.created_at)}
</span>
<span className="text-sm text-foreground tabular-nums" data-testid="order-amount">
{convertToLocale({ amount: order.total, currency_code: order.currency_code })}
</span>
<ArrowRight className="hidden h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5 sm:block" />
</LocalizedClientLink>
</li>
))
) : (
<li className="py-10 text-center text-sm text-muted-foreground" data-testid="no-orders-message">
Još nemate narudžbi.{" "}
<LocalizedClientLink href="/store" className="text-primary underline underline-offset-4">
Pogledajte katalog
</LocalizedClientLink>
</li>
)}
</ul>
</section>
</div>
)
}
const getProfileCompletion = (customer: HttpTypes.StoreCustomer | null) => {
if (!customer) return 0
let count = 0
if (!customer) {
return 0
}
if (customer.email) {
count++
}
if (customer.first_name && customer.last_name) {
count++
}
if (customer.phone) {
count++
}
const billingAddress = customer.addresses?.find(
(addr) => addr.is_default_billing
)
if (billingAddress) {
count++
}
if (customer.email) count++
if (customer.first_name && customer.last_name) count++
if (customer.phone) count++
if (customer.addresses?.find((addr) => addr.is_default_billing)) count++
return (count / 4) * 100
}