From af13fa491717e222732116649bc3aa67bad045f1 Mon Sep 17 00:00:00 2001 From: joana Date: Wed, 13 Nov 2024 10:20:20 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20=20Move=20AddressAutocompleteField?= =?UTF-8?q?=20as=20Gurb's=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adapt component to gurb's design - Remove component from contract form --- src/containers/Contract/SupplyPoint.jsx | 84 ++++++++----------- .../components/AddressAutocompletedField.jsx | 52 ++++++++---- .../Gurb/pages/Requirements/Address.jsx | 31 +++---- 3 files changed, 80 insertions(+), 87 deletions(-) rename src/{ => containers/Gurb}/components/AddressAutocompletedField.jsx (76%) diff --git a/src/containers/Contract/SupplyPoint.jsx b/src/containers/Contract/SupplyPoint.jsx index 821237de..d552a0af 100644 --- a/src/containers/Contract/SupplyPoint.jsx +++ b/src/containers/Contract/SupplyPoint.jsx @@ -19,7 +19,6 @@ import CnaeField from '../../components/CnaeField' import { CNAE_HOUSING } from '../../services/utils' import { getMunicipisByPostalCode } from '../../services/api' import CadastralReferenceField from '../../components/CadastralReferenceField' -import LocationInput from '../../components/AddressAutocompletedField' const CadastralReferenceHelperText = () => { const { t } = useTranslation() @@ -37,8 +36,6 @@ const CadastralReferenceHelperText = () => { const SupplyPoint = (props) => { const { t } = useTranslation() - const SHOW_STATE_CITY = props.isGurbEnabled ? false : true - const [addressValue, setAddressValue] = useState('') const { @@ -146,35 +143,23 @@ const SupplyPoint = (props) => { - {props.isGurbEnabled ? ( - - ) : ( - - )} + { { /> - {SHOW_STATE_CITY ? ( - - ) : null} + { } helperText={ values?.supply_point?.cadastral_reference && - errors?.supply_point?.cadastral_reference ? ( + errors?.supply_point?.cadastral_reference ? ( errors?.supply_point?.cadastral_reference ) : ( diff --git a/src/components/AddressAutocompletedField.jsx b/src/containers/Gurb/components/AddressAutocompletedField.jsx similarity index 76% rename from src/components/AddressAutocompletedField.jsx rename to src/containers/Gurb/components/AddressAutocompletedField.jsx index 8f1272fe..f27f3a1f 100644 --- a/src/components/AddressAutocompletedField.jsx +++ b/src/containers/Gurb/components/AddressAutocompletedField.jsx @@ -1,10 +1,21 @@ import React, { useRef, useState } from 'react' -import getGoogleMapsPlacesApiClient from '../services/googleApiClient' +import getGoogleMapsPlacesApiClient from '../../../services/googleApiClient' import TextField from '@mui/material/TextField' import Autocomplete from '@mui/material/Autocomplete' import { useTranslation } from 'react-i18next' +import Box from '@mui/material/Box' +import Typography from '@mui/material/Typography' +import { textHeader4 } from '../gurbTheme' +import { HelperText } from './InputField' -export default function LocationInput({ value, onChange, onLocationSelected }) { +export default function LocationInput({ + textFieldLabel, + textFieldName, + textFieldHelper, + value, + onChange, + onLocationSelected +}) { const { t } = useTranslation() const timeoutRef = useRef() const sessionTokenRef = useRef() @@ -122,20 +133,29 @@ export default function LocationInput({ value, onChange, onLocationSelected }) { noOptionsText="No locations" onChange={handleSuggestionSelected} renderInput={(params) => ( - { - const newValue = event.target.value - // update controlled input value - onChange(newValue) - // clear any previously loaded place details - setPlaceDetail(undefined) - // trigger the load of suggestions - loadSuggestions(newValue) - }} - /> + + {textFieldName} + { + const newValue = event.target.value + // update controlled input value + onChange(newValue) + // clear any previously loaded place details + setPlaceDetail(undefined) + // trigger the load of suggestions + loadSuggestions(newValue) + }} + /> + )} />
diff --git a/src/containers/Gurb/pages/Requirements/Address.jsx b/src/containers/Gurb/pages/Requirements/Address.jsx index faff52d0..9de58b2c 100644 --- a/src/containers/Gurb/pages/Requirements/Address.jsx +++ b/src/containers/Gurb/pages/Requirements/Address.jsx @@ -2,8 +2,7 @@ import { useContext, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import TextRecomendation from '../../components/TextRecomendation' -import InputField from '../../components/InputField' -import LocationInput from '../../../../components/AddressAutocompletedField' +import LocationInput from '../../components/AddressAutocompletedField' import { setMunicipisWithPostalCode } from '../../../../services/utils' import { checkGurbDistance } from '../../../../services/apiGurb' import GurbErrorContext from '../../../../context/GurbErrorContext' @@ -35,7 +34,7 @@ const Address = (props) => { }, [values.address.postal_code]) const handleCheckGurbDistance = async () => { - // TODO: gurb id from where? + // TODO: waiting to know where gurb id comes from const gurbId = 3 await checkGurbDistance(gurbId, values.address.lat, values.address.long) .then(({ data }) => { @@ -43,12 +42,12 @@ const Address = (props) => { if (data === false) { setError(true) setErrorInfo({ - main_text: t('GURB_ADDRESS_ERROR_MAIN_TEXT'), - seconday_text: t('GURB_ADDRESS_ERROR_SECONDARY_TEXT'), - link_text: t('GURB_ADDRESS_ERROR_LINK_TEXT'), - test: () => { - initializeAddress() - } + main_text: t('GURB_ADDRESS_ERROR_MAIN_TEXT'), + seconday_text: t('GURB_ADDRESS_ERROR_SECONDARY_TEXT'), + link_text: t('GURB_ADDRESS_ERROR_LINK_TEXT'), + clean_address: () => { + initializeAddress() + } }) } }) @@ -105,23 +104,15 @@ const Address = (props) => { />   - ) }