Skip to content

Commit

Permalink
Merge pull request #33 from cap-collectif/form-address
Browse files Browse the repository at this point in the history
  • Loading branch information
MedElfadhelELHACHEMI authored May 19, 2022
2 parents b273a67 + 0664fb1 commit dc72b13
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/components/address/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ import PlacesAutocomplete, {

import type { AddressComplete, AddressWithoutPosition } from './Address.type'

export type AddressProps = InputProps
export type AddressProps = InputProps & {
getAddress?: (address: AddressComplete) => void
}
const Address: React.FC<AddressProps> = ({
value,
onChange,
placeholder,
className,
width,
getAddress,
}) => {
const handleSelect = async (address: string) => {
const addressWithoutPosition: AddressWithoutPosition = await geocodeByAddress(
address,
)
.then((results: AddressWithoutPosition[]) => {
// There is no lat & lng here
return results[0]
})
.catch(error => console.error('Error', error))
const addressWithoutPosition: AddressWithoutPosition =
await geocodeByAddress(address)
.then((results: AddressWithoutPosition[]) => {
// There is no lat & lng here
return results[0]
})
.catch(error => console.error('Error', error))

await getLatLng(addressWithoutPosition)
.then(latLng => {
Expand All @@ -39,11 +41,11 @@ const Address: React.FC<AddressProps> = ({
},
},
}
if (getAddress) getAddress(addressComplete)
onChange(addressComplete.formatted_address)
})
.catch(error => console.error('Error', error))
}

return (
<PlacesAutocomplete
value={value}
Expand Down
1 change: 1 addition & 0 deletions src/components/fieldInput/FieldInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const FieldInput: FC<FieldInputProps> = ({

switch (type) {
default:
case 'hidden':
case 'text':
case 'email':
case 'password':
Expand Down
2 changes: 1 addition & 1 deletion src/components/fieldInput/FieldInput.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export type FieldTextArea = {
} & TextAreaProps

export type FieldText = {
type: 'text' | 'email' | 'password' | 'tel'
type: 'text' | 'email' | 'password' | 'tel' | 'hidden'
} & InputProps

export type FieldSwitch = {
Expand Down

0 comments on commit dc72b13

Please sign in to comment.