Skip to content

Commit

Permalink
🚧 Add missing address fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanaFigueira committed Jan 30, 2025
1 parent cb08e7d commit ec95478
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/containers/Gurb/components/AddressAutocompletedField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import TextField from '@mui/material/TextField'
import Autocomplete from '@mui/material/Autocomplete'
import { useTranslation } from 'react-i18next'
import Box from '@mui/material/Box'
import Grid from '@mui/material/Grid'

import Typography from '@mui/material/Typography'
import { textHeader4 } from '../gurbTheme'
import InputField from './InputField'

export default function LocationInput({
textFieldLabel,
textFieldName,
textFieldHelper,
value,
onChange,
onLocationSelected
onLocationSelected,
numberField = false,
required = false
}) {
const { t } = useTranslation()
const timeoutRef = useRef()
Expand Down
5 changes: 4 additions & 1 deletion src/containers/Gurb/contractValidations.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const holderTaxAddressValidations = Yup.object().shape({
is: 'supplypoint-tax-address-different',
then: Yup.string().required('NO_ADDRESS_NUMBER')
}),
floor: Yup.string(),
door: Yup.string(),
stairs: Yup.string(),
bloc: Yup.string(),
postal_code: Yup.string().when('has_different_address', {
is: 'supplypoint-tax-address-different',
then: Yup.string().required('NO_ADDRESS_POSTAL_CODE')
Expand Down Expand Up @@ -91,7 +95,6 @@ export const powerValidations = Yup.object().shape({
power4: Yup.string(),
power5: Yup.string(),
power6: Yup.string()

})
.when('power_type', {
is: 'power-higher-15kw',
Expand Down
88 changes: 78 additions & 10 deletions src/containers/Gurb/pages/Contract/TaxAddress.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const TaxAddress = (props) => {
setAddressValue(value)
}

const handleChangeAddressDetails = (event) => {
let value = event.target.value.match(/^[A-Za-z0-9 ]*/)
value = value[0]
setFieldValue(event.target.name, value)
}

const initializeAddress = () => {
setFieldValue('tax_address', {
has_different_address: values.tax_address.has_different_address,
Expand Down Expand Up @@ -136,16 +142,78 @@ const TaxAddress = (props) => {
</Box>
{values.tax_address.has_different_address ===
'supplypoint-tax-address-different' ? (
<LocationInput
textFieldLabel={t('GURB_ADDRESS_LABEL')}
textFieldName={t('GURB_TAX_ADDRESS_FIELD')}
textFieldHelper={t('GURB_ADDRESS_HELPER')}
id="tax_address-street"
name="tax_address.street"
value={addressValue}
onChange={handleAddressChange}
onLocationSelected={handleLocationSelected}
/>
<>
<LocationInput
textFieldLabel={t('GURB_ADDRESS_LABEL')}
textFieldName={t('GURB_TAX_ADDRESS_FIELD')}
textFieldHelper={t('GURB_ADDRESS_HELPER')}
id="tax_address-street"
name="tax_address.street"
value={addressValue}
onChange={handleAddressChange}
onLocationSelected={handleLocationSelected}
/>
<Grid container columnSpacing={2} sx={{ marginBottom: '6rem' }}>
<Grid item xs={2.5}>
<InputField
name={'holder.name'}
textFieldName={t('NUMBER')}
// handleChange={handleChangeName}
// handleBlur={() => {
// setFieldTouched('holder.name', true)
// }}
touched={touched?.tax_address?.number}
value={values?.tax_address?.number}
error={errors?.tax_address?.number}
required={true}
/>
</Grid>
<Grid item xs={2.5}>
<InputField
name={'tax_address.floor'}
textFieldName={t('FLOOR')}
handleChange={handleChangeAddressDetails}
touched={touched?.tax_address?.floor}
value={values?.tax_address?.floor}
error={errors?.tax_address?.floor}
required={false}
/>
</Grid>
<Grid item xs={2.5}>
<InputField
name={'tax_address.door'}
textFieldName={t('DOOR')}
handleChange={handleChangeAddressDetails}
touched={touched?.tax_address?.door}
value={values?.tax_address?.door}
error={errors?.tax_address?.door}
required={false}
/>
</Grid>
<Grid item xs={2.5}>
<InputField
name={'tax_address.stairs'}
textFieldName={t('STAIRS')}
handleChange={handleChangeAddressDetails}
touched={touched?.tax_address?.stairs}
value={values?.tax_address?.stairs}
error={errors?.tax_address?.stairs}
required={false}
/>
</Grid>
<Grid item xs={2}>
<InputField
name={'tax_address.bloc'}
textFieldName={t('BLOCK')}
handleChange={handleChangeAddressDetails}
touched={touched?.tax_address?.bloc}
value={values?.tax_address?.bloc}
error={errors?.tax_address?.bloc}
required={false}
/>
</Grid>
</Grid>
</>
) : (
<></>
)}
Expand Down

0 comments on commit ec95478

Please sign in to comment.