Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit d344c8d

Browse files
David AleknaDavid Alekna
authored andcommitted
lookup api config
1 parent 74a58aa commit d344c8d

7 files changed

Lines changed: 37 additions & 28 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ docs.json
6565
.docz/public
6666
.idea/
6767

68-
68+
# Env variables
69+
.env
6970

7071
junit.xml
7172

docs/Playground.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Playground as DoczPlayground } from 'docz';
33
import { CssResets } from '../packages/theming/src';
4+
import fetch from 'node-fetch';
45

56
export const Playground = (props) => {
67
return (
@@ -9,3 +10,14 @@ export const Playground = (props) => {
910
</CssResets>
1011
);
1112
};
13+
14+
console.log(process.env);
15+
16+
export const experianApiGet = (endpoint) => {
17+
return fetch(`https://api.edq.com/capture/address/v2/${endpoint}`, {
18+
method: 'get',
19+
headers: {
20+
'Auth-Token': process.env.DOCZ_LOOKUP_API_URL,
21+
},
22+
}).then((resp) => resp.json());
23+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"jest": "^26.0.1",
5555
"lerna": "^3.19.0",
5656
"lerna-changelog": "^1.0.0",
57+
"node-fetch": "^2.6.0",
5758
"node-sass": "^4.14.0",
5859
"npm-run-all": "^4.1.5",
5960
"prettier": "^2.0.4",

packages/layout/src/components/cards/trustee/trustee.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ route: /layout/trustee
55
---
66

77
import { Props } from 'docz';
8-
import { Playground } from '@playground';
8+
import { Playground, experianApiGet } from '@playground';
99
import { Form } from 'react-final-form';
1010
import { useState } from 'react';
1111
import { Trustee } from './trustee';
@@ -29,9 +29,7 @@ import { Trustee } from '@tpr/layout';
2929
<Playground>
3030
{() => {
3131
const [complete, setComplete] = useState(false);
32-
const API = {
33-
get: () => Promise.reject(new Error('THERE IS NO API IMPLEMENTATION')),
34-
};
32+
const API = experianApiGet;
3533
const callbackFn = (values, _fullTrusteeObject) => {
3634
console.log(values);
3735
return Promise.resolve();

packages/layout/src/components/cards/trustee/trustee.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const CardContent: React.FC = () => {
4949

5050
const TrusteeButton: React.FC = () => {
5151
const { current, send } = useTrusteeContext();
52+
5253
return (
5354
<UnderlinedButton
5455
isOpen={

packages/layout/src/components/cards/trustee/views/address/AutoComplete.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const AutoComplete: React.FC<AutoCompleteProps> = ({ onClick, options }) => {
1414

1515
const onSubmit = (values) => {
1616
if (Object.values(values).length > 0) {
17-
send('SAVE', { values });
17+
send('SAVE', { address: values.address.value });
1818
} else {
1919
Promise.reject('Address has not been selected...');
2020
}
@@ -25,7 +25,7 @@ const AutoComplete: React.FC<AutoCompleteProps> = ({ onClick, options }) => {
2525
{({ handleSubmit }) => (
2626
<form onSubmit={handleSubmit}>
2727
<FFSelect
28-
name="postcode"
28+
name="address"
2929
placeholder="Please select the address from the dropdown"
3030
options={options}
3131
inputWidth={6}

packages/layout/src/components/cards/trustee/views/address/Postcode.tsx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,32 @@ const Postcode: React.FC<PostcodeProps> = ({
2626
const { addressAPI } = useTrusteeContext();
2727

2828
const search = useCallback(
29-
(postcode: string, country = 'GBR', take = 100) => {
29+
(postcode: string, country = 'GBR', take = 25) => {
3030
setLoading(true);
31-
addressAPI
32-
.get(`search?country=${country}&query=${postcode}&take=${take}`)
31+
addressAPI(`search?country=${country}&query=${postcode}&take=${take}`)
3332
.then((resp) => {
34-
if (
35-
Array.isArray(resp.data.results) &&
36-
resp.data.results.length > 0
37-
) {
33+
if (Array.isArray(resp.results) && resp.results.length > 0) {
3834
Promise.all(
39-
resp.data.results.map(({ format }: { format: string }) => {
35+
resp.results.map(({ format }: { format: string }) => {
4036
const [url] = format.split('v2/').slice(-1);
41-
return addressAPI.get(url).then(({ data }) => {
42-
const address = extractToObject(data.address);
37+
return addressAPI(url).then(({ address }) => {
38+
const addressObject = extractToObject(address);
4339

4440
const addressToOurFormat = {
45-
addressLine1: address.addressLine1 || '',
46-
addressLine2: address.addressLine2 || '',
47-
addressLine3: address.addressLine3 || '',
48-
city: address.locality || '',
49-
county: address.province || '',
50-
postcode: address.postalCode || '',
51-
country: address.country || '',
41+
addressLine1: addressObject.addressLine1 || '',
42+
addressLine2: addressObject.addressLine2 || '',
43+
addressLine3: addressObject.addressLine3 || '',
44+
postTown: addressObject.locality || '',
45+
postcode: addressObject.postalCode || '',
46+
county: addressObject.province || '',
47+
country: addressObject.country || '',
5248
};
5349

5450
return {
55-
...addressToOurFormat,
56-
singleLineAddress: Object.keys(addressToOurFormat)
57-
.filter((key) => address[key])
58-
.map((key) => address[key])
51+
value: addressToOurFormat,
52+
label: Object.keys(addressToOurFormat)
53+
.filter((key) => addressObject[key])
54+
.map((key) => addressObject[key])
5955
.join(', '),
6056
};
6157
});

0 commit comments

Comments
 (0)