2020-03-09 14:23:16 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
2021-04-22 11:37:27 +00:00
|
|
|
export interface AddressField {
|
|
|
|
// The label for the field.
|
|
|
|
label: string;
|
|
|
|
// The label for the field if made optional.
|
|
|
|
optionalLabel: string;
|
|
|
|
// The HTML autocomplete attribute value. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
|
|
|
autocomplete: string;
|
|
|
|
// How this field value is capitalized.
|
|
|
|
autocapitalize?: string;
|
|
|
|
// Set to true if the field is required.
|
|
|
|
required: boolean;
|
|
|
|
// Set to true if the field should not be rendered.
|
|
|
|
hidden: boolean;
|
|
|
|
// Fields will be sorted and render in this order, lowest to highest.
|
|
|
|
index: number;
|
|
|
|
}
|
|
|
|
|
2023-05-31 09:30:44 +00:00
|
|
|
export interface LocaleSpecificAddressField extends Partial< AddressField > {
|
|
|
|
priority?: number | undefined;
|
2021-06-17 08:35:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 11:37:27 +00:00
|
|
|
export interface AddressFields {
|
|
|
|
first_name: AddressField;
|
|
|
|
last_name: AddressField;
|
|
|
|
company: AddressField;
|
|
|
|
address_1: AddressField;
|
|
|
|
address_2: AddressField;
|
|
|
|
country: AddressField;
|
|
|
|
city: AddressField;
|
|
|
|
state: AddressField;
|
|
|
|
postcode: AddressField;
|
|
|
|
}
|
|
|
|
|
2021-06-17 08:35:24 +00:00
|
|
|
export type AddressType = 'billing' | 'shipping';
|
2022-10-06 14:48:52 +00:00
|
|
|
export interface ShippingAddress {
|
2021-05-10 09:03:30 +00:00
|
|
|
first_name: string;
|
|
|
|
last_name: string;
|
|
|
|
company: string;
|
|
|
|
address_1: string;
|
|
|
|
address_2: string;
|
|
|
|
country: string;
|
|
|
|
city: string;
|
|
|
|
state: string;
|
|
|
|
postcode: string;
|
2022-02-22 17:45:01 +00:00
|
|
|
phone: string;
|
2021-05-10 09:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type KeyedAddressField = AddressField & {
|
|
|
|
key: keyof AddressFields;
|
2021-06-17 08:35:24 +00:00
|
|
|
errorMessage?: string;
|
2021-05-10 09:03:30 +00:00
|
|
|
};
|
2022-10-06 14:48:52 +00:00
|
|
|
export interface BillingAddress extends ShippingAddress {
|
2022-02-22 17:45:01 +00:00
|
|
|
email: string;
|
|
|
|
}
|
2021-05-10 09:03:30 +00:00
|
|
|
export type CountryAddressFields = Record< string, AddressFields >;
|
|
|
|
|
2020-03-09 14:23:16 +00:00
|
|
|
/**
|
|
|
|
* Default address field properties.
|
|
|
|
*/
|
2021-04-22 11:37:27 +00:00
|
|
|
export const defaultAddressFields: AddressFields = {
|
2020-03-09 14:23:16 +00:00
|
|
|
first_name: {
|
|
|
|
label: __( 'First name', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'First name (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'given-name',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 10,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
last_name: {
|
|
|
|
label: __( 'Last name', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'Last name (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'family-name',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 20,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
company: {
|
|
|
|
label: __( 'Company', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'Company (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'organization',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: false,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 30,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
address_1: {
|
|
|
|
label: __( 'Address', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'Address (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'address-line1',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 40,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
address_2: {
|
|
|
|
label: __( 'Apartment, suite, etc.', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'Apartment, suite, etc. (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'address-line2',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: false,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 50,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
country: {
|
|
|
|
label: __( 'Country/Region', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'Country/Region (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'country',
|
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 60,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
city: {
|
|
|
|
label: __( 'City', 'woo-gutenberg-products-block' ),
|
2020-03-24 10:28:19 +00:00
|
|
|
optionalLabel: __( 'City (optional)', 'woo-gutenberg-products-block' ),
|
2020-03-09 14:23:16 +00:00
|
|
|
autocomplete: 'address-level2',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 70,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
state: {
|
|
|
|
label: __( 'State/County', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'State/County (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'address-level1',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'sentences',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 80,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
postcode: {
|
|
|
|
label: __( 'Postal code', 'woo-gutenberg-products-block' ),
|
|
|
|
optionalLabel: __(
|
|
|
|
'Postal code (optional)',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
autocomplete: 'postal-code',
|
2020-08-03 08:53:42 +00:00
|
|
|
autocapitalize: 'characters',
|
2020-03-09 14:23:16 +00:00
|
|
|
required: true,
|
|
|
|
hidden: false,
|
2021-02-11 16:49:27 +00:00
|
|
|
index: 90,
|
2020-03-09 14:23:16 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-08 12:31:12 +00:00
|
|
|
export default defaultAddressFields;
|