@k-int/address-plugins 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -0
- package/es/address-plugin-british-isles/index.js +13 -0
- package/es/address-plugin-british-isles/src/AddressFieldsGBR.js +110 -0
- package/es/address-plugin-british-isles/src/backendToFields.js +45 -0
- package/es/address-plugin-british-isles/src/fieldOrder.js +16 -0
- package/es/address-plugin-british-isles/src/fieldsToBackend.js +101 -0
- package/es/address-plugin-british-isles/src/index.js +21 -0
- package/es/address-plugin-british-isles/src/listOfSupportedCountries.js +8 -0
- package/es/address-plugin-generic/index.js +13 -0
- package/es/address-plugin-generic/src/AddressFieldsGeneric.js +140 -0
- package/es/address-plugin-generic/src/backendToFields.js +53 -0
- package/es/address-plugin-generic/src/fieldOrder.js +19 -0
- package/es/address-plugin-generic/src/fieldsToBackend.js +140 -0
- package/es/address-plugin-generic/src/index.js +21 -0
- package/es/address-plugin-generic/src/listOfSupportedCountries.js +8 -0
- package/es/address-plugin-north-america/index.js +13 -0
- package/es/address-plugin-north-america/src/AddressFieldsUSA.js +106 -0
- package/es/address-plugin-north-america/src/backendToFields.js +41 -0
- package/es/address-plugin-north-america/src/fieldOrder.js +15 -0
- package/es/address-plugin-north-america/src/fieldsToBackend.js +98 -0
- package/es/address-plugin-north-america/src/index.js +21 -0
- package/es/address-plugin-north-america/src/listOfSupportedCountries.js +8 -0
- package/es/address-utils/index.js +16 -0
- package/es/address-utils/src/deleteFieldIfExists.js +17 -0
- package/es/address-utils/src/getExistingLineField.js +14 -0
- package/es/address-utils/src/index.js +27 -0
- package/es/address-utils/src/requiredValidator.js +20 -0
- package/es/index.js +31 -0
- package/package.json +65 -0
- package/src/address-plugin-british-isles/README.md +31 -0
- package/src/address-plugin-british-isles/index.js +1 -0
- package/src/address-plugin-british-isles/src/AddressFieldsGBR.js +88 -0
- package/src/address-plugin-british-isles/src/backendToFields.js +43 -0
- package/src/address-plugin-british-isles/src/fieldOrder.js +11 -0
- package/src/address-plugin-british-isles/src/fieldsToBackend.js +51 -0
- package/src/address-plugin-british-isles/src/index.js +9 -0
- package/src/address-plugin-british-isles/src/listOfSupportedCountries.js +3 -0
- package/src/address-plugin-generic/README.md +6 -0
- package/src/address-plugin-generic/index.js +1 -0
- package/src/address-plugin-generic/src/AddressFieldsGeneric.js +112 -0
- package/src/address-plugin-generic/src/backendToFields.js +51 -0
- package/src/address-plugin-generic/src/fieldOrder.js +14 -0
- package/src/address-plugin-generic/src/fieldsToBackend.js +68 -0
- package/src/address-plugin-generic/src/index.js +9 -0
- package/src/address-plugin-generic/src/listOfSupportedCountries.js +3 -0
- package/src/address-plugin-north-america/README.md +33 -0
- package/src/address-plugin-north-america/index.js +1 -0
- package/src/address-plugin-north-america/src/AddressFieldsUSA.js +85 -0
- package/src/address-plugin-north-america/src/backendToFields.js +40 -0
- package/src/address-plugin-north-america/src/fieldOrder.js +10 -0
- package/src/address-plugin-north-america/src/fieldsToBackend.js +50 -0
- package/src/address-plugin-north-america/src/index.js +8 -0
- package/src/address-plugin-north-america/src/listOfSupportedCountries.js +2 -0
- package/src/address-utils/README.md +40 -0
- package/src/address-utils/index.js +1 -0
- package/src/address-utils/src/deleteFieldIfExists.js +8 -0
- package/src/address-utils/src/getExistingLineField.js +8 -0
- package/src/address-utils/src/index.js +5 -0
- package/src/address-utils/src/requiredValidator.js +12 -0
- package/src/index.js +4 -0
- package/translations/ui-address-plugins/ar.json +38 -0
- package/translations/ui-address-plugins/ca.json +1 -0
- package/translations/ui-address-plugins/cs_CZ.json +38 -0
- package/translations/ui-address-plugins/da.json +38 -0
- package/translations/ui-address-plugins/de.json +38 -0
- package/translations/ui-address-plugins/en.json +44 -0
- package/translations/ui-address-plugins/en_US.json +1 -0
- package/translations/ui-address-plugins/es.json +38 -0
- package/translations/ui-address-plugins/fr.json +38 -0
- package/translations/ui-address-plugins/hi_IN.json +38 -0
- package/translations/ui-address-plugins/hu.json +38 -0
- package/translations/ui-address-plugins/it_IT.json +38 -0
- package/translations/ui-address-plugins/ja.json +38 -0
- package/translations/ui-address-plugins/ko.json +1 -0
- package/translations/ui-address-plugins/nb.json +1 -0
- package/translations/ui-address-plugins/nn.json +1 -0
- package/translations/ui-address-plugins/pl.json +38 -0
- package/translations/ui-address-plugins/pt_PT.json +38 -0
- package/translations/ui-address-plugins/ru.json +38 -0
- package/translations/ui-address-plugins/sv.json +38 -0
- package/translations/ui-address-plugins/ur.json +1 -0
- package/translations/ui-address-plugins/zh_CN.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# address-plugins
|
|
6
|
+
|
|
7
|
+
This is a set of React plugins designed to try and make internationalisation of address forms as easy and simple as possible. It was designed to mesh with a backend inspired by the [OASIS CIQ TC Standard xAL.](https://www.immagic.com/eLibrary/ARCHIVES/TECH/OASIS/XAL_V2.PDF)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
These are React NPM plugins, and as such, you will need to include it in you project's package.json file.
|
|
11
|
+
Too get a form up and running is:
|
|
12
|
+
```
|
|
13
|
+
"@k-int/address-plugins": "^1.0.0",
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
To call these plugins in your code, you would then include:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
import {pluginGeneric} from '@k-int/address-plugins';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
and call `<pluginGeneric.addressFields>`, say, to use the component `AddressFields` for this plugin.
|
|
23
|
+
|
|
24
|
+
## Motivation
|
|
25
|
+
When researching address forms, we came across the problem that addresses are constructed differently all over the world. The standard mentioned in the link above aims to solve this problem. However in constructing a frontend to match this kind of data model, we realised that this must be a problem that crops up a lot, and so decided to write as standalone code as possible, so that our solution can be reused in other applications.
|
|
26
|
+
|
|
27
|
+
## Data Model
|
|
28
|
+
The particular flavour of address model our backend uses comprises of an `Address`, containing many `AddressLines`, an `AddressLabel` string and a `CountryCode` string, corresponding to an ISO 3166-2 code (Or `"generic")`.
|
|
29
|
+
`AddressLines` contain
|
|
30
|
+
- a `value` String
|
|
31
|
+
- a `type` RefdataValue, taking one of the values:
|
|
32
|
+
```
|
|
33
|
+
- AdministrativeArea
|
|
34
|
+
- Country
|
|
35
|
+
- Department
|
|
36
|
+
- Thoroughfare
|
|
37
|
+
- Locality
|
|
38
|
+
- PostalCode
|
|
39
|
+
- PostBox
|
|
40
|
+
- PostOffice
|
|
41
|
+
- PostalCodeOrTown
|
|
42
|
+
- Premise
|
|
43
|
+
```
|
|
44
|
+
It is heavily recommended that any potential user do some reading of the standard above in order to understand what each of these can mean/be used for.
|
|
45
|
+
|
|
46
|
+
:warning: This backend setup has an important restriction, in that each address is supposed to be limited to **ONE** of any given type of `AddressLine`. The ways in which the various types can be used is expanded on in the standard. :warning:
|
|
47
|
+
|
|
48
|
+
### Dealing with deletion registration
|
|
49
|
+
We have built this in so instead of simply omitting a field from a form on deletion, we send the field with a `_delete: true` flag. This may not exactly match your backend configuration for dealing with this, and so you may need to write your own interpreters for the form's output.
|
|
50
|
+
|
|
51
|
+
## The plugin
|
|
52
|
+
Each plugin, say `address-plugin-generic` or `address-plugin-north-america`, is named for a particular "sensible" domain sharing an address format.
|
|
53
|
+
For example the addresses of the US and Canada are similar, up to field names, and so it makes sense to bundle these together. Similarly most of the British Isles share an address format, and so there is a single plugin for those.
|
|
54
|
+
The definition of sensible is really up to whoever is writing the particular plugin, but a good rule of thumb would be to stick within continents at the highest level, and nations at the lowest level.
|
|
55
|
+
|
|
56
|
+
A plugin shouldn't have to be smart enough to deal with hundreds of address formats, `address-plugin-africa` is probably too ambitious of a scope, but should be smart enough to deal with changes within a nation, you don't want 4 plugins `address-plugin-foo-north`, `address-plugin-foo-south`, `address-plugin-foo-east`, `address-plugin-foo-west`. That should be dealt with internally.
|
|
57
|
+
|
|
58
|
+
:warning: Note to developers. If you wish to develop a plugin to fit into this set, it is highly recommended that you spend some time looking at an existing plugin to see exactly what you'll have to mirror. :warning:
|
|
59
|
+
|
|
60
|
+
### AddressFields
|
|
61
|
+
First and foremost is an `AddressFields` component,
|
|
62
|
+
which returns a collection of `AddressFieldsComponent`s, formatted in a [`react-flexbox-grid`](https://roylee0704.github.io/react-flexbox-grid/) layout.
|
|
63
|
+
These supply regular "field" information per entry for the given country address format, but it is expected that the calling code provides the `AddressTextField`, allowing for varying Form implementations (final-form etc.).
|
|
64
|
+
|
|
65
|
+
These fields will tend to stick to the field names as detailed above, so that you can expect a submitted object to look like:
|
|
66
|
+
```
|
|
67
|
+
address: {
|
|
68
|
+
premise: "<user input>",
|
|
69
|
+
thoroughfare: "<user input>",
|
|
70
|
+
...
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
and so on. There are some exceptions to this, which individual plugin READMEs should detail.
|
|
74
|
+
|
|
75
|
+
#### Props
|
|
76
|
+
`AddressField` takes 5 props:
|
|
77
|
+
- AddressTextField
|
|
78
|
+
- country
|
|
79
|
+
- name
|
|
80
|
+
- requiredValidator
|
|
81
|
+
- savedAddress
|
|
82
|
+
|
|
83
|
+
**Country**
|
|
84
|
+
In those cases where a single plugin is used for multiple different countries, the `country` prop will be used to call the correct field labels. For example in `address-plugin-north-america` passing `country="Canada"` will result in the `AdministrativeArea` field being labelled `Province`, and passing `country="USA"` will result in `AdministrativeArea` field being labelled `State`.
|
|
85
|
+
|
|
86
|
+
This happens via React-Intl's `FormattedMessage` component. Wherever a plugin's field names may need to change country by country, the field labels should be called in the following way:
|
|
87
|
+
```
|
|
88
|
+
label={<FormattedMessage id={`ui-address-plugin-north-america.${country}.locality`} />}
|
|
89
|
+
```
|
|
90
|
+
The acceptable inputs for `country` here should match the outputted `listOfSupportedCountries`.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
When a country is selected, the `country` field should pre-populate with the chosen country's translated name. If `country` was explicitly passed in with the `savedAddress` however, that data will take precedence.
|
|
94
|
+
|
|
95
|
+
**Name**
|
|
96
|
+
`name` will be prepended to the field names, such as `"${name}.locality"` etc.
|
|
97
|
+
|
|
98
|
+
For example you might want to call:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
<plugin.addressFields
|
|
102
|
+
name="address"
|
|
103
|
+
...
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
106
|
+
if these address fields sit within a larger form and you wish to group their output together together or `name={"address[index]}` if you need an array of them.
|
|
107
|
+
|
|
108
|
+
In these examples the output would take the shape:
|
|
109
|
+
```
|
|
110
|
+
address: {
|
|
111
|
+
locality: "foo",
|
|
112
|
+
postalCode: "bar"
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
or
|
|
116
|
+
```
|
|
117
|
+
address: [
|
|
118
|
+
{
|
|
119
|
+
locality: "foo",
|
|
120
|
+
postalCode: "bar"
|
|
121
|
+
},
|
|
122
|
+
...
|
|
123
|
+
]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
**RequiredValidator**
|
|
128
|
+
`requiredValidator` takes a function, which will be run on each field marked as `required`. A simple example might be
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
const required = value => (
|
|
132
|
+
!value ? "missing value" : undefined
|
|
133
|
+
);
|
|
134
|
+
```
|
|
135
|
+
This would then flag any `required` fields missing data with the text `missing value` on submittal.
|
|
136
|
+
|
|
137
|
+
The idea here is that if your function returns a falsy value then validation is deemed to have passed.
|
|
138
|
+
|
|
139
|
+
**SavedAddress**
|
|
140
|
+
`savedAddress` takes an address object of the [correct shape](#address-shape), which it will then pass to `backendToFields`, and finally be used line by line to fill out the initialValues for each line's Field.
|
|
141
|
+
|
|
142
|
+
**AddressTextField**
|
|
143
|
+
Finally, `AddressTextField` is what will actually be displayed as an input box. Simplest case is
|
|
144
|
+
```
|
|
145
|
+
<plugin.AddressField
|
|
146
|
+
AddressTextField={(props) => <input {...props}/>}
|
|
147
|
+
...
|
|
148
|
+
/>
|
|
149
|
+
```
|
|
150
|
+
You can pass a custom component here if you wish, wrapped in a final-form `<Field>` or otherwise.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
#### Field labels
|
|
154
|
+
Right now we only have internationalised field labels for en_US, and there may be some work to do on your project's end to utilise those. The idea in future is that if you were accessing `address-plugin-north-america` US fields from France, that you would see "Etat" in place of "State", or if you were accessing the `address-plugin-north-america` Canada fields from
|
|
155
|
+
Germany you'd see "Provinz" in place of "Province".
|
|
156
|
+
|
|
157
|
+
### backendToFields
|
|
158
|
+
|
|
159
|
+
This is a function: `backendToFields` that the `AddressFields` component uses to massage the data held in `savedAddress` into a shape the fields can read and use as initial values for the form. It accepts addresses of the [correct shape](#address-shape).
|
|
160
|
+
|
|
161
|
+
### fieldsToBackend
|
|
162
|
+
This is a function: `fieldsToBackend` that does the opposite, takes the output from the fields, and reshapes it into something the backend will accept. In the most basic case, the plugin for `"Foo"` will simply take the flattened `{premise: "A", locality: "B", ...}` shape and translate that to
|
|
163
|
+
```
|
|
164
|
+
{
|
|
165
|
+
countryCode: "foo",
|
|
166
|
+
lines: [
|
|
167
|
+
{
|
|
168
|
+
type: {
|
|
169
|
+
value: "Premise",
|
|
170
|
+
},
|
|
171
|
+
value: "A"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: {
|
|
175
|
+
value: "Locality",
|
|
176
|
+
},
|
|
177
|
+
value: "B"
|
|
178
|
+
},
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
In the cases though where a field is _not_ required, it will do the above if a field is filled, else call an `address-utils` function, `deleteFieldIfExists`, to remove any existing data. This is the part that may not be compatible with all backend setups, so extra massaging may be required.
|
|
183
|
+
|
|
184
|
+
Extra magic might occur here, but that should be covered in each `address-plugin`'s README.
|
|
185
|
+
|
|
186
|
+
### listOfSupportedCountries
|
|
187
|
+
This is simply an array, containing a list of countries for which this plugin supports.
|
|
188
|
+
This list **MUST** contain the ISO 3166-2 codes of countries the plugin supports. For example the output for `address-plugin-british-isles` is `["GB-ENG", "GB-SCT", "GB-WLS", "GB-NIR"]`, and the output for `address-plugin-north-america` is `["US", "CA"]`. These are used for the plugin translations (where there is a need to differ by country), e.g. `"US.countryCode": "USA",` and `"CA.administrativeArea": "Province",`
|
|
189
|
+
|
|
190
|
+
### fieldOrder
|
|
191
|
+
This is an object, with keys corresponding to the standard addressLine types [above](#data-model), and values corresponding to their ordering in a written address.
|
|
192
|
+
For example the `address-plugin-british-isles` `fieldOrder` object looks like this:
|
|
193
|
+
```
|
|
194
|
+
const fieldOrder = {
|
|
195
|
+
"Premise": 0,
|
|
196
|
+
"Thoroughfare": 1,
|
|
197
|
+
"PostalCodeOrTown": 2,
|
|
198
|
+
"Locality": 3,
|
|
199
|
+
"AdministrativeArea": 4,
|
|
200
|
+
"PostalCode": 5,
|
|
201
|
+
"Country": 6
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
The ordering should match the order you'd expect to see those fields in if you were to display the address.
|
|
205
|
+
|
|
206
|
+
We can then use this for building the address later in a `ViewAddress` component (FUTURE RELEASE), or potentially use it to save the order to the backend, if that's something your backend necessitates.
|
|
207
|
+
|
|
208
|
+
It's shaped like this as it seemed preferable to search for a key and return a value than to iterate over an array such as `[Premise, Thoroughfare,...]` and return an index.
|
|
209
|
+
|
|
210
|
+
### pluginName
|
|
211
|
+
Finally we also export a simple String containing the plugin's name, i.e. `address-plugin-north-america`. This can be used to access the plugin's own translation codes inside your own project.
|
|
212
|
+
|
|
213
|
+
## Address Shape
|
|
214
|
+
|
|
215
|
+
The minimum shape expected by the frontend fields is:
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
{
|
|
219
|
+
countryCode: "GB-ENG"
|
|
220
|
+
lines: [
|
|
221
|
+
{
|
|
222
|
+
id: "some_id",
|
|
223
|
+
type: {
|
|
224
|
+
value: "department"
|
|
225
|
+
},
|
|
226
|
+
value: "Shipping department"
|
|
227
|
+
},
|
|
228
|
+
...
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
with each `AddressLine` being an object on the `lines` array, comprising of an `id`, a `type` object containing a `value` string, and a `value` string itself.
|
|
233
|
+
|
|
234
|
+
A saved address is expected to have a `countryCode`, in ISO 3166-2 form. The above example is the subdivided code for England, which we use here in place of the general ISO code `GB` for greater specification.
|
|
235
|
+
|
|
236
|
+
## Known Issues
|
|
237
|
+
When changing an address's country format to one with more fields, everything _should_ work as expected. However, we currently don't have a built in process to remove fields that a particular format might not include.
|
|
238
|
+
|
|
239
|
+
For example, filling out a UK address with a `Town` field will place that information into a `postalCodeOrTown` `AddressLine`, but then switching that address to a US one, the field will be missing from the form, but the backend data massagers do not know to remove something from `postalCodeOrTown` if it exists. This is not priority work for now, but shouldn't be too hard to fix.
|
|
240
|
+
|
|
241
|
+
### Labelling
|
|
242
|
+
Labels are currently automagically included in an existing react-intl scope. This will in a future update be _removed_ in favour of the calling implementation handling labelling itself, keeping this as a "dumb" implementation with NO external knowledge of the system above.
|
|
243
|
+
|
|
244
|
+
## Other READMEs
|
|
245
|
+
As mentioned above, this is really a _set_ of plugins and components, so I'll include here links to all the specific READMEs for the individual plugins/repos, and attempt to keep it up to date as new ones are added.
|
|
246
|
+
|
|
247
|
+
- [address-utils](https://gitlab.com/knowledge-integration/folio/addressplugins/-/blob/main/address-utils/README.md)
|
|
248
|
+
- [address-plugin-north-america](https://gitlab.com/knowledge-integration/folio/addressplugins/-/blob/main/address-plugin-north-america/README.md)
|
|
249
|
+
- [address-plugin-british-isles](https://gitlab.com/knowledge-integration/folio/addressplugins/-/blob/main/address-plugin-british-isles/README.md)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _src.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _src = _interopRequireDefault(require("./src"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _reactIntl = require("react-intl");
|
|
9
|
+
var _reactFlexboxGrid = require("react-flexbox-grid");
|
|
10
|
+
var _addressUtils = require("../../address-utils");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
const AddressFieldsGBR = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
AddressTextField,
|
|
16
|
+
name
|
|
17
|
+
} = _ref;
|
|
18
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
19
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactFlexboxGrid.Row, {
|
|
20
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
21
|
+
xs: 4,
|
|
22
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
23
|
+
name: name ? "".concat(name, ".premise") : 'premise',
|
|
24
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
25
|
+
id: "ui-address-plugins.GBR.premise"
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
29
|
+
xs: 4,
|
|
30
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
31
|
+
name: name ? "".concat(name, ".thoroughfare") : 'thoroughfare',
|
|
32
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
33
|
+
id: "ui-address-plugins.GBR.thoroughfare"
|
|
34
|
+
}),
|
|
35
|
+
required: true,
|
|
36
|
+
validator: _addressUtils.requiredValidator
|
|
37
|
+
})
|
|
38
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
39
|
+
xs: 4,
|
|
40
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
41
|
+
name: name ? "".concat(name, ".postalCodeOrTown") : 'postalCodeOrTown',
|
|
42
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
43
|
+
id: "ui-address-plugins.GBR.postalCodeOrTown"
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
})]
|
|
47
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactFlexboxGrid.Row, {
|
|
48
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
49
|
+
xs: 4,
|
|
50
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
51
|
+
name: name ? "".concat(name, ".locality") : 'locality',
|
|
52
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
53
|
+
id: "ui-address-plugins.GBR.locality"
|
|
54
|
+
}),
|
|
55
|
+
required: true,
|
|
56
|
+
validator: _addressUtils.requiredValidator
|
|
57
|
+
})
|
|
58
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
59
|
+
xs: 4,
|
|
60
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
61
|
+
name: name ? "".concat(name, ".administrativeArea") : 'administrativeArea',
|
|
62
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
63
|
+
id: "ui-address-plugins.GBR.administrativeArea"
|
|
64
|
+
}),
|
|
65
|
+
required: true,
|
|
66
|
+
validator: _addressUtils.requiredValidator
|
|
67
|
+
})
|
|
68
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
69
|
+
xs: 4,
|
|
70
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
71
|
+
name: name ? "".concat(name, ".postalCode") : 'postalCode',
|
|
72
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
73
|
+
id: "ui-address-plugins.GBR.postalCode"
|
|
74
|
+
}),
|
|
75
|
+
required: true,
|
|
76
|
+
validator: _addressUtils.requiredValidator
|
|
77
|
+
})
|
|
78
|
+
})]
|
|
79
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Row, {
|
|
80
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFlexboxGrid.Col, {
|
|
81
|
+
xs: 12,
|
|
82
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AddressTextField, {
|
|
83
|
+
name: name ? "".concat(name, ".country") : 'country',
|
|
84
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
85
|
+
id: "ui-address-plugins.GBR.country"
|
|
86
|
+
}),
|
|
87
|
+
required: true,
|
|
88
|
+
validator: _addressUtils.requiredValidator
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})]
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
AddressFieldsGBR.propTypes = {
|
|
95
|
+
AddressTextField: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
|
|
96
|
+
name: _propTypes.default.string,
|
|
97
|
+
savedAddress: _propTypes.default.shape({
|
|
98
|
+
addressLabel: _propTypes.default.string,
|
|
99
|
+
countryCode: _propTypes.default.string,
|
|
100
|
+
id: _propTypes.default.string,
|
|
101
|
+
lines: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
102
|
+
id: _propTypes.default.string.isRequired,
|
|
103
|
+
type: _propTypes.default.shape({
|
|
104
|
+
value: _propTypes.default.string.isRequired
|
|
105
|
+
}).isRequired,
|
|
106
|
+
value: _propTypes.default.string.isRequired
|
|
107
|
+
}))
|
|
108
|
+
})
|
|
109
|
+
};
|
|
110
|
+
var _default = exports.default = AddressFieldsGBR;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _addressUtils = require("../../address-utils");
|
|
8
|
+
const backendToFields = address => {
|
|
9
|
+
var _getExistingLineField, _getExistingLineField2, _getExistingLineField3, _getExistingLineField4, _getExistingLineField5, _getExistingLineField6, _getExistingLineField7;
|
|
10
|
+
const addressFields = {};
|
|
11
|
+
const premise = (_getExistingLineField = (0, _addressUtils.getExistingLineField)(address.lines, 'premise')) === null || _getExistingLineField === void 0 ? void 0 : _getExistingLineField.value;
|
|
12
|
+
const thoroughfare = (_getExistingLineField2 = (0, _addressUtils.getExistingLineField)(address.lines, 'thoroughfare')) === null || _getExistingLineField2 === void 0 ? void 0 : _getExistingLineField2.value;
|
|
13
|
+
const postalCodeOrTown = (_getExistingLineField3 = (0, _addressUtils.getExistingLineField)(address.lines, 'postalcodeortown')) === null || _getExistingLineField3 === void 0 ? void 0 : _getExistingLineField3.value;
|
|
14
|
+
const locality = (_getExistingLineField4 = (0, _addressUtils.getExistingLineField)(address.lines, 'locality')) === null || _getExistingLineField4 === void 0 ? void 0 : _getExistingLineField4.value;
|
|
15
|
+
const postalCode = (_getExistingLineField5 = (0, _addressUtils.getExistingLineField)(address.lines, 'postalcode')) === null || _getExistingLineField5 === void 0 ? void 0 : _getExistingLineField5.value;
|
|
16
|
+
const administrativeArea = (_getExistingLineField6 = (0, _addressUtils.getExistingLineField)(address.lines, 'administrativearea')) === null || _getExistingLineField6 === void 0 ? void 0 : _getExistingLineField6.value;
|
|
17
|
+
const country = (_getExistingLineField7 = (0, _addressUtils.getExistingLineField)(address.lines, 'country')) === null || _getExistingLineField7 === void 0 ? void 0 : _getExistingLineField7.value;
|
|
18
|
+
const countryCode = address === null || address === void 0 ? void 0 : address.countryCode;
|
|
19
|
+
if (premise) {
|
|
20
|
+
addressFields.premise = premise;
|
|
21
|
+
}
|
|
22
|
+
if (thoroughfare) {
|
|
23
|
+
addressFields.thoroughfare = thoroughfare;
|
|
24
|
+
}
|
|
25
|
+
if (postalCodeOrTown) {
|
|
26
|
+
addressFields.postalCodeOrTown = postalCodeOrTown;
|
|
27
|
+
}
|
|
28
|
+
if (locality) {
|
|
29
|
+
addressFields.locality = locality;
|
|
30
|
+
}
|
|
31
|
+
if (postalCode) {
|
|
32
|
+
addressFields.postalCode = postalCode;
|
|
33
|
+
}
|
|
34
|
+
if (administrativeArea) {
|
|
35
|
+
addressFields.administrativeArea = administrativeArea;
|
|
36
|
+
}
|
|
37
|
+
if (country) {
|
|
38
|
+
addressFields.country = country;
|
|
39
|
+
}
|
|
40
|
+
if (countryCode) {
|
|
41
|
+
addressFields.countryCode = countryCode;
|
|
42
|
+
}
|
|
43
|
+
return addressFields;
|
|
44
|
+
};
|
|
45
|
+
var _default = exports.default = backendToFields;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const fieldOrder = {
|
|
8
|
+
'Premise': 0,
|
|
9
|
+
'Thoroughfare': 1,
|
|
10
|
+
'PostalCodeOrTown': 2,
|
|
11
|
+
'Locality': 3,
|
|
12
|
+
'AdministrativeArea': 4,
|
|
13
|
+
'PostalCode': 5,
|
|
14
|
+
'Country': 6
|
|
15
|
+
};
|
|
16
|
+
var _default = exports.default = fieldOrder;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _addressUtils = require("../../address-utils");
|
|
8
|
+
const fieldsToBackend = address => {
|
|
9
|
+
const addressId = address.id || null;
|
|
10
|
+
const countryCode = address.countryCode || null;
|
|
11
|
+
const newAddress = {};
|
|
12
|
+
let lines = [];
|
|
13
|
+
if (address.premise) {
|
|
14
|
+
var _getExistingLineField;
|
|
15
|
+
const id = (_getExistingLineField = (0, _addressUtils.getExistingLineField)(address.lines, 'premise')) === null || _getExistingLineField === void 0 ? void 0 : _getExistingLineField.id;
|
|
16
|
+
lines.push({
|
|
17
|
+
type: {
|
|
18
|
+
value: 'Premise'
|
|
19
|
+
},
|
|
20
|
+
value: address.premise,
|
|
21
|
+
id
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
lines.push((0, _addressUtils.deleteFieldIfExists)(address.lines, 'premise'));
|
|
25
|
+
}
|
|
26
|
+
if (address.thoroughfare) {
|
|
27
|
+
var _getExistingLineField2;
|
|
28
|
+
const id = (_getExistingLineField2 = (0, _addressUtils.getExistingLineField)(address.lines, 'thoroughfare')) === null || _getExistingLineField2 === void 0 ? void 0 : _getExistingLineField2.id;
|
|
29
|
+
lines.push({
|
|
30
|
+
type: {
|
|
31
|
+
value: 'Thoroughfare'
|
|
32
|
+
},
|
|
33
|
+
value: address.thoroughfare,
|
|
34
|
+
id
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (address.postalCodeOrTown) {
|
|
38
|
+
var _getExistingLineField3;
|
|
39
|
+
const id = (_getExistingLineField3 = (0, _addressUtils.getExistingLineField)(address.lines, 'postalcodeortown')) === null || _getExistingLineField3 === void 0 ? void 0 : _getExistingLineField3.id;
|
|
40
|
+
lines.push({
|
|
41
|
+
type: {
|
|
42
|
+
value: 'PostalCodeOrTown'
|
|
43
|
+
},
|
|
44
|
+
value: address.postalCodeOrTown,
|
|
45
|
+
id
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
lines.push((0, _addressUtils.deleteFieldIfExists)(address.lines, 'postalcodeortown'));
|
|
49
|
+
}
|
|
50
|
+
if (address.locality) {
|
|
51
|
+
var _getExistingLineField4;
|
|
52
|
+
const id = (_getExistingLineField4 = (0, _addressUtils.getExistingLineField)(address.lines, 'locality')) === null || _getExistingLineField4 === void 0 ? void 0 : _getExistingLineField4.id;
|
|
53
|
+
lines.push({
|
|
54
|
+
type: {
|
|
55
|
+
value: 'Locality'
|
|
56
|
+
},
|
|
57
|
+
value: address.locality,
|
|
58
|
+
id
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (address.administrativeArea) {
|
|
62
|
+
var _getExistingLineField5;
|
|
63
|
+
const id = (_getExistingLineField5 = (0, _addressUtils.getExistingLineField)(address.lines, 'administrativearea')) === null || _getExistingLineField5 === void 0 ? void 0 : _getExistingLineField5.id;
|
|
64
|
+
lines.push({
|
|
65
|
+
type: {
|
|
66
|
+
value: 'AdministrativeArea'
|
|
67
|
+
},
|
|
68
|
+
value: address.administrativeArea,
|
|
69
|
+
id
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (address.postalCode) {
|
|
73
|
+
var _getExistingLineField6;
|
|
74
|
+
const id = (_getExistingLineField6 = (0, _addressUtils.getExistingLineField)(address.lines, 'postalcode')) === null || _getExistingLineField6 === void 0 ? void 0 : _getExistingLineField6.id;
|
|
75
|
+
lines.push({
|
|
76
|
+
type: {
|
|
77
|
+
value: 'PostalCode'
|
|
78
|
+
},
|
|
79
|
+
value: address.postalCode,
|
|
80
|
+
id
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (address.country) {
|
|
84
|
+
var _getExistingLineField7;
|
|
85
|
+
const id = (_getExistingLineField7 = (0, _addressUtils.getExistingLineField)(address.lines, 'country')) === null || _getExistingLineField7 === void 0 ? void 0 : _getExistingLineField7.id;
|
|
86
|
+
lines.push({
|
|
87
|
+
type: {
|
|
88
|
+
value: 'Country'
|
|
89
|
+
},
|
|
90
|
+
value: address.country,
|
|
91
|
+
id
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
lines = lines.filter(line => line !== null);
|
|
95
|
+
newAddress.addressLabel = address.addressLabel;
|
|
96
|
+
newAddress.lines = lines;
|
|
97
|
+
newAddress.id = addressId;
|
|
98
|
+
newAddress.countryCode = countryCode;
|
|
99
|
+
return newAddress;
|
|
100
|
+
};
|
|
101
|
+
var _default = exports.default = fieldsToBackend;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _AddressFieldsGBR = _interopRequireDefault(require("./AddressFieldsGBR"));
|
|
8
|
+
var _fieldsToBackend = _interopRequireDefault(require("./fieldsToBackend"));
|
|
9
|
+
var _backendToFields = _interopRequireDefault(require("./backendToFields"));
|
|
10
|
+
var _listOfSupportedCountries = _interopRequireDefault(require("./listOfSupportedCountries"));
|
|
11
|
+
var _fieldOrder = _interopRequireDefault(require("./fieldOrder"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
const pluginName = 'address-plugin-british-isles';
|
|
14
|
+
var _default = exports.default = {
|
|
15
|
+
addressFields: _AddressFieldsGBR.default,
|
|
16
|
+
fieldsToBackend: _fieldsToBackend.default,
|
|
17
|
+
backendToFields: _backendToFields.default,
|
|
18
|
+
listOfSupportedCountries: _listOfSupportedCountries.default,
|
|
19
|
+
fieldOrder: _fieldOrder.default,
|
|
20
|
+
pluginName
|
|
21
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _src.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _src = _interopRequireDefault(require("./src"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|