import { Avatar as MuiAvatar } from "@mui/material"; import PropTypes from "prop-types"; import { useSelector } from "react-redux"; import { useEffect, useState } from "react"; import { useTheme } from "@emotion/react"; /** * @component * @param {Object} props * @param {string} props.src - Path to image for avatar * @param {boolean} props.small - Specifies if avatar should be large * @param {Object} [props.sx] - Additional styles to apply to the button. * @returns {JSX.Element} * @example * // Render a red label * */ const Avatar = ({ src, small, sx, onClick = () => {} }) => { const { user } = useSelector((state) => state.auth); const theme = useTheme(); const style = small ? { width: 32, height: 32 } : { width: 64, height: 64 }; const border = small ? 1 : 3; const [image, setImage] = useState(); useEffect(() => { if (user.avatarImage) { setImage(`data:image/png;base64,${user.avatarImage}`); } }, [user?.avatarImage]); return ( {user.firstName?.charAt(0)} {user.lastName?.charAt(0) || ""} ); }; Avatar.propTypes = { src: PropTypes.string, small: PropTypes.bool, sx: PropTypes.object, onClick: PropTypes.func, }; export default Avatar;