From 12792757b925347e515ae0a967eeb88e000f5455 Mon Sep 17 00:00:00 2001 From: rohan09-raj Date: Wed, 17 Aug 2022 20:29:24 +0530 Subject: address refactoring --- client/src/constants/RegEx.js | 2 +- client/src/pages/Enrollment/Address/Address.jsx | 77 ++++++++++++++++------ client/src/pages/Enrollment/Enrollment.jsx | 40 +++++++---- .../src/pages/Update/Demographic/Demographic.jsx | 47 +++++++------ 4 files changed, 113 insertions(+), 53 deletions(-) (limited to 'client/src') diff --git a/client/src/constants/RegEx.js b/client/src/constants/RegEx.js index fca28f1..6c2ebbc 100644 --- a/client/src/constants/RegEx.js +++ b/client/src/constants/RegEx.js @@ -1,4 +1,4 @@ -export const validString = /^[a-zA-Z]+$/ +export const validString = /^[a-zA-Z ?]+$/ export const validMobileNumber = /^[0-9]{10}$/ diff --git a/client/src/pages/Enrollment/Address/Address.jsx b/client/src/pages/Enrollment/Address/Address.jsx index b6c3809..2e0fc6c 100644 --- a/client/src/pages/Enrollment/Address/Address.jsx +++ b/client/src/pages/Enrollment/Address/Address.jsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState, useEffect } from 'react' import Header from '../../../components/Header/Header' import Input from '../../../components/Input/Input' import { Country, State, City } from 'country-state-city' @@ -8,9 +8,36 @@ import styles from './Address.module.css' import { useTranslation } from 'react-i18next' const Address = ({ formData, setFormData }) => { + const [tempData, setTempData] = useState({ + country: '', + state: '', + district: '' + }) const { t } = useTranslation() const countries = Country.getAllCountries() + useEffect(() => { + setFormData({ + ...formData, + address: { + country: { + name: tempData.country.label, + code: tempData.country.isoCode + }, + state: { + name: tempData.state.label, + code: tempData.state.isoCode + }, + district: { + name: tempData.district.label, + code: tempData.district.isoCode + } + } + }) + }, [tempData]) + + console.log('Form Data: ', formData.address) + const updatedCountries = countries.map((country) => ({ label: country.name, value: country.id, @@ -62,10 +89,10 @@ const Address = ({ formData, setFormData }) => { name="country" label="country" options={updatedCountries} - value={formData.country} + value={tempData.country} onChange={(e) => { - setFormData({ - ...formData, + setTempData({ + ...tempData, country: e }) }} @@ -79,11 +106,11 @@ const Address = ({ formData, setFormData }) => {