Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
107 lines
4.4 KiB
TypeScript
107 lines
4.4 KiB
TypeScript
'use client'
|
||
|
||
import { useState } from 'react'
|
||
import { ShoppingBag } from 'lucide-react'
|
||
import { PosLine } from '@/app/pos/shared'
|
||
import { useMoney } from '@/app/pos/currency'
|
||
import { Button } from '@/app/components/ui/button'
|
||
import type { MemberCheckoutDiscountLine } from '@/app/lib/types'
|
||
import { useT } from '@/app/lib/i18n/MessagesProvider'
|
||
|
||
// POS cart rows (redesign-pos-sale-flow, BABYBOO-38): image (or placeholder), name, code and unit
|
||
// price, line amount, − qty + and Remove. − on a line of 1 removes it. The order pane's footer owns
|
||
// the total.
|
||
|
||
interface CartPanelProps {
|
||
lines: PosLine[]
|
||
onInc: (key: number) => void
|
||
onDec: (key: number) => void
|
||
onRemove: (key: number) => void
|
||
discountLines?: MemberCheckoutDiscountLine[]
|
||
/** pPricingIds not in stock at this till (sold out or pre-order): those lines are marked "Order in". */
|
||
soldOutIds?: Set<string>
|
||
}
|
||
|
||
function LineImage({ line }: { line: PosLine }) {
|
||
const [failed, setFailed] = useState(false)
|
||
if (!line.imageUrl || failed) {
|
||
return (
|
||
<span data-testid={`cart-image-${line.key}`} className="flex size-14 shrink-0 items-center justify-center rounded-md bg-muted">
|
||
<ShoppingBag aria-hidden="true" className="size-5 text-muted-foreground" />
|
||
</span>
|
||
)
|
||
}
|
||
return (
|
||
// eslint-disable-next-line @next/next/no-img-element -- remote drive URLs; no next/image remotePatterns configured
|
||
<img
|
||
data-testid={`cart-image-${line.key}`}
|
||
src={line.imageUrl}
|
||
alt=""
|
||
onError={() => setFailed(true)}
|
||
className="size-14 shrink-0 rounded-md bg-card object-contain"
|
||
/>
|
||
)
|
||
}
|
||
|
||
export function CartPanel({ lines, onInc, onDec, onRemove, discountLines, soldOutIds }: CartPanelProps) {
|
||
const money = useMoney()
|
||
const t = useT()
|
||
if (lines.length === 0) {
|
||
return (
|
||
<div className="flex flex-col items-center gap-1 py-8 text-center text-sm text-muted-foreground">
|
||
<ShoppingBag aria-hidden="true" className="size-6" />
|
||
<span className="font-medium text-foreground">{t('PosNoItemsYet')}</span>
|
||
<span>{t('PosNoItemsHint')}</span>
|
||
</div>
|
||
)
|
||
}
|
||
return (
|
||
<ul className="divide-y">
|
||
{lines.map((line, index) => {
|
||
const discount = discountLines?.find((d) => d.lineIndex === index)
|
||
const meta = [line.productCode, t('PosPriceEach', { price: money(line.unitPrice) })].filter(Boolean).join(' · ')
|
||
return (
|
||
<li key={line.key} data-testid={`cart-line-${line.key}`} className="flex gap-3 py-3">
|
||
<LineImage line={line} />
|
||
<div className="min-w-0 flex-1 space-y-1">
|
||
<div className="flex items-start justify-between gap-2">
|
||
<span className="font-medium leading-5">{line.label}</span>
|
||
<span className="font-semibold tabular-nums">{money(line.unitPrice * line.qty)}</span>
|
||
</div>
|
||
<div className="text-xs text-muted-foreground">{meta}</div>
|
||
{soldOutIds?.has(line.pPricingId) && <div className="text-xs font-medium text-primary">{t('PosOrderIn')}</div>}
|
||
{discount && (
|
||
<div data-testid={`line-discount-${line.key}`} className="text-xs text-positive">
|
||
{discount.campaignLabel} -{money(discount.amount)}
|
||
</div>
|
||
)}
|
||
<div className="flex items-center justify-between">
|
||
<div className="flex items-center rounded-md border">
|
||
<Button
|
||
type="button"
|
||
variant="ghost"
|
||
size="sm"
|
||
aria-label={t('PosDecreaseAria', { name: line.label })}
|
||
onClick={() => (line.qty > 1 ? onDec(line.key) : onRemove(line.key))}
|
||
>
|
||
−
|
||
</Button>
|
||
<span data-testid={`cart-qty-${line.key}`} className="w-8 text-center tabular-nums">
|
||
{line.qty}
|
||
</span>
|
||
<Button type="button" variant="ghost" size="sm" aria-label={t('PosIncreaseAria', { name: line.label })} onClick={() => onInc(line.key)}>
|
||
+
|
||
</Button>
|
||
</div>
|
||
<Button type="button" variant="link" size="sm" aria-label={t('PosRemoveAria', { name: line.label })} onClick={() => onRemove(line.key)}>
|
||
{t('PosRemove')}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
</li>
|
||
)
|
||
})}
|
||
</ul>
|
||
)
|
||
}
|