Skip to content

Commit cecb3d4

Browse files
committed
refactor(dashboard): Extract inline setValuesForUpdate to named function
Extract the inline arrow in setValuesForUpdate to a standalone mapOrderAddressToFormValues() function, matching the codebase pattern used in customers/components/customer-address-form.tsx. Also uses || instead of ?? for consistency with the existing mapAddressToFormValues.
1 parent 3a5c714 commit cecb3d4

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

packages/dashboard/src/app/routes/_authenticated/_orders/components/customer-address-selector.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,7 @@ export function CustomerAddressSelector({
143143
<CustomerAddressForm
144144
hideDefaultAddressFlags
145145
address={initialAddress}
146-
setValuesForUpdate={addr => ({
147-
id: '',
148-
fullName: addr?.fullName ?? '',
149-
company: addr?.company ?? '',
150-
streetLine1: addr?.streetLine1 ?? '',
151-
streetLine2: addr?.streetLine2 ?? '',
152-
city: addr?.city ?? '',
153-
province: addr?.province ?? '',
154-
postalCode: addr?.postalCode ?? '',
155-
countryCode: addr?.countryCode ?? '',
156-
phoneNumber: addr?.phoneNumber ?? '',
157-
defaultShippingAddress: false,
158-
defaultBillingAddress: false,
159-
customFields: {},
160-
})}
146+
setValuesForUpdate={mapOrderAddressToFormValues}
161147
submitLabel={submitLabel}
162148
onSubmit={values => {
163149
onSubmitNew(mapFormValuesToInput(values));
@@ -173,6 +159,24 @@ export function CustomerAddressSelector({
173159
);
174160
}
175161

162+
function mapOrderAddressToFormValues(address: Order['shippingAddress']): AddressFormValues {
163+
return {
164+
id: '',
165+
fullName: address?.fullName || '',
166+
company: address?.company || '',
167+
streetLine1: address?.streetLine1 || '',
168+
streetLine2: address?.streetLine2 || '',
169+
city: address?.city || '',
170+
province: address?.province || '',
171+
postalCode: address?.postalCode || '',
172+
countryCode: address?.countryCode || '',
173+
phoneNumber: address?.phoneNumber || '',
174+
defaultShippingAddress: false,
175+
defaultBillingAddress: false,
176+
customFields: {},
177+
};
178+
}
179+
176180
function mapFormValuesToInput(values: AddressFormValues): CreateAddressInput {
177181
return {
178182
fullName: values.fullName,

0 commit comments

Comments
 (0)