create-brainerce-store 1.72.0 → 1.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -4
- package/messages/en.json +3 -0
- package/messages/he.json +3 -0
- package/package.json +1 -1
- package/templates/nextjs/base/TRANSLATIONS.md +207 -207
- package/templates/nextjs/base/src/app/checkout/page.tsx +1074 -1074
- package/templates/nextjs/base/src/components/account/order-history.tsx +371 -371
- package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +85 -85
- package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +127 -127
- package/templates/nextjs/base/src/ui/cart/cart-item.tsx +164 -164
- package/templates/nextjs/base/src/ui/cart/cart-view.tsx +176 -176
- package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +137 -137
- package/templates/nextjs/base/src/ui/product/review-form.tsx +33 -11
- package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +177 -181
- package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +158 -158
- package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +184 -184
- package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +131 -131
- package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +30 -10
- package/templates/nextjs/ui-canvas/cart/cart-item.tsx +137 -137
- package/templates/nextjs/ui-canvas/cart/cart-view.tsx +140 -140
- package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +124 -124
- package/templates/nextjs/ui-canvas/product/review-form.tsx +9 -1
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
5
|
-
import type { CartItem as CartItemType } from 'brainerce';
|
|
6
|
-
import { getCartItemImage, formatPrice } from 'brainerce';
|
|
7
|
-
import { getClient } from '@/core/lib/brainerce';
|
|
8
|
-
import { useTranslations } from '@/core/lib/translations';
|
|
9
|
-
import { useCurrency } from '@/core/lib/use-currency';
|
|
10
|
-
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
11
|
-
import { cn } from '@/core/lib/utils';
|
|
12
|
-
import { IconMinus, IconPlus, IconTrash } from '@/ui/shared/icons';
|
|
13
|
-
|
|
14
|
-
interface CartItemProps {
|
|
15
|
-
item: CartItemType;
|
|
16
|
-
onUpdate: () => void;
|
|
17
|
-
className?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Single cart line: image, name, variant, unit price, quantity controls,
|
|
22
|
-
* remove, line total; the `item` prop comes from useCartPage().cart.
|
|
23
|
-
*/
|
|
24
|
-
export function CartItem({ item, onUpdate, className }: CartItemProps) {
|
|
25
|
-
const t = useTranslations('common');
|
|
26
|
-
const td = useTranslations('productDetail');
|
|
27
|
-
const currency = useCurrency();
|
|
28
|
-
const [updating, setUpdating] = useState(false);
|
|
29
|
-
const [removing, setRemoving] = useState(false);
|
|
30
|
-
|
|
31
|
-
const productName = item.product.name;
|
|
32
|
-
const imageUrl = getCartItemImage(item);
|
|
33
|
-
const variantName = item.variant?.name;
|
|
34
|
-
const unitPrice = parseFloat(item.unitPrice);
|
|
35
|
-
const lineTotal = unitPrice * item.quantity;
|
|
36
|
-
|
|
37
|
-
// The server decides purchasability, per line. `isAvailable === false` means
|
|
38
|
-
// this line blocks checkout until it is removed, whether the stock ran out
|
|
39
|
-
// (a released reservation is the common cause) or the product/variant was
|
|
40
|
-
// withdrawn from sale. `unavailableReason` separates the two for the label.
|
|
41
|
-
const isUnavailable = item.isAvailable === false;
|
|
42
|
-
const unavailableLabel = isUnavailable
|
|
43
|
-
? item.unavailableReason === 'OUT_OF_STOCK'
|
|
44
|
-
? td('outOfStock')
|
|
45
|
-
: td('unavailable')
|
|
46
|
-
: null;
|
|
47
|
-
|
|
48
|
-
async function handleQuantityChange(newQuantity: number) {
|
|
49
|
-
if (newQuantity < 1 || updating) return;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
setUpdating(true);
|
|
53
|
-
const client = getClient();
|
|
54
|
-
await client.smartUpdateCartItem(item.productId, newQuantity, item.variantId || undefined);
|
|
55
|
-
onUpdate();
|
|
56
|
-
} catch (err) {
|
|
57
|
-
console.error('Failed to update quantity:', err);
|
|
58
|
-
} finally {
|
|
59
|
-
setUpdating(false);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function handleRemove() {
|
|
64
|
-
if (removing) return;
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
setRemoving(true);
|
|
68
|
-
const client = getClient();
|
|
69
|
-
await client.smartRemoveFromCart(item.productId, item.variantId || undefined);
|
|
70
|
-
onUpdate();
|
|
71
|
-
} catch (err) {
|
|
72
|
-
console.error('Failed to remove item:', err);
|
|
73
|
-
} finally {
|
|
74
|
-
setRemoving(false);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<div className={cn('flex items-start gap-4', className)}>
|
|
80
|
-
{/* Image — `relative` + fixed box are layout-critical for next/image fill */}
|
|
81
|
-
<div className="relative h-20 w-20 shrink-0 overflow-hidden rounded-lg border
|
|
82
|
-
{imageUrl ? (
|
|
83
|
-
<Image src={imageUrl} alt={productName} fill sizes="96px" className="object-cover" />
|
|
84
|
-
) : (
|
|
85
|
-
<span className="sr-only">{productName}</span>
|
|
86
|
-
)}
|
|
87
|
-
</div>
|
|
88
|
-
|
|
89
|
-
{/* Details */}
|
|
90
|
-
<div className="min-w-0 flex-1">
|
|
91
|
-
<h3 className="font-sans text-[15px] font-semibold leading-snug
|
|
92
|
-
{productName}
|
|
93
|
-
</h3>
|
|
94
|
-
|
|
95
|
-
{/* Availability badge. This line blocks checkout while it shows. */}
|
|
96
|
-
{unavailableLabel && (
|
|
97
|
-
<span className="mt-1 inline-flex items-center rounded-full
|
|
98
|
-
{unavailableLabel}
|
|
99
|
-
</span>
|
|
100
|
-
)}
|
|
101
|
-
|
|
102
|
-
{/* Variant name */}
|
|
103
|
-
{variantName && <p className="mt-0.5 text-xs
|
|
104
|
-
|
|
105
|
-
{/* Unit price */}
|
|
106
|
-
<p className="mt-1 text-sm
|
|
107
|
-
{formatPrice(unitPrice, { currency }) as string}
|
|
108
|
-
</p>
|
|
109
|
-
|
|
110
|
-
{/* Quantity controls + remove */}
|
|
111
|
-
<div className="mt-3 flex flex-wrap items-center gap-3">
|
|
112
|
-
<div
|
|
113
|
-
className="flex h-9 items-center rounded-full border"
|
|
114
|
-
role="group"
|
|
115
|
-
aria-label={td('quantityLabel')}
|
|
116
|
-
>
|
|
117
|
-
<button
|
|
118
|
-
type="button"
|
|
119
|
-
onClick={() => handleQuantityChange(item.quantity - 1)}
|
|
120
|
-
disabled={updating || item.quantity <= 1}
|
|
121
|
-
aria-label={td('decreaseQuantity')}
|
|
122
|
-
className="flex h-full w-9 items-center justify-center rounded-s-full transition-colors
|
|
123
|
-
>
|
|
124
|
-
<IconMinus size={16} />
|
|
125
|
-
</button>
|
|
126
|
-
<span aria-live="polite" className="min-w-7 text-center text-sm font-semibold">
|
|
127
|
-
{updating ? <LoadingSpinner size="sm" /> : item.quantity}
|
|
128
|
-
</span>
|
|
129
|
-
<button
|
|
130
|
-
type="button"
|
|
131
|
-
onClick={() => handleQuantityChange(item.quantity + 1)}
|
|
132
|
-
disabled={updating || isUnavailable}
|
|
133
|
-
aria-label={td('increaseQuantity')}
|
|
134
|
-
className="flex h-full w-9 items-center justify-center rounded-e-full transition-colors
|
|
135
|
-
>
|
|
136
|
-
<IconPlus size={16} />
|
|
137
|
-
</button>
|
|
138
|
-
</div>
|
|
139
|
-
|
|
140
|
-
<button
|
|
141
|
-
type="button"
|
|
142
|
-
onClick={handleRemove}
|
|
143
|
-
disabled={removing}
|
|
144
|
-
className="inline-flex items-center gap-1.5 text-xs font-medium
|
|
145
|
-
>
|
|
146
|
-
<IconTrash size={16} />
|
|
147
|
-
{removing ? t('removing') : t('remove')}
|
|
148
|
-
</button>
|
|
149
|
-
</div>
|
|
150
|
-
</div>
|
|
151
|
-
|
|
152
|
-
{/* Line total */}
|
|
153
|
-
<span className="text-base font-semibold
|
|
154
|
-
{formatPrice(lineTotal, { currency }) as string}
|
|
155
|
-
</span>
|
|
156
|
-
</div>
|
|
157
|
-
);
|
|
158
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
5
|
+
import type { CartItem as CartItemType } from 'brainerce';
|
|
6
|
+
import { getCartItemImage, formatPrice } from 'brainerce';
|
|
7
|
+
import { getClient } from '@/core/lib/brainerce';
|
|
8
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
9
|
+
import { useCurrency } from '@/core/lib/use-currency';
|
|
10
|
+
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
11
|
+
import { cn } from '@/core/lib/utils';
|
|
12
|
+
import { IconMinus, IconPlus, IconTrash } from '@/ui/shared/icons';
|
|
13
|
+
|
|
14
|
+
interface CartItemProps {
|
|
15
|
+
item: CartItemType;
|
|
16
|
+
onUpdate: () => void;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Single cart line: image, name, variant, unit price, quantity controls,
|
|
22
|
+
* remove, line total; the `item` prop comes from useCartPage().cart.
|
|
23
|
+
*/
|
|
24
|
+
export function CartItem({ item, onUpdate, className }: CartItemProps) {
|
|
25
|
+
const t = useTranslations('common');
|
|
26
|
+
const td = useTranslations('productDetail');
|
|
27
|
+
const currency = useCurrency();
|
|
28
|
+
const [updating, setUpdating] = useState(false);
|
|
29
|
+
const [removing, setRemoving] = useState(false);
|
|
30
|
+
|
|
31
|
+
const productName = item.product.name;
|
|
32
|
+
const imageUrl = getCartItemImage(item);
|
|
33
|
+
const variantName = item.variant?.name;
|
|
34
|
+
const unitPrice = parseFloat(item.unitPrice);
|
|
35
|
+
const lineTotal = unitPrice * item.quantity;
|
|
36
|
+
|
|
37
|
+
// The server decides purchasability, per line. `isAvailable === false` means
|
|
38
|
+
// this line blocks checkout until it is removed, whether the stock ran out
|
|
39
|
+
// (a released reservation is the common cause) or the product/variant was
|
|
40
|
+
// withdrawn from sale. `unavailableReason` separates the two for the label.
|
|
41
|
+
const isUnavailable = item.isAvailable === false;
|
|
42
|
+
const unavailableLabel = isUnavailable
|
|
43
|
+
? item.unavailableReason === 'OUT_OF_STOCK'
|
|
44
|
+
? td('outOfStock')
|
|
45
|
+
: td('unavailable')
|
|
46
|
+
: null;
|
|
47
|
+
|
|
48
|
+
async function handleQuantityChange(newQuantity: number) {
|
|
49
|
+
if (newQuantity < 1 || updating) return;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
setUpdating(true);
|
|
53
|
+
const client = getClient();
|
|
54
|
+
await client.smartUpdateCartItem(item.productId, newQuantity, item.variantId || undefined);
|
|
55
|
+
onUpdate();
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error('Failed to update quantity:', err);
|
|
58
|
+
} finally {
|
|
59
|
+
setUpdating(false);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function handleRemove() {
|
|
64
|
+
if (removing) return;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
setRemoving(true);
|
|
68
|
+
const client = getClient();
|
|
69
|
+
await client.smartRemoveFromCart(item.productId, item.variantId || undefined);
|
|
70
|
+
onUpdate();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error('Failed to remove item:', err);
|
|
73
|
+
} finally {
|
|
74
|
+
setRemoving(false);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div className={cn('flex items-start gap-4', className)}>
|
|
80
|
+
{/* Image — `relative` + fixed box are layout-critical for next/image fill */}
|
|
81
|
+
<div className="bg-secondary relative h-20 w-20 shrink-0 overflow-hidden rounded-lg border sm:h-24 sm:w-24">
|
|
82
|
+
{imageUrl ? (
|
|
83
|
+
<Image src={imageUrl} alt={productName} fill sizes="96px" className="object-cover" />
|
|
84
|
+
) : (
|
|
85
|
+
<span className="sr-only">{productName}</span>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
{/* Details */}
|
|
90
|
+
<div className="min-w-0 flex-1">
|
|
91
|
+
<h3 className="text-foreground font-sans text-[15px] font-semibold leading-snug">
|
|
92
|
+
{productName}
|
|
93
|
+
</h3>
|
|
94
|
+
|
|
95
|
+
{/* Availability badge. This line blocks checkout while it shows. */}
|
|
96
|
+
{unavailableLabel && (
|
|
97
|
+
<span className="bg-destructive/10 text-destructive mt-1 inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium">
|
|
98
|
+
{unavailableLabel}
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
101
|
+
|
|
102
|
+
{/* Variant name */}
|
|
103
|
+
{variantName && <p className="text-muted-foreground mt-0.5 text-xs">{variantName}</p>}
|
|
104
|
+
|
|
105
|
+
{/* Unit price */}
|
|
106
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
107
|
+
{formatPrice(unitPrice, { currency }) as string}
|
|
108
|
+
</p>
|
|
109
|
+
|
|
110
|
+
{/* Quantity controls + remove */}
|
|
111
|
+
<div className="mt-3 flex flex-wrap items-center gap-3">
|
|
112
|
+
<div
|
|
113
|
+
className="flex h-9 items-center rounded-full border"
|
|
114
|
+
role="group"
|
|
115
|
+
aria-label={td('quantityLabel')}
|
|
116
|
+
>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
onClick={() => handleQuantityChange(item.quantity - 1)}
|
|
120
|
+
disabled={updating || item.quantity <= 1}
|
|
121
|
+
aria-label={td('decreaseQuantity')}
|
|
122
|
+
className="hover:bg-secondary flex h-full w-9 items-center justify-center rounded-s-full transition-colors disabled:opacity-40"
|
|
123
|
+
>
|
|
124
|
+
<IconMinus size={16} />
|
|
125
|
+
</button>
|
|
126
|
+
<span aria-live="polite" className="min-w-7 text-center text-sm font-semibold">
|
|
127
|
+
{updating ? <LoadingSpinner size="sm" /> : item.quantity}
|
|
128
|
+
</span>
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
onClick={() => handleQuantityChange(item.quantity + 1)}
|
|
132
|
+
disabled={updating || isUnavailable}
|
|
133
|
+
aria-label={td('increaseQuantity')}
|
|
134
|
+
className="hover:bg-secondary flex h-full w-9 items-center justify-center rounded-e-full transition-colors disabled:opacity-40"
|
|
135
|
+
>
|
|
136
|
+
<IconPlus size={16} />
|
|
137
|
+
</button>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
onClick={handleRemove}
|
|
143
|
+
disabled={removing}
|
|
144
|
+
className="text-muted-foreground hover:text-destructive inline-flex items-center gap-1.5 text-xs font-medium transition-colors disabled:opacity-50"
|
|
145
|
+
>
|
|
146
|
+
<IconTrash size={16} />
|
|
147
|
+
{removing ? t('removing') : t('remove')}
|
|
148
|
+
</button>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
{/* Line total */}
|
|
153
|
+
<span className="text-foreground text-base font-semibold">
|
|
154
|
+
{formatPrice(lineTotal, { currency }) as string}
|
|
155
|
+
</span>
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
}
|