@nuskin/address-lookup 1.0.0 → 1.0.1-pa-1033.2
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/package.json
CHANGED
package/src/AddressLookup.jsx
CHANGED
|
@@ -3,23 +3,25 @@ import EgonResults from './components/EgonResults.jsx';
|
|
|
3
3
|
import SmartyResults from './components/SmartyResults.jsx';
|
|
4
4
|
import { COUNTRY_MAP } from './countries';
|
|
5
5
|
|
|
6
|
-
const AddressLookup = ({ onAddressSelect }) => {
|
|
7
|
-
const [countryCode, setCountryCode] = useState(
|
|
6
|
+
const AddressLookup = ({ onAddressSelect, country = 'US', showCountrySelection = true }) => {
|
|
7
|
+
const [countryCode, setCountryCode] = useState(country);
|
|
8
8
|
|
|
9
9
|
return (
|
|
10
10
|
<div>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
{showCountrySelection && (
|
|
12
|
+
<select
|
|
13
|
+
value={countryCode}
|
|
14
|
+
onChange={(e) => setCountryCode(e.target.value)}
|
|
15
|
+
style={{ marginBottom: '20px', padding: '8px' }}
|
|
16
|
+
>
|
|
17
|
+
<option value="">Select Country</option>
|
|
18
|
+
{Object.entries(COUNTRY_MAP).map(([code, country]) => (
|
|
19
|
+
<option key={code} value={code}>
|
|
20
|
+
{country.name}
|
|
21
|
+
</option>
|
|
22
|
+
))}
|
|
23
|
+
</select>
|
|
24
|
+
)}
|
|
23
25
|
|
|
24
26
|
<div style={{ display: 'flex', gap: '20px' }}>
|
|
25
27
|
<EgonResults countryCode={countryCode} onSelect={onAddressSelect} />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import useEgonLookup from '
|
|
3
|
-
import useEgonNormalize from '
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import useEgonLookup from '../hooks/useEgonLookup.jsx';
|
|
3
|
+
import useEgonNormalize from '../hooks/useEgonNormalize.jsx';
|
|
4
4
|
|
|
5
5
|
const EgonResults = ({ countryCode, onSelect }) => {
|
|
6
6
|
const [query, setQuery] = useState('');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import useSmartyUSLookup from '
|
|
3
|
-
import useSmartyInternationalLookup from '
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import useSmartyUSLookup from '../hooks/useSmartyUSLookup.jsx';
|
|
3
|
+
import useSmartyInternationalLookup from '../hooks/useSmartyInternationalLookup.jsx';
|
|
4
4
|
|
|
5
5
|
const SmartyResults = ({ countryCode, onSelect }) => {
|
|
6
6
|
const [query, setQuery] = useState('');
|
|
@@ -22,7 +22,7 @@ const SmartyResults = ({ countryCode, onSelect }) => {
|
|
|
22
22
|
error: smartyIntlError,
|
|
23
23
|
responseTime: smartyIntlResponseTime
|
|
24
24
|
} = useSmartyInternationalLookup(!isUS ? query : '', countryCode, selectedIntlAddressId, 300);
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
const suggestions = isUS ? smartyUSSuggestions : smartyIntlSuggestions;
|
|
27
27
|
const loading = isUS ? smartyUSLoading : smartyIntlLoading;
|
|
28
28
|
const error = isUS ? smartyUSError : smartyIntlError;
|
|
@@ -23,7 +23,7 @@ const useEgonLookup = (query, countryCode = '', debounceMs = 300) => {
|
|
|
23
23
|
const timer = setTimeout(async () => {
|
|
24
24
|
try {
|
|
25
25
|
const iso3 = COUNTRY_MAP[countryCode].iso3;
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
const startTime = performance.now();
|
|
28
28
|
const response = await axios.post(
|
|
29
29
|
'https://egonapis.egoncloud.com:1257/Egon/api/single-line/full-address',
|