feat(spa): add order history and automatic address book

This commit is contained in:
Your Name committed 2026-06-06 19:29:19 +07:00
1 parent 15cb147c81
commit ca31564ee7
3 files changed
+126 -31

No files matched your search

+18 -1
View File
@@ -31,7 +31,7 @@ export default function CheckoutPage() {
address: ''
})
// Prefill form with LINE customer data
// Prefill form with LINE customer data and last used address
useEffect(() => {
if (customer) {
setFormData(prev => ({
@@ -40,6 +40,23 @@ export default function CheckoutPage() {
email: prev.email || customer.email || '',
phone: prev.phone || customer.phone || ''
}))
// Fetch latest order to pre-fill address acting as an automatic Address Book
fetch(`${API_BASE}/orders/customer/${customer.id}`)
.then(res => res.json())
.then(data => {
if (Array.isArray(data) && data.length > 0) {
const lastOrder = data[0];
setFormData(prev => ({
...prev,
name: prev.name || lastOrder.customerName || '',
phone: prev.phone || lastOrder.customerPhone || '',
email: prev.email || lastOrder.customerEmail || '',
address: prev.address || lastOrder.shippingAddress || ''
}))
}
})
.catch(console.error)
}
}, [customer])