simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 18 | import ListItem from '@mui/material/ListItem'; |
| 19 | import ListItemIcon from '@mui/material/ListItemIcon'; |
| 20 | import ListItemText from '@mui/material/ListItemText'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 21 | import PropTypes from 'prop-types'; |
| 22 | import { forwardRef, useMemo } from 'react'; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 23 | import { Link as RouterLink } from 'react-router-dom'; |
| 24 | |
| 25 | function ListItemLink(props) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 26 | const { icon, primary, secondary, to, account } = props; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 27 | |
| 28 | const renderLink = useMemo( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 29 | () => |
| 30 | forwardRef((itemProps, ref) => { |
| 31 | console.log('LIST ITEM LINK: ', account, itemProps); |
| 32 | return <RouterLink to={to} ref={ref} {...itemProps} state={account} />; |
| 33 | }), |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 34 | [account, to] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 35 | ); |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 36 | |
| 37 | return ( |
| 38 | <ListItem button component={renderLink}> |
| 39 | {icon ? <ListItemIcon>{icon}</ListItemIcon> : null} |
| 40 | <ListItemText primary={primary} secondary={secondary} /> |
| 41 | </ListItem> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 42 | ); |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | ListItemLink.propTypes = { |
| 46 | icon: PropTypes.element, |
| 47 | primary: PropTypes.string.isRequired, |
| 48 | secondary: PropTypes.string, |
| 49 | to: PropTypes.string.isRequired, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 50 | account: PropTypes.object, |
| 51 | }; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 52 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 53 | export default ListItemLink; |