{"version":3,"sources":["components/search/SearchMunicipalitySelection.js"],"names":["MunicipalitySelection","_ref","location_value","lang","nis","translate","useSelector","state","general","search","dispatch","useDispatch","municipalities","setMunicipalities","useState","setNis","e","emptyLocationSelection","addToLocationSelection","useEffect","async","location","filteredName","toLowerCase","replace","location_by_name_model","require","default","option","from","size","query","query_string","fields","tie_breaker","Axios","get","auth","username","password","params","source_content_type","source","JSON","stringify","then","res","data","hits","_source","length","setFirstMunicipality","loc","push","i","children","slug","catch","err","setInitialNis","setLocationValue","React","createElement","Fragment","postal_code","style","paddingRight","name","className","Array","isArray","Icon","map","index","key","type","onClick","child"],"mappings":"6FAAA,kFAiOeA,UAtNeC,IAAyB,IAAxB,eAAEC,GAAgBD,GAC3C,KAAEE,EAAI,IAAEC,EAAG,UAAEC,GAAcC,YAAaC,GAAUA,EAAMC,SACxDC,EAASH,YAAaC,GAAUA,EAAME,QAE1C,MAAMC,EAAWC,eACVC,EAAgBC,GAAqBC,mBAAS,IAE/CC,EAAUC,IACdN,EAASO,eACTP,EAASQ,YAAuBF,KAIlCG,oBAAU,KAMcC,WACpB,GAAIhB,EAAK,CAqBP,IAAIiB,EAAW,GACXC,EAAelB,EAChBmB,cAWAC,QAAQ,SAAU,IAClBA,QAAQ,UAAW,IACnBA,QAAQ,UAAW,IACnBA,QAAQ,OAAQ,IAChBA,QAAQ,IAAK,IACbA,QAAQ,aAAc,kBACtBA,QAAQ,gBAAc,kBACtBA,QAAQ,aAAc,eACtBA,QAAQ,YAAa,cACrBA,QAAQ,eAAa,cACrBA,QAAQ,eAAa,cACrBA,QAAQ,UAAW,YACnBA,QAAQ,iBAAkB,gBAC1BA,QAAQ,YAAa,gBAErBA,QAAQ,SAAK,MAEK,YAAjBF,IAA8BA,EAAe,YAC5B,YAAjBA,IAA8BA,EAAe,YAC5B,WAAjBA,IAA6BA,EAAe,WAChD,MAAMG,EACJC,EAAQ,KAA+BC,QACzC,IAAIC,EAAS,CACXC,KAAM,EACNC,KAAM,GACNC,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N,IAAAC,cAAA,OAAKM,UAAU,WAEZxD,GACCA,EAAe4D,IAAI,CAACpB,EAAKqB,IAErBZ,IAAAC,cAACD,IAAME,SAAQ,CAACW,IAAKD,GAClBrB,EAAIuB,MACHd,IAAAC,cAAA,QAAMM,UAAU,gBACb/D,EAAU,gBAAgB,KAG/BwD,IAAAC,cAAA,OACEM,UAAW,WAAUhB,EAAII,OAAS/C,EAAOY,SAAS,GAAGmC,KAAO,SAAW,IAEvEoB,QAASA,IAAM7D,EAAOqC,IAErBQ,EAAiBR,IAGnBA,EAAIG,UAAYH,EAAIG,SAASL,OAAS,GAAKE,EAAIuB,MAC9Cd,IAAAC,cAAA,QAAMM,UAAU,gBACb/D,EAAU,sBAAsB,KAGpC+C,EAAIG,UACHH,EAAIG,SAASL,OAAS,GACtBE,EAAIG,SAASiB,IAAI,CAACK,EAAOvB,IAErBO,IAAAC,cAAA,OACEM,UAAW,WAAUS,EAAMrB,QAAU/C,EAAOY,SAAS6B,OAAS,EAAIzC,EAAOY,SAASZ,EAAOY,SAAS6B,OAAS,GAAGM,KAAO,IAAM,SAGrH,IAENoB,QAASA,IAAM7D,EAAO8D,GACtBH,IAAKpB,GAEJM,EAAiBiB","file":"static/js/38.fa9389ae.chunk.js","sourcesContent":["import {\r\n addToLocationSelection,\r\n emptyLocationSelection,\r\n setFirstMunicipality,\r\n} from \"../../actions\";\r\nimport { searchLocation } from \"../../services\";\r\nimport { useDispatch, useSelector } from \"react-redux\";\r\nimport Icon from \"@identitybuilding/idb-react-iconlib\";\r\nimport React, { useEffect, useState } from \"react\";\r\nimport Axios from \"axios\";\r\n\r\nconst MunicipalitySelection = ({ location_value }) => {\r\n let { lang, nis, translate } = useSelector((state) => state.general);\r\n let search = useSelector((state) => state.search);\r\n\r\n const dispatch = useDispatch();\r\n const [municipalities, setMunicipalities] = useState([]);\r\n\r\n const setNis = (e) => {\r\n dispatch(emptyLocationSelection());\r\n dispatch(addToLocationSelection(e));\r\n };\r\n\r\n \r\n useEffect(() => {\r\n const setNis = (e) => {\r\n dispatch(emptyLocationSelection());\r\n dispatch(addToLocationSelection(e));\r\n };\r\n\r\n const setInitialNis = async () => {\r\n if (nis) {\r\n // const locByName = await searchLocation({\r\n // lang: lang,\r\n // name: nis.toLowerCase(),\r\n // nis,\r\n // translate,\r\n // });\r\n // if (search.location.length === 0) {\r\n // dispatch(addToLocationSelection(locByName));\r\n // dispatch(setFirstMunicipality(locByName));\r\n // }\r\n\r\n // let loc = [];\r\n // loc.push(locByName);\r\n // for (let i = 0; i < locByName && locByName.children.length; i++) {\r\n // loc.push(locByName.children[i]);\r\n\r\n // if (locByName.children[i].slug === location_value)\r\n // setNis(locByName.children[i]);\r\n // }\r\n // setMunicipalities(loc);\r\n let location = \"\";\r\n let filteredName = nis\r\n .toLowerCase()\r\n // .replace(/è/g, \"e\")\r\n // .replace(/é/g, \"e\")\r\n // .replace(/ê/g, \"e\")\r\n // .replace(/ë/g, \"e\")\r\n // .replace(/á/g, \"a\")\r\n // .replace(/à/g, \"a\")\r\n // .replace(/â/g, \"a\")\r\n // .replace(/ä/g, \"a\")\r\n // .replace(/ü/g, \"u\")\r\n // .replace(/û/g, \"u\")\r\n .replace(\"(stad)\", \"\")\r\n .replace(\"(ville)\", \"\")\r\n .replace(\"(stadt)\", \"\")\r\n .replace(\"city\", \"\")\r\n .replace(\" \", \"\")\r\n .replace(\"lalouviere\", \"la louvière\")\r\n .replace(\"lalouvière\", \"la louvière\")\r\n .replace(\"lacalamine\", \"la calamine\")\r\n .replace(\"labruyere\", \"la-bruyere\")\r\n .replace(\"labruyère\", \"la-bruyere\")\r\n .replace(\"labruyère\", \"la-bruyere\")\r\n .replace(\"lahulpe\", \"la hulpe\")\r\n .replace('s-gravenbrakel', \"gravenbrakel\")\r\n .replace('louveigne', \"louveigné\")\r\n\r\n .replace(\"œ\", \"oe\");\r\n\r\n if (filteredName === \"depanne\") { filteredName = \"de panne\" }\r\n if (filteredName === \"depinte\") { filteredName = \"de pinte\" }\r\n if (filteredName === \"dehaan\") { filteredName = \"de haan\" }\r\n const location_by_name_model =\r\n require(\"../../models/LocationByName\").default;\r\n let option = {\r\n from: 0,\r\n size: 30,\r\n query: {\r\n query_string: {\r\n query: `${filteredName}`,\r\n fields: [\r\n `name_nl`,\r\n `name_fr`,\r\n `name_de`,\r\n `name_en`,\r\n `alt_name_nl`,\r\n `alt_name_fr`,\r\n `submunicipality_set.name_nl`,\r\n `submunicipality_set.name_fr`,\r\n `submunicipality_set.name_de`,\r\n `submunicipality_set.name_en`,\r\n 'slug'\r\n ],\r\n tie_breaker: 0.3,\r\n },\r\n },\r\n };\r\n Axios.get(\r\n `${process.env.REACT_APP_BASE_MEDIA_URL2}municipalities/_search`,\r\n {\r\n auth: {\r\n username: `${process.env.REACT_APP_ESUSERNAME}`,\r\n password: `${process.env.REACT_APP_ESPSW}`,\r\n },\r\n params: {\r\n source_content_type: \"application/json\",\r\n source: JSON.stringify(option),\r\n },\r\n }\r\n )\r\n .then((res) => {\r\n let data = res.data.hits.hits[0]._source;\r\n location = location_by_name_model(\r\n translate,\r\n data,\r\n lang,\r\n \"municipality\"\r\n );\r\n\r\n if (search.location.length === 0) {\r\n dispatch(addToLocationSelection(location));\r\n dispatch(setFirstMunicipality(location));\r\n }\r\n\r\n let loc = [];\r\n loc.push(location);\r\n for (let i = 0; i < location && location.children.length; i++) {\r\n\r\n if (location.children[i].slug === location_value)\r\n setNis(location.children[i]);\r\n }\r\n setMunicipalities(loc);\r\n\r\n })\r\n .catch((err) => (err ? err : \"\"));\r\n }\r\n };\r\n setInitialNis();\r\n // }, [dispatch, lang, location_value, nis, search.location.length, translate]);\r\n }, [dispatch, lang, location_value, nis, translate]);\r\n\r\n const setLocationValue = (loc) => {\r\n if (!loc || typeof loc !== \"object\") return null; // Handle undefined `loc`\r\n\r\n return (\r\n <>\r\n {loc.postal_code && {loc.postal_code}}\r\n {loc.name}\r\n \r\n );\r\n };\r\n\r\n // const show_type = (nis) => nis ? nis.substring(nis.length - 1, nis.length) === \"A\" ? `(${translate(\"sub_municipality\")})` : \"\" : \"\"\r\n return (\r\n search.location.length > 0 && (\r\n
\r\n
\r\n {Array.isArray(search.location[0]) && search.location[0].length > 0\r\n ? setLocationValue(search.location[0][0])\r\n : setLocationValue(search.location[0])}\r\n \r\n
\r\n
\r\n {/* show the municipality */}\r\n {municipalities &&\r\n municipalities.map((loc, index) => {\r\n return (\r\n \r\n {loc.type && (\r\n \r\n {translate(\"municipality\")}:\r\n \r\n )}\r\n setNis(loc)}\r\n >\r\n {setLocationValue(loc)}\r\n
\r\n {/* show the submunicipalities */}\r\n {loc.children && loc.children.length > 1 && loc.type && (\r\n \r\n {translate(\"sub_municipalities\")}:\r\n \r\n )}\r\n {loc.children &&\r\n loc.children.length > 1 &&\r\n loc.children.map((child, i) => {\r\n return (\r\n 0 ? search.location[search.location.length - 1].slug : \"\") ? \"active\" : \"\"\r\n\r\n ? \"active\"\r\n : \"\"\r\n }`}\r\n onClick={() => setNis(child)}\r\n key={i}\r\n >\r\n {setLocationValue(child)}\r\n
\r\n );\r\n })}\r\n \r\n );\r\n })}\r\n \r\n \r\n )\r\n );\r\n};\r\n\r\nexport default MunicipalitySelection;\r\n"],"sourceRoot":""}