diff --git a/src/partials/digitalId/ProfileTable.jsx b/src/partials/digitalId/ProfileTable.jsx index b65797b..77901bc 100644 --- a/src/partials/digitalId/ProfileTable.jsx +++ b/src/partials/digitalId/ProfileTable.jsx @@ -29,17 +29,40 @@ function ProfileTable({ } }; + function filterByCategory(map, category) { + let filteredArray = []; + if (arguments.length === 1) { + map.forEach((value, key) => { + if (!data.general.includes(key) && !data.nationality.includes(key) && !data.social.includes(key)){ + filteredArray.push({ + 'key': key, + 'value': value + }); + } + }); + } else { + map.forEach((value, key) => { + if (category.includes(key)){ + filteredArray.push({ + 'key': key, + 'value': value + }) + } + }); + } + return filteredArray; + } + const data = { general:["First name","Second name", "Gender", "Birthdate", "Place of birth"], nationality:["Nationality", "National id", "National doctype", "National doc id", "National doc issue date", "National doc expiry date"], social:["Telephone", "Twitter", "Facebook", "Instagram", "Youtube", "Wechat", "Tiktok", "Linkedin", "Vk", "Github", "Telegram", "Qq", "Snapchat", "Reddit"] } - const generalData = userData.filter(elem => data.general.includes(elem.label)), - nationalityData = userData.filter(elem => data.nationality.includes(elem.label)), - sosialData = userData.filter(elem => data.nationality.includes(elem.label)), - otherData = userData.filter((elem) => - !data.general.includes(elem.label) && !data.nationality.includes(elem.label) && !data.social.includes(elem.label)); + const generalData = filterByCategory(userData, data.general), + nationalityData = filterByCategory(userData, data.nationality), + sosialData = filterByCategory(userData, data.social), + otherData = filterByCategory(userData); return ( <> @@ -49,19 +72,19 @@ function ProfileTable({