You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.8 KiB
131 lines
3.8 KiB
import React, { useState } from 'react';
|
|
import { useLocation } from 'react-router-dom';
|
|
import { MobileShell } from '../../components/layout/MobileShell';
|
|
import { StandardPageHeader } from '../../components/layout/TopHeader';
|
|
import {
|
|
AddressCard,
|
|
AddNewAddressCard,
|
|
} from '../../components/checkout/AddressCard';
|
|
import { AddressFormSheet } from '../../components/modals/AddressFormSheet';
|
|
import { BUY01_ADDRESSES } from '../../data/checkoutData';
|
|
import { useShopApp } from '../../context/ShopAppContext';
|
|
import { mapAddressToOption } from '../../lib/mappers';
|
|
import { isBareMode, ROUTES } from '../../lib/routes';
|
|
import type { ApiAddress } from '../../lib/shopApi';
|
|
|
|
/**
|
|
* Node 4182:13316 — `shop-adreess` (My Addresses, 375×814)
|
|
*/
|
|
export const ShopAddressPage: React.FC = () => {
|
|
const location = useLocation();
|
|
const bare = isBareMode(location.search);
|
|
|
|
const {
|
|
addresses: apiAddresses,
|
|
selectedAddressId,
|
|
selectAddress,
|
|
saveAddress,
|
|
deleteAddress,
|
|
} = useShopApp();
|
|
|
|
const [bareSelectedId, setBareSelectedId] = useState('addr-1');
|
|
const [sheetOpen, setSheetOpen] = useState(false);
|
|
const [editingAddress, setEditingAddress] = useState<ApiAddress | null>(null);
|
|
|
|
const bareAddresses = BUY01_ADDRESSES.map((addr) => ({
|
|
...addr,
|
|
selected: addr.id === bareSelectedId,
|
|
}));
|
|
|
|
return (
|
|
<MobileShell width={375} height={814} backgroundColor="#f3f1ef">
|
|
{/* Top Header: Back button + "My Adresses" */}
|
|
<StandardPageHeader
|
|
title="My Adresses"
|
|
titleTop={29}
|
|
backTo={bare ? '/shop-account' : ROUTES.account}
|
|
/>
|
|
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
flex: 1,
|
|
padding: '32px var(--page-px) 28px',
|
|
gap: 22,
|
|
}}
|
|
>
|
|
{/* Saved Addresses List (4182:13410) */}
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
gap: 10,
|
|
}}
|
|
>
|
|
{bare ? (
|
|
bareAddresses.map((address) => (
|
|
<AddressCard
|
|
key={address.id}
|
|
item={address}
|
|
variant="manage"
|
|
onSelect={() => setBareSelectedId(address.id)}
|
|
/>
|
|
))
|
|
) : apiAddresses.length > 0 ? (
|
|
apiAddresses.map((addr, index) => (
|
|
<AddressCard
|
|
key={addr.id}
|
|
item={mapAddressToOption(addr, selectedAddressId, index)}
|
|
variant="manage"
|
|
onSelect={() => selectAddress(addr.id)}
|
|
onEdit={() => {
|
|
setEditingAddress(addr);
|
|
setSheetOpen(true);
|
|
}}
|
|
onDelete={() => {
|
|
void deleteAddress(addr.id);
|
|
}}
|
|
/>
|
|
))
|
|
) : (
|
|
<div
|
|
style={{
|
|
padding: '22px 16px',
|
|
borderRadius: 15,
|
|
backgroundColor: '#ffffff',
|
|
textAlign: 'center',
|
|
fontFamily: 'var(--font-sans)',
|
|
fontSize: 13,
|
|
color: '#73889d',
|
|
}}
|
|
>
|
|
No saved delivery addresses yet. Tap below to add your first address.
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Add New Address Card (4182:13457) */}
|
|
<AddNewAddressCard
|
|
onClick={
|
|
bare
|
|
? undefined
|
|
: () => {
|
|
setEditingAddress(null);
|
|
setSheetOpen(true);
|
|
}
|
|
}
|
|
/>
|
|
</div>
|
|
|
|
{!bare && (
|
|
<AddressFormSheet
|
|
isOpen={sheetOpen}
|
|
onClose={() => setSheetOpen(false)}
|
|
initialAddress={editingAddress}
|
|
onSave={saveAddress}
|
|
/>
|
|
)}
|
|
</MobileShell>
|
|
);
|
|
};
|