@@ -32,6 +32,7 @@ const Label = styled.label`
3232
3333const CountryCity = ( ) => {
3434 const { state, dispatch } = useGlobalState ( ) ;
35+
3536 const [ fields , setFields ] = useState ( {
3637 cities : [ ] ,
3738 countries : [ ] ,
@@ -42,6 +43,7 @@ const CountryCity = () => {
4243 useEffect ( ( ) => {
4344 if ( ! isFieldsLoaded ) {
4445 const loadFields = ( ) => {
46+
4547 setFields ( {
4648 cities : getFieldsByTabName ( "misc" , "iranian-cities" ) ,
4749 countries : getFieldsByTabName ( "misc" , "countries" ) ,
@@ -53,20 +55,25 @@ const CountryCity = () => {
5355 }
5456 } , [ isFieldsLoaded ] ) ;
5557
56- const getTranslation = ( fieldsType , stateValue ) => {
57- if ( ! isFieldsLoaded ) return "" ;
58- const selectedField = fields [ fieldsType ] . find (
59- ( field ) => field . name . trim ( ) . toLowerCase ( ) === stateValue ?. trim ( ) . toLowerCase ( )
60- ) ;
61- return selectedField ? selectedField . translation : "" ;
62- } ;
58+ const getTranslation = ( fieldsType , stateValue ) => {
59+ if ( ! isFieldsLoaded ) return "" ;
60+ const selectedField = fields [ fieldsType ] . find (
61+ ( field ) =>
62+ field ?. name &&
63+ field . name . trim ( ) . toLowerCase ( ) === stateValue ?. trim ( ) . toLowerCase ( )
64+ ) ;
65+ return selectedField ? selectedField . translation : "" ;
66+ } ;
6367
64- const handleFieldChange = ( fieldsType , translation , actionType ) => {
65- const selectedField = fields [ fieldsType ] . find ( ( field ) => field . translation === translation ) ;
66- if ( selectedField ) {
67- dispatch ( { type : actionType , payload : selectedField . name } ) ;
68- }
69- } ;
68+
69+ const handleFieldChange = ( fieldsType , translation , actionType ) => {
70+ const selectedField = fields [ fieldsType ] . find (
71+ ( field ) => field ?. translation === translation
72+ ) ;
73+ if ( selectedField ) {
74+ dispatch ( { type : actionType , payload : selectedField . name } ) ;
75+ }
76+ } ;
7077
7178 const options = [
7279 {
0 commit comments