Skip to content

Commit

Permalink
get api returning data and add a little styling
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-odonovan committed Oct 2, 2023
1 parent 626aaf7 commit de27d4c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/components/Molecules/PostcodeLookup/PostcodeLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import PropTypes from 'prop-types';
import { isValid, toNormalised } from 'postcode';
import axios from 'axios';
import Lookup from '../Lookup/Lookup';
import StyledWrapper from './PostcodeLookup.style';

const validatePostcode = postcode => {
const trimmed = typeof postcode === 'string' ? postcode.trim() : '';
return isValid(trimmed) && toNormalised(trimmed);
};

const getAddresses = postcode => axios.get(
`${process.env.GATSBY_LOOKUP_SERVICE_BASE_URL}/postcode/lookup`,
'https://lookups-staging.sls.comicrelief.com/postcode/lookup',
{
timeout: 10000,
params: { query: postcode }
Expand Down Expand Up @@ -47,17 +48,19 @@ const addressFetcher = async postcode => {
* @constructor
*/
const PostcodeLookup = ({ onSelect, ...rest }) => (
<Lookup
name="postcode_lookup"
label="Find address by postcode"
placeholder="Enter postcode..."
buttonText="Find address"
noResultsMessage="Sorry, could not find any addresses for that postcode"
mapOptionToString={addressToString}
lookupHandler={addressFetcher}
onSelect={onSelect}
{...rest}
/>
<StyledWrapper>
<Lookup
name="postcode_lookup"
label="Find address by postcode"
placeholder="Enter postcode..."
buttonText="Find address"
noResultsMessage="Sorry, could not find any addresses for that postcode"
mapOptionToString={addressToString}
lookupHandler={addressFetcher}
onSelect={onSelect}
{...rest}
/>
</StyledWrapper>
);

PostcodeLookup.propTypes = {
Expand Down
12 changes: 12 additions & 0 deletions src/components/Molecules/PostcodeLookup/PostcodeLookup.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import styled from 'styled-components';
import spacing from '../../../theme/shared/spacing';

const StyledWrapper = styled.div`
> div {
display: flex;
flex-direction: column;
gap: ${spacing('md')};
}
`;

export default StyledWrapper;

0 comments on commit de27d4c

Please sign in to comment.