DropZoneAvatar.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {useDropzone} from 'react-dropzone';
  2. import { useEffect} from 'react';
  3. import { connect } from 'react-redux';
  4. import { Avatar } from '@mui/material';
  5. import { backendURL } from '../../helpers/gql';
  6. import { actionSetUserAvatar } from '../../actions/actionsMedia';
  7. import Camera from './icons8_camera.png';
  8. import { Drop } from '../ChatInfoModal/ChatInfoModal.style';
  9. import { AvatarWrap, AvatarOverlay } from './DropZoneAvatar.style';
  10. import { BadgeComponent } from '../UserEditorModal/UserEditorModal.style';
  11. import Photo from "../UserEditorModal/icons8photo.png";
  12. const DropAvatarComponent = ({url}) => {
  13. return(
  14. <AvatarWrap>
  15. <Avatar
  16. src={url}
  17. sx={{width: "75px", height: "75px"}}
  18. />
  19. <AvatarOverlay>
  20. <img src={Camera}/>
  21. </AvatarOverlay>
  22. </AvatarWrap>
  23. )
  24. }
  25. const DropAvatarPopupComponent = () => {
  26. return(
  27. <div style={{
  28. width: "100%",
  29. height: "30px",
  30. backgroundColor: "grey",
  31. opacity: "0.5",
  32. display: "flex",
  33. justifyContent: "center",
  34. alignItem: "center",
  35. cursor: "pointer"
  36. }}>
  37. <img style={{height: "26px"}} src={Camera}/>
  38. </div>
  39. )
  40. }
  41. export default function DropZoneAvatar({onLoad, component, url }) {
  42. const dropMap = {
  43. dropAvatarComponent: <DropAvatarComponent url={url}/>,
  44. dropAvatarPopupComponent: <DropAvatarPopupComponent/>,
  45. dropAvatarBadge: <BadgeComponent><img src={Photo}/></BadgeComponent>
  46. }
  47. const {acceptedFiles, getRootProps, getInputProps} = useDropzone({
  48. noDrag: true,
  49. multiple: false,
  50. accept: 'image/*'
  51. });
  52. useEffect(()=>{
  53. acceptedFiles[0] && onLoad(acceptedFiles[0])
  54. }, [acceptedFiles])
  55. return (
  56. <section className="container" >
  57. <div
  58. {...getRootProps({className: 'dropzone'})}>
  59. <input {...getInputProps()} />
  60. {dropMap[component]}
  61. </div>
  62. </section>
  63. );
  64. }