@graphcommerce/address-fields-nl 5.2.0-canary.9 → 6.0.0-canary.21
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/CHANGELOG.md +24 -0
- package/helpers/usePostcodeService.ts +18 -12
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @graphcommerce/address-fields-nl
|
|
2
2
|
|
|
3
|
+
## 6.0.0-canary.21
|
|
4
|
+
|
|
5
|
+
## 6.0.0-canary.20
|
|
6
|
+
|
|
7
|
+
## 5.2.0-canary.19
|
|
8
|
+
|
|
9
|
+
## 5.2.0-canary.18
|
|
10
|
+
|
|
11
|
+
## 5.2.0-canary.17
|
|
12
|
+
|
|
13
|
+
## 5.2.0-canary.16
|
|
14
|
+
|
|
15
|
+
## 5.2.0-canary.15
|
|
16
|
+
|
|
17
|
+
## 5.2.0-canary.14
|
|
18
|
+
|
|
19
|
+
## 5.2.0-canary.13
|
|
20
|
+
|
|
21
|
+
## 5.2.0-canary.12
|
|
22
|
+
|
|
23
|
+
## 5.2.0-canary.11
|
|
24
|
+
|
|
25
|
+
## 5.2.0-canary.10
|
|
26
|
+
|
|
3
27
|
## 5.2.0-canary.9
|
|
4
28
|
|
|
5
29
|
## 5.2.0-canary.8
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useEffect } from
|
|
5
|
-
import { postcodeNLDocument } from
|
|
1
|
+
import { UseFormReturn } from '@graphcommerce/ecommerce-ui'
|
|
2
|
+
import { useLazyQuery } from '@graphcommerce/graphql'
|
|
3
|
+
import { AddressFieldValues } from '@graphcommerce/magento-customer'
|
|
4
|
+
import { useEffect } from 'react'
|
|
5
|
+
import { postcodeNLDocument } from '../graphql/PostcodeNL.gql'
|
|
6
6
|
|
|
7
7
|
const postCodeRegex = /^[1-9][0-9]{3}[a-z]{2}$/i
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
const defaultPostcodeFieldnames = {
|
|
11
10
|
postcode: 'postcode',
|
|
12
11
|
houseNumber: 'houseNumber',
|
|
@@ -17,7 +16,7 @@ const defaultPostcodeFieldnames = {
|
|
|
17
16
|
|
|
18
17
|
export function usePostcodeService(
|
|
19
18
|
form: UseFormReturn<any>,
|
|
20
|
-
fieldNames: AddressFieldValues = defaultPostcodeFieldnames
|
|
19
|
+
fieldNames: AddressFieldValues = defaultPostcodeFieldnames,
|
|
21
20
|
) {
|
|
22
21
|
const { watch, setValue, resetField } = form
|
|
23
22
|
|
|
@@ -27,9 +26,16 @@ export function usePostcodeService(
|
|
|
27
26
|
const [execute, result] = useLazyQuery(postcodeNLDocument)
|
|
28
27
|
|
|
29
28
|
useEffect(() => {
|
|
30
|
-
if (!houseNumber || !postcode || !postCodeRegex.test(postcode.trim().replace(/ /g, '')))
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (!houseNumber || !postcode || !postCodeRegex.test(postcode.trim().replace(/ /g, '')))
|
|
30
|
+
return () => {}
|
|
31
|
+
|
|
32
|
+
const handler = () =>
|
|
33
|
+
execute({
|
|
34
|
+
variables: {
|
|
35
|
+
postcode: postcode.trim().replace(/ /g, ''),
|
|
36
|
+
housenumber: addition ? houseNumber + addition : houseNumber,
|
|
37
|
+
},
|
|
38
|
+
})
|
|
33
39
|
const clear = setTimeout(handler, 300)
|
|
34
40
|
|
|
35
41
|
return () => clearInterval(clear)
|
|
@@ -48,8 +54,8 @@ export function usePostcodeService(
|
|
|
48
54
|
setValue(fieldNames.city ?? '', city, { shouldValidate: true })
|
|
49
55
|
} else {
|
|
50
56
|
resetField(fieldNames.street ?? '')
|
|
51
|
-
resetField(fieldNames.city?? '')
|
|
57
|
+
resetField(fieldNames.city ?? '')
|
|
52
58
|
}
|
|
53
59
|
}, [result.data?.postcodeNL, setValue, resetField, fieldNames.street, fieldNames.city])
|
|
54
60
|
return [result.data?.postcodeNL, result.loading] as const
|
|
55
|
-
}
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/address-fields-nl",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "6.0.0-canary.21",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,22 +12,22 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "
|
|
16
|
-
"@graphcommerce/prettier-config-pwa": "
|
|
17
|
-
"@graphcommerce/typescript-config-pwa": "
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "6.0.0-canary.21",
|
|
16
|
+
"@graphcommerce/prettier-config-pwa": "6.0.0-canary.21",
|
|
17
|
+
"@graphcommerce/typescript-config-pwa": "6.0.0-canary.21"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@graphcommerce/ecommerce-ui": "
|
|
21
|
-
"@graphcommerce/graphql": "
|
|
22
|
-
"@graphcommerce/magento-customer": "
|
|
23
|
-
"@graphcommerce/magento-store": "
|
|
24
|
-
"@graphcommerce/next-ui": "
|
|
20
|
+
"@graphcommerce/ecommerce-ui": "6.0.0-canary.21",
|
|
21
|
+
"@graphcommerce/graphql": "6.0.0-canary.21",
|
|
22
|
+
"@graphcommerce/magento-customer": "6.0.0-canary.21",
|
|
23
|
+
"@graphcommerce/magento-store": "6.0.0-canary.21",
|
|
24
|
+
"@graphcommerce/next-ui": "6.0.0-canary.21"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@lingui/react": "^3.13.2",
|
|
28
28
|
"@lingui/core": "^3.13.2",
|
|
29
29
|
"@mui/material": "^5.10.16",
|
|
30
|
-
"next": "^
|
|
30
|
+
"next": "^13.1.1",
|
|
31
31
|
"react": "^18.2.0",
|
|
32
32
|
"react-dom": "^18.2.0"
|
|
33
33
|
}
|