From 17b0ea6111115b8492074aeebe11bd2542214cfd Mon Sep 17 00:00:00 2001 From: Nuwan Date: Mon, 11 Mar 2024 22:23:12 +0530 Subject: [PATCH] fix errors while selecting country, region and city --- jam-ui/src/components/page/JKEditProfile.js | 48 +++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/jam-ui/src/components/page/JKEditProfile.js b/jam-ui/src/components/page/JKEditProfile.js index a81c4052f..75da1d2d2 100644 --- a/jam-ui/src/components/page/JKEditProfile.js +++ b/jam-ui/src/components/page/JKEditProfile.js @@ -198,6 +198,7 @@ function JKEditProfile() { }) .then(data => { setRegions(data.regions); + skipRegionChange.current = false; }) .catch(error => console.log(error)); }; @@ -322,17 +323,20 @@ function JKEditProfile() { regionRef.current.select.clearValue(); setCities([]); cityRef.current.select.clearValue(); - fetchRegions(country.value); + fetchRegions(country); forceUpdate(); handleChange(); }; const handleRegionChange = selectedOpt => { + console.log("region selectedOpt", selectedOpt) if (!selectedOpt) return; + if (skipRegionChange.current) { skipRegionChange.current = false; return; } + const state = selectedOpt.value; const country = getValues('country'); setValue('state', state); @@ -470,13 +474,24 @@ function JKEditProfile() { control={control} render={({ field: { onChange, value } }) => { const country = countries.find(country => country.countrycode === value); + if (!country) { + return ( + { - return { value: country.countrycode, label: country.countryname }; + options={countries.map(c => { + return { value: c.countrycode, label: c.countryname }; })} /> ); @@ -494,16 +509,30 @@ function JKEditProfile() { control={control} render={({ field: { onChange, value } }) => { const region = regions.find(region => region.region === value); + if (region) { return ( { + return { value: r.region, label: r.region }; + })} + /> + ); + } }} /> @@ -517,11 +546,12 @@ function JKEditProfile() { control={control} render={({ field: { onChange, value } }) => (