import {Link} from 'react-router'; import {Money} from '@shopify/hydrogen'; import type {CustomerFragment} from 'customer-accountapi.generated'; import {AccountWishlistStat} from '~/components/AccountWishlistStat'; import { getCustomerDisplayName, getCustomerInitials, } from '~/lib/customerDisplay'; export type AccountOverviewOrder = { id: string; name: string; processedAt: string | null; fulfillmentStatus: string | null; totalPrice: { amount: string; currencyCode: string; } | null; lineItems: { nodes: Array<{ title: string; quantity: number; price: { amount: string; currencyCode: string; } | null; }>; } | null; }; export type AccountOverviewData = { creationDate: string | null; orders: { pageInfo: {hasNextPage: boolean}; nodes: AccountOverviewOrder[]; } | null; }; function sumTotalSpent(orders: AccountOverviewOrder[], currency: string) { let total = 0; for (const o of orders) { if (o.totalPrice && o.totalPrice.currencyCode === currency) { total += Number.parseFloat(o.totalPrice.amount) || 0; } } return total; } type Props = { customer: CustomerFragment; overview: AccountOverviewData; }; /** * Figma 123:11834 account overview: profile band, stat tiles, recent order. */ export function AccountOverview({customer, overview}: Props) { const orders = overview.orders?.nodes ?? []; const hasNext = overview.orders?.pageInfo.hasNextPage ?? false; const count = orders.length; const orderCountLabel = hasNext ? `${count}+` : String(count); const spendCurrency = orders.find((o) => o.totalPrice)?.totalPrice ?.currencyCode; const recent = orders[0] ?? null; const memberLabel = overview.creationDate ? `Member since ${new Date(overview.creationDate).getFullYear()}` : 'Member'; return (
{getCustomerInitials(customer)}

{getCustomerDisplayName(customer) || 'Account'}

{memberLabel}

Recent order

{recent ?

{recent.name}

{recent.processedAt ? new Date(recent.processedAt).toLocaleDateString() : '—'}

{recent.fulfillmentStatus ?

{recent.fulfillmentStatus}

: null} {recent.lineItems?.nodes.length ?
    {recent.lineItems.nodes.map((line, i) => (
  • {line.title}{' '} ×{line.quantity} {line.price ? : null}
  • ))}
: null} {recent.totalPrice ?
Total:{' '}
: null}

View order

:

You haven’t placed an order yet.{' '} Browse the shop

}
); }