|
@@ -1,23 +1,25 @@
|
|
import {CUpdateForm, CUsersList, SearchUserInput, CUpdateAdminForm} from "./index";
|
|
import {CUpdateForm, CUsersList, SearchUserInput, CUpdateAdminForm} from "./index";
|
|
import {gql, urlUpload, actionPromise, actionGoodCard, getGoods,
|
|
import {gql, urlUpload, actionPromise, actionGoodCard, getGoods,
|
|
actionUserFindOne, updateImgAction, actionAuthLogin, actionAuthLogout,
|
|
actionUserFindOne, updateImgAction, actionAuthLogin, actionAuthLogout,
|
|
- actionUserUpdate,getData } from "../reducers";
|
|
|
|
|
|
+ actionUserUpdate,getData, actionLogin } from "../reducers";
|
|
import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
|
|
import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
|
|
import { connect } from "react-redux";
|
|
import { connect } from "react-redux";
|
|
import { useEffect, useState, useRef } from "react";
|
|
import { useEffect, useState, useRef } from "react";
|
|
|
|
|
|
import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
|
|
import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
|
|
|
|
+import { NewAuth } from "../reducers/actionAuthLog";
|
|
|
|
|
|
|
|
|
|
-const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
|
|
- updateUser, isUserAdmin, status, data = {}, getData,
|
|
|
|
- match:{params:{_id}}, isAdmin = [], isOwner, newPicture = "clear"}) => {
|
|
|
|
|
|
+const YourProfile = ({state, updatedUser = {}, isImg, token, onLogin, onLogout, updateImg,
|
|
|
|
+ updateUser, isUserAdmin = {}, status, data = {}, getData,
|
|
|
|
+ match:{params:{_id}}, isAdmin = [], isOwner = {}, newPicture = "clear"}) => {
|
|
|
|
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
|
|
|
|
const formRef = useRef(null);
|
|
const formRef = useRef(null);
|
|
const [nick, changeNick] = useState(null);
|
|
const [nick, changeNick] = useState(null);
|
|
const [newLogin, changeLogin] = useState(null);
|
|
const [newLogin, changeLogin] = useState(null);
|
|
|
|
+ const [nowPassword, superPassword] = useState(null);
|
|
const [password, changePassword] = useState(null);
|
|
const [password, changePassword] = useState(null);
|
|
const [password2, changePassword2] = useState(null);
|
|
const [password2, changePassword2] = useState(null);
|
|
const [isUpdateImg, changeImg] = useState(false);
|
|
const [isUpdateImg, changeImg] = useState(false);
|
|
@@ -25,6 +27,8 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
const [newImage, getImage] = useState({});
|
|
const [newImage, getImage] = useState({});
|
|
|
|
|
|
useEffect(() => history.location.pathname.includes(`/profile/`) ? getData(`${isOwner.id}`) : getData(`${_id}`),[history.location.pathname])
|
|
useEffect(() => history.location.pathname.includes(`/profile/`) ? getData(`${isOwner.id}`) : getData(`${_id}`),[history.location.pathname])
|
|
|
|
+
|
|
|
|
+ useEffect(() => updatedUser && updatedUser.data && updatedUser.data.UserUpsert && window.location.reload(), [updatedUser])
|
|
|
|
|
|
const date = new Date(data ? +data.createdAt : 0);
|
|
const date = new Date(data ? +data.createdAt : 0);
|
|
const [showUpdate, onShow] = useState(false);
|
|
const [showUpdate, onShow] = useState(false);
|
|
@@ -32,8 +36,8 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
const [searchInput, changeValue] = useState("Пошук");
|
|
const [searchInput, changeValue] = useState("Пошук");
|
|
|
|
|
|
|
|
|
|
- console.log(isOwner);
|
|
|
|
- console.log(data);
|
|
|
|
|
|
+ // console.log(state);
|
|
|
|
+ // console.log(data);
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -59,13 +63,13 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
|
|
- { (isOwner.login == data.login) ? <h2>Привіт, {data.nick || "людино"}!</h2> : <h2>{data.nick}</h2>}
|
|
|
|
|
|
+ { (isOwner.id == data._id) ? <h2>Привіт, {data.nick || "людино"}!</h2> : <h2>{data.nick || data.login}</h2>}
|
|
|
|
|
|
<img src={data.avatar ? `${urlUpload}/${data.avatar.url}`: 'https://pngicon.ru/file/uploads/picca-1.png'} />
|
|
<img src={data.avatar ? `${urlUpload}/${data.avatar.url}`: 'https://pngicon.ru/file/uploads/picca-1.png'} />
|
|
<span>
|
|
<span>
|
|
Сторінку створено {`${date.getDate()}. ${date.getMonth() + 1}. ${date.getFullYear()} о ${date.getHours()}: ${date.getMinutes()}: ${date.getSeconds()} `}
|
|
Сторінку створено {`${date.getDate()}. ${date.getMonth() + 1}. ${date.getFullYear()} о ${date.getHours()}: ${date.getMinutes()}: ${date.getSeconds()} `}
|
|
</span>
|
|
</span>
|
|
- {( (isOwner.login == data.login) || (isAdmin && !isUserAdmin)) &&
|
|
|
|
|
|
+ {( (isOwner.id == data._id) || (isAdmin && !isUserAdmin)) &&
|
|
<span>
|
|
<span>
|
|
<button onClick = {() => onShow(!showUpdate)}>Редагувати</button>
|
|
<button onClick = {() => onShow(!showUpdate)}>Редагувати</button>
|
|
</span>
|
|
</span>
|
|
@@ -73,6 +77,13 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
{showUpdate &&
|
|
{showUpdate &&
|
|
<div className = "updateWrapper">
|
|
<div className = "updateWrapper">
|
|
<h4>Редагування</h4>
|
|
<h4>Редагування</h4>
|
|
|
|
+
|
|
|
|
+ {updatedUser && updatedUser.errors && updatedUser.errors.length > 0 && <p>Введено невірні дані, або цей логін вже зайнято</p>}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ {(!isAdmin || (isAdmin && isOwner.id == data._id))&&
|
|
|
|
+ <input onChange = {(e) => superPassword(e.target.value)} placeholder = "Пароль для зміни даних"/>}
|
|
|
|
+
|
|
<input onChange = {(e) => changeNick(e.target.value)} placeholder = "Новий нікнейм"/>
|
|
<input onChange = {(e) => changeNick(e.target.value)} placeholder = "Новий нікнейм"/>
|
|
<input onChange = {(e) => changeLogin(e.target.value)} placeholder = "Новий логін"/>
|
|
<input onChange = {(e) => changeLogin(e.target.value)} placeholder = "Новий логін"/>
|
|
<input onChange = {(e) => changePassword(e.target.value)} placeholder = "Новий пароль"/>
|
|
<input onChange = {(e) => changePassword(e.target.value)} placeholder = "Новий пароль"/>
|
|
@@ -84,7 +95,14 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
changeImg(true);
|
|
changeImg(true);
|
|
}
|
|
}
|
|
}/>
|
|
}/>
|
|
- <button disabled = {newPicture == "PENDING"} onClick = {() => {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <button disabled = {(newPicture == "PENDING") ||
|
|
|
|
+ ( !isAdmin && !nowPassword) ||
|
|
|
|
+ ((isAdmin && isOwner.id == data._id) && !nowPassword )}
|
|
|
|
+ onClick = {
|
|
|
|
+ () => {
|
|
|
|
|
|
let newUser = {}
|
|
let newUser = {}
|
|
newUser._id = data._id;
|
|
newUser._id = data._id;
|
|
@@ -106,15 +124,27 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
newUser.avatar._id = isImg._id;
|
|
newUser.avatar._id = isImg._id;
|
|
newUser.avatar.url = isImg._url;
|
|
newUser.avatar.url = isImg._url;
|
|
}
|
|
}
|
|
- updateUser(newUser);
|
|
|
|
|
|
+ updateUser(newUser);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(!isAdmin || (isAdmin && isOwner.id == data._id)){
|
|
|
|
+
|
|
|
|
+ onLogin(newLogin|| data.login, password || nowPassword);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ window.location.reload();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
- !isAdmin ? onLogout() : window.location.reload();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}>Зберегти</button>
|
|
}}>Зберегти</button>
|
|
- {(isAdmin && (isOwner.login != data.login)) && <button className = "redAlert">Видалити юзера</button>}
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@@ -125,8 +155,7 @@ const YourProfile = ({state, isImg, token, onLogin, onLogout, updateImg,
|
|
</div>
|
|
</div>
|
|
</>
|
|
</>
|
|
}
|
|
}
|
|
- {status === ("PENDING") && <>Loading</>}
|
|
|
|
- {/* {(status == "RESOLVED" && !data) && history.push("/error/")} */}
|
|
|
|
|
|
+
|
|
</>
|
|
</>
|
|
)
|
|
)
|
|
|
|
|
|
@@ -148,6 +177,10 @@ const mapStateToProps = state => ({
|
|
|
|
|
|
token: state.auth && state.auth.token,
|
|
token: state.auth && state.auth.token,
|
|
|
|
|
|
|
|
+ updatedUser: state.promiseRed && state.promiseRed.newUser &&
|
|
|
|
+ state.promiseRed.newUser.payload && state.promiseRed.newUser.payload.data &&
|
|
|
|
+ state.promiseRed.newUser.payload,
|
|
|
|
+
|
|
isUserAdmin: state.promiseRed && state.promiseRed.user &&
|
|
isUserAdmin: state.promiseRed && state.promiseRed.user &&
|
|
state.promiseRed.user.payload && state.promiseRed.user.payload.data &&
|
|
state.promiseRed.user.payload && state.promiseRed.user.payload.data &&
|
|
state.promiseRed.user.payload.data.UserFindOne &&
|
|
state.promiseRed.user.payload.data.UserFindOne &&
|
|
@@ -171,14 +204,10 @@ const mapStateToProps = state => ({
|
|
updateImg: updateImgAction,
|
|
updateImg: updateImgAction,
|
|
updateUser: actionUserUpdate,
|
|
updateUser: actionUserUpdate,
|
|
onLogout: actionAuthLogout,
|
|
onLogout: actionAuthLogout,
|
|
- onLogin: actionAuthLogin
|
|
|
|
|
|
+ onLogin: actionLogin
|
|
}, dispatch);
|
|
}, dispatch);
|
|
|
|
|
|
const CYourProfile = connect(mapStateToProps, mapDispatchToProps)
|
|
const CYourProfile = connect(mapStateToProps, mapDispatchToProps)
|
|
(YourProfile)
|
|
(YourProfile)
|
|
export default CYourProfile;
|
|
export default CYourProfile;
|
|
|
|
|
|
-
|
|
|
|
- {/* <div class="spinner-border text-secondary" role="status">
|
|
|
|
- <span class="sr-only"></span>
|
|
|
|
-</div> */}
|
|
|