give
/
src
/
DonorDashboards
/
resources
/
js
/
app
/
components
/
dashboard-content
Last commit date
index.js
4 years ago
style.scss
4 years ago
index.js
34 lines
| 1 | import {useState, useEffect} from 'react'; |
| 2 | import {useSelector} from 'react-redux'; |
| 3 | |
| 4 | import './style.scss'; |
| 5 | |
| 6 | const DashboardContent = () => { |
| 7 | const tabsSelector = useSelector((state) => state.tabs); |
| 8 | const [tabs, setTabs] = useState([]); |
| 9 | const [dashboardContent, setDashboardContent] = useState([]); |
| 10 | |
| 11 | useEffect(() => { |
| 12 | setTabs(Object.entries(tabsSelector)); |
| 13 | }, [tabsSelector]); |
| 14 | |
| 15 | useEffect(() => { |
| 16 | if (tabs.length > 2) { |
| 17 | setDashboardContent(getDashboardContent(tabs)); |
| 18 | } |
| 19 | }, [tabs]); |
| 20 | |
| 21 | const getDashboardContent = (tabsArray) => { |
| 22 | return tabsArray.reduce((content, tab, index) => { |
| 23 | if (tab[1].dashboardContent) { |
| 24 | const Content = tab[1].dashboardContent; |
| 25 | content.push(<Content key={index} />); |
| 26 | } |
| 27 | return content; |
| 28 | }, []); |
| 29 | }; |
| 30 | |
| 31 | return <div className="give-donor-dashboard-dashboard-content">{dashboardContent}</div>; |
| 32 | }; |
| 33 | export default DashboardContent; |
| 34 |