|
@@ -1,4 +1,4 @@
|
|
-import React, {useEffect, useState} from 'react';
|
|
|
|
|
|
+import React, {useEffect, useState, useRef} from 'react';
|
|
import Box from '@mui/material/Box';
|
|
import Box from '@mui/material/Box';
|
|
import Modal from '@mui/material/Modal';
|
|
import Modal from '@mui/material/Modal';
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
@@ -14,7 +14,7 @@ import {UserAvatar} from '../components'
|
|
|
|
|
|
import { printStrReq } from "../helpers";
|
|
import { printStrReq } from "../helpers";
|
|
import {connect} from 'react-redux'
|
|
import {connect} from 'react-redux'
|
|
-import {actionSetAvatar} from '../actions'
|
|
|
|
|
|
+import {actionSetUserInfo} from '../actions'
|
|
|
|
|
|
|
|
|
|
const styleModalParrent = {
|
|
const styleModalParrent = {
|
|
@@ -34,33 +34,6 @@ const styleModalParrent = {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-const AvatarDropZone = ({onLoad}) => {
|
|
|
|
- const {
|
|
|
|
- acceptedFiles,
|
|
|
|
- getRootProps,
|
|
|
|
- getInputProps
|
|
|
|
- } = useDropzone({
|
|
|
|
- accept: 'image/*',
|
|
|
|
- maxFiles: 1,
|
|
|
|
- onDrop: (acceptedFiles) => {
|
|
|
|
- console.log(acceptedFiles[0])
|
|
|
|
- // onLoad("media", acceptedFiles[0])
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <form action="/upload" method="post" encType="multipart/form-data" id='formUser'>
|
|
|
|
- <section className="container">
|
|
|
|
- <div {...getRootProps({className: 'dropzone'})}>
|
|
|
|
- <input {...getInputProps()} type="file" name="media" id='mediaUser' />
|
|
|
|
- <p>Изменить аватар</p>
|
|
|
|
- </div>
|
|
|
|
- </section>
|
|
|
|
- </form>
|
|
|
|
- );
|
|
|
|
-}
|
|
|
|
-const CAvatarDropZone = connect( null, {onLoad: actionSetAvatar})(AvatarDropZone)
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
@@ -68,20 +41,30 @@ const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
// console.log(myProfile)
|
|
// console.log(myProfile)
|
|
// const {login, nick, avatar: {url}} = myProfile
|
|
// const {login, nick, avatar: {url}} = myProfile
|
|
|
|
|
|
- const [login, setLogin] = useState(myProfile.login)
|
|
|
|
- const [logBlur, setLogBlur] = useState(false)
|
|
|
|
-
|
|
|
|
- const [nick, setNick] = useState(myProfile.nick)
|
|
|
|
-
|
|
|
|
- const [img, setImg] = useState(myProfile.avatar?.url)
|
|
|
|
|
|
+ const [login, setLogin] = useState(myProfile.login)
|
|
|
|
+ const [logBlur, setLogBlur] = useState(false)
|
|
|
|
+ const [nick, setNick] = useState(myProfile.nick)
|
|
|
|
+ const currAvatar = useRef(myProfile.avatar?.url)
|
|
|
|
|
|
|
|
+ const [img, setImg] = useState(null)
|
|
|
|
+ const {
|
|
|
|
+ acceptedFiles,
|
|
|
|
+ getRootProps,
|
|
|
|
+ getInputProps
|
|
|
|
+ } = useDropzone({
|
|
|
|
+ accept: 'image/*',
|
|
|
|
+ maxFiles: 1,
|
|
|
|
+ onDrop: (acceptedFiles) => {
|
|
|
|
+ console.log(acceptedFiles)
|
|
|
|
+ setImg(acceptedFiles[0])
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- const handleOpen = () => {setOpen(true)}
|
|
|
|
- const handleClose = () => {setOpen(false)}
|
|
|
|
|
|
+ const handleOpen = () => setOpen(true)
|
|
|
|
+ const handleClose = () => (setImg(null), setOpen(false))
|
|
|
|
|
|
return (
|
|
return (
|
|
<div>
|
|
<div>
|
|
- {/* <Button onClick={handleOpen}>Профиль</Button> */}
|
|
|
|
<MenuItem onClick={handleOpen}>
|
|
<MenuItem onClick={handleOpen}>
|
|
Профиль
|
|
Профиль
|
|
</MenuItem>
|
|
</MenuItem>
|
|
@@ -105,10 +88,21 @@ const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
Мой профиль
|
|
Мой профиль
|
|
</Typography>
|
|
</Typography>
|
|
</Box>
|
|
</Box>
|
|
-
|
|
|
|
|
|
+
|
|
<Box sx={{ display: 'flex', justifyContent: 'start', mt: 2, }}>
|
|
<Box sx={{ display: 'flex', justifyContent: 'start', mt: 2, }}>
|
|
- <UserAvatar profile={{login: login, nick: nick, avatar: {url: img || ''}}} />
|
|
|
|
- <CAvatarDropZone />
|
|
|
|
|
|
+
|
|
|
|
+ <UserAvatar profile={{ login: login, nick: nick, avatar: {url: myProfile.avatar?.url || ''},
|
|
|
|
+ localUrl: img && URL.createObjectURL(img)}} />
|
|
|
|
+
|
|
|
|
+ <form action="/upload" method="post" encType="multipart/form-data" id='formUser'>
|
|
|
|
+ <section className="container">
|
|
|
|
+ <div {...getRootProps({className: 'dropzone'})}>
|
|
|
|
+ <input {...getInputProps()} type="file" name="media" id='mediaUser' />
|
|
|
|
+ <p>Изменить аватар</p>
|
|
|
|
+ </div>
|
|
|
|
+ </section>
|
|
|
|
+ </form>
|
|
|
|
+
|
|
</Box>
|
|
</Box>
|
|
|
|
|
|
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', mt: 4 }}>
|
|
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', mt: 4 }}>
|
|
@@ -147,7 +141,7 @@ const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
</Box>
|
|
</Box>
|
|
|
|
|
|
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', mt: 4 }}>
|
|
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', mt: 4 }}>
|
|
- <Typography variant="body1" /* color="error" */>
|
|
|
|
|
|
+ <Typography variant="body1" >
|
|
Изменить ник
|
|
Изменить ник
|
|
</Typography>
|
|
</Typography>
|
|
<TextField
|
|
<TextField
|
|
@@ -178,7 +172,7 @@ const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
<Box sx={{ display: 'flex', justifyContent: 'end', mt: 2}}>
|
|
<Box sx={{ display: 'flex', justifyContent: 'end', mt: 2}}>
|
|
<Button variant="contained"
|
|
<Button variant="contained"
|
|
disabled={(login?.length >= minLog) ? false : true}
|
|
disabled={(login?.length >= minLog) ? false : true}
|
|
- onClick={() => onСonfirm()}>
|
|
|
|
|
|
+ onClick={() => onСonfirm("media", img, login, nick)}>
|
|
Применить
|
|
Применить
|
|
</Button>
|
|
</Button>
|
|
</Box>
|
|
</Box>
|
|
@@ -190,6 +184,6 @@ const ProfileModal = ({minLog='2', myProfile, onСonfirm, onModalOpen}) => {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
export const CProfileModal = connect( state => ({myProfile: state.promise?.myProfile?.payload || {}}),
|
|
export const CProfileModal = connect( state => ({myProfile: state.promise?.myProfile?.payload || {}}),
|
|
- {onСonfirm : actionSetAvatar})(ProfileModal)
|
|
|
|
|
|
+ {onСonfirm : actionSetUserInfo})(ProfileModal)
|
|
|
|
|
|
|
|
|