blob: b56e87d5275c5cebdab46dcee8932185c54aa220 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
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éraudab519ff2022-05-03 15:34:48 -040018import ListItem from '@mui/material/ListItem';
19import ListItemIcon from '@mui/material/ListItemIcon';
20import ListItemText from '@mui/material/ListItemText';
simon07b4eb02022-09-29 17:50:26 -040021import PropTypes from 'prop-types';
22import { forwardRef, useMemo } from 'react';
Adrien Béraud88a52442021-04-26 12:11:41 -040023import { Link as RouterLink } from 'react-router-dom';
24
25function ListItemLink(props) {
simond47ef9e2022-09-28 22:24:28 -040026 const { icon, primary, secondary, to, account } = props;
Adrien Béraud88a52442021-04-26 12:11:41 -040027
28 const renderLink = useMemo(
simond47ef9e2022-09-28 22:24:28 -040029 () =>
30 forwardRef((itemProps, ref) => {
31 console.log('LIST ITEM LINK: ', account, itemProps);
32 return <RouterLink to={to} ref={ref} {...itemProps} state={account} />;
33 }),
simon80b7b3b2022-09-28 17:50:10 -040034 [account, to]
simond47ef9e2022-09-28 22:24:28 -040035 );
Adrien Béraud88a52442021-04-26 12:11:41 -040036
37 return (
38 <ListItem button component={renderLink}>
39 {icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
40 <ListItemText primary={primary} secondary={secondary} />
41 </ListItem>
simond47ef9e2022-09-28 22:24:28 -040042 );
Adrien Béraud88a52442021-04-26 12:11:41 -040043}
44
45ListItemLink.propTypes = {
46 icon: PropTypes.element,
47 primary: PropTypes.string.isRequired,
48 secondary: PropTypes.string,
49 to: PropTypes.string.isRequired,
simond47ef9e2022-09-28 22:24:28 -040050 account: PropTypes.object,
51};
Adrien Béraud88a52442021-04-26 12:11:41 -040052
simond47ef9e2022-09-28 22:24:28 -040053export default ListItemLink;