Header.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React from 'react'
  2. import logo from '../../logo.svg';
  3. import noAva from '../../images/noAva.png'
  4. import { Link } from 'react-router-dom';
  5. import { CFieldSearch } from './Search';
  6. import { connect } from 'react-redux';
  7. import { actionAuthLogout, actionProfilData } from '../../actions';
  8. import { backURL } from '../../helpers';
  9. import Layout, { Header } from 'antd/lib/layout/layout';
  10. import { Avatar, Col, Menu, Popover, Row } from 'antd';
  11. import { UserOutlined, CompassOutlined, SettingOutlined, HomeOutlined, ImportOutlined, MessageOutlined, PlusCircleOutlined } from '@ant-design/icons/lib/icons';
  12. const UserNav = ({ id }) => {
  13. return <div className='UserNav'>
  14. <CUserNavIcon />
  15. </div>
  16. }
  17. export const UserAvatar = ({ avatarSize, avatar }) => {
  18. return (
  19. <>
  20. <Avatar style={{
  21. width: avatarSize,
  22. height: avatarSize
  23. }}
  24. src={avatar && avatar?.url ?
  25. <img src={(backURL + '/' + avatar.url)} alt='avatar' /> :
  26. <img src={noAva} />
  27. } />
  28. </>
  29. )
  30. }
  31. const ProfileDropMenu = ( {myID, onLogOut }) =>
  32. <Menu className='dropMenu'>
  33. <Menu.Item key={'0'}>
  34. <Link to={`${myID}`}><UserOutlined /> My Profile</Link>
  35. </Menu.Item>
  36. <Menu.Item key={'1'}>
  37. <Link to={'/'}><SettingOutlined /> Settings</Link>
  38. </Menu.Item>
  39. <Menu.Divider />
  40. <Menu.Item key={'2'}>
  41. <button onClick={() => onLogOut()}><ImportOutlined /> Log out</button>
  42. </Menu.Item>
  43. </Menu>
  44. const CProfileDropMenu = connect(null, { onLogOut: actionAuthLogout })(ProfileDropMenu)
  45. const UserNavIcon = ({ userData: { _id, avatar, login } }) =>
  46. <Row justify="end" align="middle" className='Header__userNav'>
  47. <Col >
  48. <Link to='/'><HomeOutlined /></Link>
  49. </Col>
  50. <Col >
  51. <Link to='/message'><MessageOutlined /></Link>
  52. </Col>
  53. <Col >
  54. <Link to='/add'><PlusCircleOutlined /></Link>
  55. </Col>
  56. <Col >
  57. <Link to='/rar'><CompassOutlined /></Link>
  58. </Col>
  59. <Col>
  60. <Popover placement="bottomRight" content={<CProfileDropMenu myID={_id} />} trigger={'click'}>
  61. <></>
  62. <UserAvatar avatar={avatar} login={login} avatarSize={'45px'} />
  63. </Popover>
  64. </Col>
  65. </Row >
  66. const CUserNav = connect(state => ({ id: state.auth?.payload.sub.id || {} }))(UserNav)
  67. const CUserNavIcon = connect(state => ({ userData: state.promise?.aboutMe?.payload || {} }))(UserNavIcon)
  68. const Logo = () =>
  69. <Link className='Logo' to='/'>
  70. <img src={logo} alt='logo' width='180vw' />
  71. </Link>
  72. const HeaderComponent = () =>
  73. <Layout>
  74. <Header style={{ position: 'fixed', zIndex: 1, width: '100%' }}>
  75. <Row justify="space-between" align="middle" className='Header__inner'>
  76. <Col span={8}>
  77. <Logo />
  78. </Col>
  79. <Col span={8}>
  80. <CFieldSearch />
  81. </Col>
  82. <Col span={8}>
  83. <CUserNav />
  84. </Col>
  85. </Row>
  86. </Header>
  87. </Layout>
  88. export default HeaderComponent