|
@@ -6,6 +6,7 @@ import image from '../images/card.png';
|
|
|
import { actionAuthLogin } from '../store/authReducer';
|
|
|
import {Link} from 'react-router-dom';
|
|
|
import Form from 'react-bootstrap/Form';
|
|
|
+import {Accordion} from "react-bootstrap";
|
|
|
|
|
|
|
|
|
export async function sendForm (url, data) {
|
|
@@ -33,6 +34,7 @@ export function EditProfile (props) {
|
|
|
const [login, setLogin] = useState(props.user?.login);
|
|
|
const [name, setName] = useState(props.user?.name);
|
|
|
const [avatar, setAvatar] = useState((props.user?.avatar || image));
|
|
|
+ const [description, setDescription] = useState(props.user?.description);
|
|
|
const [passwordConfirm, setPasswordConfirm] = useState('');
|
|
|
const [password, setPassword] = useState('');
|
|
|
const [textModal, setTextModal] = useState('');
|
|
@@ -43,6 +45,7 @@ export function EditProfile (props) {
|
|
|
const data = new FormData();
|
|
|
login && login!==props.user?.login && data.append("login", login);
|
|
|
name && name!==props.user?.name && data.append("name", name);
|
|
|
+ data.append("description", description);
|
|
|
avatar.name && data.append("avatar", avatar, avatar.name);
|
|
|
|
|
|
setTextModal(( typeof(await sendForm('profile/edit', data))==='string')? (await sendForm('profile/edit', data)) : '');
|
|
@@ -59,70 +62,72 @@ export function EditProfile (props) {
|
|
|
}
|
|
|
|
|
|
return (<>
|
|
|
- <div className='d-flex container align-items-center justify-content-center'>
|
|
|
- <div className=''>
|
|
|
- <img className='m-4' alt='...' src={props.user?.avatar || image} width='150px'/>
|
|
|
- </div>
|
|
|
- <div className=''>
|
|
|
- <h5>Name: {store.getState().auth?.user?.name}</h5>
|
|
|
- <p>Login: {store.getState().auth?.user?.login}</p>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <Form onSubmit={postForm} className='d-flex justify-content-center align-items-center'>
|
|
|
- <div>
|
|
|
- <Form.Group className="mb-3" controlId="formBasicLogin">
|
|
|
- <Form.Label>Change Login:</Form.Label>
|
|
|
- <div className='d-flex'>
|
|
|
- <Form.Control type="text" className="me-1" placeholder={login}
|
|
|
- value={login} onChange={e => setLogin(e.target.value)} />
|
|
|
- <Button variant="outline-danger" type="submit">Save</Button>
|
|
|
- </div>
|
|
|
- <Form.Text className="text-muted">{textModal || "*login must be unique"}</Form.Text>
|
|
|
- </Form.Group>
|
|
|
-
|
|
|
- <Form.Group className="mb-3" controlId="formBasicName">
|
|
|
- <Form.Label>Change Name:</Form.Label>
|
|
|
- <div className='d-flex'>
|
|
|
- <Form.Control type="text" className="me-1" placeholder="Anastasiia"
|
|
|
- value={name} onChange={e => setName(e.target.value)} />
|
|
|
- <Button variant="outline-danger" type="submit">Save</Button>
|
|
|
+ <div className='d-flex w-100'>
|
|
|
+ <div className="me-4">
|
|
|
+ <div className='mb-3 playlist-img-box rounded-5' style={{backgroundImage: `url(${props.user?.avatar || image})`, backgroundSize: "cover", backgroundRepeat: "no-repeat", backgroundPosition: "center"}}></div>
|
|
|
+ <Form.Group className="mb-3" controlId="formBasicAvatar">
|
|
|
+ <div className='d-flex'>
|
|
|
+ <Form.Control type="file" className="me-1" name="picture" accept="image/*" onChange={e => setAvatar(e.target.files[0])} multiple={false} />
|
|
|
+ </div>
|
|
|
+ </Form.Group>
|
|
|
</div>
|
|
|
- </Form.Group>
|
|
|
+ <div className='w-100'>
|
|
|
+ <div className="d-flex flex-column justify-content-between h-100">
|
|
|
+ <div className="w-100 row">
|
|
|
+ <Form onSubmit={postForm}>
|
|
|
+ <Form.Group className="mb-3" controlId="formBasicAvatar">
|
|
|
+ <Form.Label>Change Login:</Form.Label>
|
|
|
+ <Form.Control type="text" className="me-1" placeholder={login}
|
|
|
+ value={login} onChange={e => setLogin(e.target.value)} />
|
|
|
+ </Form.Group>
|
|
|
+ <Form.Group className="mb-3" controlId="formBasicAvatar">
|
|
|
+ <Form.Label>Change Name:</Form.Label>
|
|
|
+ <Form.Control type="text" className="me-1" placeholder="Anastasiia"
|
|
|
+ value={name} onChange={e => setName(e.target.value)} />
|
|
|
+ </Form.Group>
|
|
|
+ <Form.Group className="mb-3" controlId="formBasicAvatar">
|
|
|
+ <Form.Label>Change About Me:</Form.Label>
|
|
|
+ <Form.Control as="textarea" rows="3" className="me-1"
|
|
|
+ value={description !== 'null' ? description : ''} onChange={e => setDescription(e.target.value)} />
|
|
|
+ </Form.Group>
|
|
|
+ <div className="d-flex justify-content-between align-items-center mb-3">
|
|
|
+ <Link to={'/user'}>Back to home Page</Link>
|
|
|
+ <Button variant="outline-success" type="submit">Save</Button>
|
|
|
+ </div>
|
|
|
+ </Form>
|
|
|
+ <Accordion className="border-0">
|
|
|
+ <Accordion.Item eventKey="0" className="border-0">
|
|
|
+ <Accordion.Header className="btn-dark">Change Password</Accordion.Header>
|
|
|
+ <Accordion.Body className="bg-dark">
|
|
|
+ <Form onSubmit={postEditPassword} className=''>
|
|
|
+ <div className="d-flex m-0">
|
|
|
+ <Form.Group className="col-6 px-3" controlId="formBasicNewPassword">
|
|
|
+ <Form.Label>New Password:</Form.Label>
|
|
|
+ <Form.Control type="password" className="" placeholder="new password"
|
|
|
+ value={password} onChange={e => setPassword(e.target.value)} />
|
|
|
+ <Form.Text className="text-muted m-0 p-0">* Minimum 8 symbols.</Form.Text>
|
|
|
+ </Form.Group>
|
|
|
|
|
|
- <Form.Group className="mb-3" controlId="formBasicAvatar">
|
|
|
- <Form.Label>Change Avatar:</Form.Label>
|
|
|
- <div className='d-flex'>
|
|
|
- <Form.Control type="file" className="me-1" name="picture" accept="image/*" onChange={e => setAvatar(e.target.files[0])} multiple={false} />
|
|
|
- <Button variant="outline-danger" type="submit">Save</Button>
|
|
|
- </div>
|
|
|
- </Form.Group>
|
|
|
- </div>
|
|
|
- </Form>
|
|
|
- <h5 className='d-flex justify-content-center'> Change Password:</h5>
|
|
|
- <Form onSubmit={postEditPassword} className='d-flex justify-content-center align-items-center'>
|
|
|
-
|
|
|
- <div>
|
|
|
- <Form.Group className="mb-3" controlId="formBasicNewPassword">
|
|
|
- <Form.Label>New Password:</Form.Label>
|
|
|
- <Form.Control type="password" className="" placeholder="new password"
|
|
|
- value={password} onChange={e => setPassword(e.target.value)} />
|
|
|
- <Form.Text className="text-muted">* Minimum 8 symbols.</Form.Text>
|
|
|
- </Form.Group>
|
|
|
-
|
|
|
|
|
|
- <Form.Group className="mb-3" controlId="formBasicConfirmPassword">
|
|
|
- <Form.Label>Confirm New Password:</Form.Label>
|
|
|
- <Form.Control type="password" placeholder="confirm new password"
|
|
|
- value={passwordConfirm} onChange={e => setPasswordConfirm(e.target.value)} />
|
|
|
- </Form.Group>
|
|
|
- <div className='d-flex justify-content-between'>
|
|
|
- <Button variant="outline-danger" type="submit" disabled={ password.length < 8 || password !== passwordConfirm}>
|
|
|
- Change Password
|
|
|
- </Button>
|
|
|
- <Link to={'/user'}>Back to home Page</Link>
|
|
|
+ <Form.Group className="col-6 px-3" controlId="formBasicConfirmPassword">
|
|
|
+ <Form.Label>Confirm New Password:</Form.Label>
|
|
|
+ <Form.Control type="password" placeholder="confirm new password"
|
|
|
+ value={passwordConfirm} onChange={e => setPasswordConfirm(e.target.value)} />
|
|
|
+ </Form.Group>
|
|
|
+ </div>
|
|
|
+ <div className='text-end'>
|
|
|
+ <Button variant="outline-success" type="submit" disabled={ password.length < 8 || password !== passwordConfirm}>
|
|
|
+ Change Password
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </Form>
|
|
|
+ </Accordion.Body>
|
|
|
+ </Accordion.Item>
|
|
|
+ </Accordion>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </Form>
|
|
|
</>)
|
|
|
}
|
|
|
export const CEditProfile = connect(state => ({ user: state.auth?.user }))(EditProfile);
|