|
1 | | -import React, { useState, useEffect } from 'react' |
2 | | -import { FormattedMessage } from 'react-intl' |
3 | | -import { useHistory } from 'react-router-dom' |
4 | | -import { |
5 | | - Dashboard as DashboardIcon, |
6 | | - AccountBalanceWallet as WalletIcon, |
7 | | - LibraryBooks, |
8 | | - Payment as PaymentIcon, |
9 | | - CardMembership as PaymentRequestsIcon, |
10 | | - SwapHoriz as PayoutIcon, |
11 | | - Public as ExploreIcon, |
12 | | - AssignmentTurnedIn as ClaimIcon |
13 | | -} from '@mui/icons-material' |
14 | | -import useUserTypes from '../../../../../../hooks/use-user-types' |
| 1 | +import React from 'react' |
| 2 | +import useProfileSidebarMenu from '../../../../../../hooks/use-profile-sidebar-menu' |
15 | 3 | import { SideMenu } from '../../../../molecules/menus/side-menu/side-menu' |
16 | 4 |
|
17 | 5 | const ProfileSidebar = ({ user }) => { |
18 | | - const [selected, setSelected] = useState(0) |
19 | | - const history = useHistory() |
20 | | - const { isContributor, isMaintainer, isFunding, completed } = useUserTypes({ user }) |
21 | | - |
22 | | - useEffect(() => { |
23 | | - const path = history.location.pathname |
24 | | - if (path.includes('/profile/explore')) { |
25 | | - setSelected(2) |
26 | | - } else if ( |
27 | | - path.includes('/profile/task') || |
28 | | - path.includes('/profile/projects') || |
29 | | - path.includes('/profile/organizations') |
30 | | - ) { |
31 | | - setSelected(1) |
32 | | - } else if (path.includes('/profile/payments')) { |
33 | | - setSelected(3) |
34 | | - } else if (path.includes('/profile/payment-requests')) { |
35 | | - setSelected(4) |
36 | | - } else if (path.includes('/profile/wallets')) { |
37 | | - setSelected(5) |
38 | | - } else if (path.includes('/profile/claims')) { |
39 | | - setSelected(6) |
40 | | - } else if (path.includes('/profile/payouts')) { |
41 | | - setSelected(7) |
42 | | - } else { |
43 | | - setSelected(null) |
44 | | - } |
45 | | - }, [history.location.pathname]) |
| 6 | + const { completed, menuItems } = useProfileSidebarMenu({ user }) |
46 | 7 |
|
47 | 8 | return ( |
48 | 9 | <div> |
49 | | - <SideMenu |
50 | | - completed={completed} |
51 | | - menuItems={[ |
52 | | - { |
53 | | - items: [ |
54 | | - { |
55 | | - include: true, |
56 | | - onClick: () => history.push('/profile'), |
57 | | - icon: <DashboardIcon />, |
58 | | - label: ( |
59 | | - <FormattedMessage |
60 | | - id="account.profile.sidemenu.home.link.label" |
61 | | - defaultMessage="Dashboard" |
62 | | - /> |
63 | | - ), |
64 | | - selected: selected === 0 |
65 | | - } |
66 | | - ] |
67 | | - }, |
68 | | - { |
69 | | - category: ( |
70 | | - <FormattedMessage id="account.profile.sidemenu.issues" defaultMessage="Issues" /> |
71 | | - ), |
72 | | - items: [ |
73 | | - { |
74 | | - include: isContributor || isMaintainer || isFunding, |
75 | | - onClick: () => history.push('/profile/tasks'), |
76 | | - icon: <LibraryBooks />, |
77 | | - label: ( |
78 | | - <FormattedMessage |
79 | | - id="account.profile.sidemenu.issues.network" |
80 | | - defaultMessage="My issues" |
81 | | - /> |
82 | | - ), |
83 | | - selected: selected === 1 |
84 | | - }, |
85 | | - { |
86 | | - include: isContributor || isFunding, |
87 | | - onClick: () => history.push('/profile/explore'), |
88 | | - icon: <ExploreIcon />, |
89 | | - label: ( |
90 | | - <FormattedMessage |
91 | | - id="account.profile.sidemenu.issues.explore" |
92 | | - defaultMessage="Explore issues" |
93 | | - /> |
94 | | - ), |
95 | | - selected: selected === 2 |
96 | | - } |
97 | | - ] |
98 | | - }, |
99 | | - { |
100 | | - category: ( |
101 | | - <FormattedMessage |
102 | | - id="account.profile.sidemenu.section.bounties" |
103 | | - defaultMessage="Bounties" |
104 | | - /> |
105 | | - ), |
106 | | - items: [ |
107 | | - { |
108 | | - include: isFunding || isMaintainer, |
109 | | - onClick: () => history.push('/profile/payments'), |
110 | | - icon: <PaymentIcon />, |
111 | | - label: ( |
112 | | - <FormattedMessage id="account.profile.payments.list" defaultMessage="Payments" /> |
113 | | - ), |
114 | | - selected: selected === 3 |
115 | | - }, |
116 | | - { |
117 | | - include: isContributor, |
118 | | - onClick: () => history.push('/profile/payment-requests'), |
119 | | - icon: <PaymentRequestsIcon />, |
120 | | - label: ( |
121 | | - <FormattedMessage |
122 | | - id="account.profile.paymentRequests.list" |
123 | | - defaultMessage="Payment Requests" |
124 | | - /> |
125 | | - ), |
126 | | - selected: selected === 4 |
127 | | - }, |
128 | | - { |
129 | | - include: isFunding || isMaintainer, |
130 | | - onClick: () => history.push('/profile/wallets'), |
131 | | - icon: <WalletIcon />, |
132 | | - label: ( |
133 | | - <FormattedMessage id="account.profile.wallet.list" defaultMessage="Wallets" /> |
134 | | - ), |
135 | | - selected: selected === 5 |
136 | | - }, |
137 | | - { |
138 | | - include: isContributor, |
139 | | - onClick: () => history.push('/profile/claims'), |
140 | | - icon: <ClaimIcon />, |
141 | | - label: ( |
142 | | - <FormattedMessage id="account.profile.claims.list" defaultMessage="Claims" /> |
143 | | - ), |
144 | | - selected: selected === 6 |
145 | | - }, |
146 | | - { |
147 | | - include: isContributor, |
148 | | - onClick: () => history.push('/profile/payouts'), |
149 | | - icon: <PayoutIcon />, |
150 | | - label: ( |
151 | | - <FormattedMessage id="account.profile.payout.list" defaultMessage="Payouts" /> |
152 | | - ), |
153 | | - selected: selected === 7 |
154 | | - } |
155 | | - ] |
156 | | - } |
157 | | - ]} |
158 | | - /> |
| 10 | + <SideMenu completed={completed} menuItems={menuItems} /> |
159 | 11 | </div> |
160 | 12 | ) |
161 | 13 | } |
|
0 commit comments