import Area from '@components/common/Area.js'; import { SelectField } from '@components/common/form/SelectField.js'; import { CardContent, CardDescription, CardTitle } from '@components/common/ui/Card.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; /** * The "Addresses" section of Settings → Customer (Address Format Registry * § 3.13): seven of the eight `address*` setting rows, posted with the page * form through the generic `saveSetting` upsert. The eighth, * `addressSellToCountries`, lives with the shipping zones it interacts with * (Settings → Shipping). Country formats, region lists and label text are * national conventions and are deliberately not editable. */ export interface CustomerAddressSettingValues { addressNameFormat: string; addressTelephone: string; addressOrganization: string; addressLine2: string; addressLine3: string; addressRequired: Record; addressDefaultCountry: string; } export interface CountryOption { code: string; name: string; } /** The postal fields a merchant may tighten (spec § 3.13: tighten only). */ const REQUIRABLE_FIELDS: { id: string; label: () => string }[] = [ { id: 'locality', label: () => _('City') }, { id: 'administrative_area', label: () => _('State / Province') }, { id: 'postal_code', label: () => _('Postal code') }, { id: 'dependent_locality', label: () => _('Ward / Neighbourhood') }, { id: 'address_line_2', label: () => _('Address line 2') } ]; function AddressFields({ setting, countries }: { setting: CustomerAddressSettingValues; countries: CountryOption[]; }) { const required = setting.addressRequired ?? {}; return (
{_('Required fields')}

{_( 'Fields a country leaves optional can be made mandatory here; nothing a country requires is ever made optional.' )}

{REQUIRABLE_FIELDS.map((f) => ( ))}
({ value: c.code, label: c.name })) ]} helperText={_( 'Pre-selected on a new address. Shipping is still limited to the countries your zones cover.' )} />
); } /** One section of the customer settings card. Area `customerAddressSetting` lets an extension add controls. */ export function AddressSection({ setting, countries }: { setting: CustomerAddressSettingValues; countries: CountryOption[]; }) { return ( {_('Addresses')} {_( 'What every address form collects, in the address book and at checkout. Country layouts, region lists and labels follow each country and are not editable.' )} ); }