|
@@ -10,7 +10,7 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
|
|
|
import { NewAuth } from "../reducers/actionAuthLog";
|
|
|
|
|
|
|
|
|
-const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, token, onLogin, onLogout, updateImg,
|
|
|
+const YourProfile = ({state, orders, loginStatus = {}, updateStatus, updatedUser = {}, newImg, token, onLogin, onLogout, updateImg,
|
|
|
updateUser, isUserAdmin = {}, status, data = {}, getData,
|
|
|
match:{params:{_id}}, isAdmin = [], isOwner = {}, newPicture = "clear"}) => {
|
|
|
|
|
@@ -22,6 +22,7 @@ const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, tok
|
|
|
const [password, changePassword] = useState(null);
|
|
|
const [password2, changePassword2] = useState(null);
|
|
|
const [isUpdateImg, changeImg] = useState(false);
|
|
|
+ const [falseTrying, OneRty] = useState(false)
|
|
|
// const [isUpdatePage, changePage] = useState(false);
|
|
|
// const [newImage, getImage] = useState({});
|
|
|
|
|
@@ -48,7 +49,7 @@ const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, tok
|
|
|
await onLogin(newLogin|| data.login, password || nowPassword);
|
|
|
|
|
|
}
|
|
|
- window.location.reload()
|
|
|
+ // window.location.reload()
|
|
|
|
|
|
}
|
|
|
}, [updateStatus])
|
|
@@ -61,8 +62,8 @@ const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, tok
|
|
|
const [searchInput, changeValue] = useState("Пошук");
|
|
|
|
|
|
|
|
|
- console.log(state);
|
|
|
- // console.log(data);
|
|
|
+ console.log(state);
|
|
|
+ // // console.log(data);
|
|
|
|
|
|
|
|
|
return (
|
|
@@ -103,7 +104,9 @@ const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, tok
|
|
|
<div className = "updateWrapper">
|
|
|
<h4>Редагування</h4>
|
|
|
|
|
|
- {updatedUser && updatedUser.errors && updatedUser.errors.length > 0 && <p>Цей логін вже зайнято</p>}
|
|
|
+ {((loginStatus.status && loginStatus.status == "RESOLVED" && !loginStatus.payload.data.login)
|
|
|
+ ||(updatedUser && updatedUser.errors && updatedUser.errors.length > 0))
|
|
|
+ && <p>Цей логін вже зайнято, або невірний пароль</p>}
|
|
|
|
|
|
|
|
|
{(!isAdmin || (isAdmin && isOwner.id == data._id))&&
|
|
@@ -124,29 +127,34 @@ const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, tok
|
|
|
( !isAdmin && !nowPassword) ||
|
|
|
((isAdmin && isOwner.id == data._id) && !nowPassword )}
|
|
|
onClick = {
|
|
|
- () => {
|
|
|
-
|
|
|
- let newUser = {};
|
|
|
- newUser._id = data._id;
|
|
|
- if(nick){
|
|
|
- newUser.nick = nick;
|
|
|
- }
|
|
|
- if (newLogin){
|
|
|
- newUser.login = newLogin;
|
|
|
- }
|
|
|
- if (password && password == password2) {
|
|
|
- newUser.password = password;
|
|
|
- } else if (password !== password2) {
|
|
|
- history.push("/loginError");
|
|
|
- return
|
|
|
- }
|
|
|
- if(isUpdateImg) {
|
|
|
+ async () => {
|
|
|
|
|
|
- newUser.avatar = {};
|
|
|
- newUser.avatar._id = newImg._id;
|
|
|
- newUser.avatar.url = newImg._url;
|
|
|
- }
|
|
|
- updateUser(newUser);
|
|
|
+ if(!isAdmin || (isAdmin && isOwner.id == data._id)){
|
|
|
+
|
|
|
+ await onLogin( data.login, nowPassword);
|
|
|
+
|
|
|
+ }
|
|
|
+ let newUser = {};
|
|
|
+ newUser._id = data._id;
|
|
|
+ if(nick){
|
|
|
+ newUser.nick = nick;
|
|
|
+ }
|
|
|
+ if (newLogin){
|
|
|
+ newUser.login = newLogin;
|
|
|
+ }
|
|
|
+ if (password && password == password2) {
|
|
|
+ newUser.password = password;
|
|
|
+ } else if (password !== password2) {
|
|
|
+ history.push("/loginError");
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(isUpdateImg) {
|
|
|
+
|
|
|
+ newUser.avatar = {};
|
|
|
+ newUser.avatar._id = newImg._id;
|
|
|
+ newUser.avatar.url = newImg._url;
|
|
|
+ }
|
|
|
+ updateUser(newUser);
|
|
|
|
|
|
|
|
|
|
|
@@ -187,6 +195,8 @@ const mapStateToProps = state => ({
|
|
|
state.promiseRed.newUser.payload && state.promiseRed.newUser.payload.data &&
|
|
|
state.promiseRed.newUser.payload,
|
|
|
|
|
|
+ loginStatus: state.promiseRed && state.promiseRed.login,
|
|
|
+
|
|
|
updateStatus: state.promiseRed && state.promiseRed.newUser &&
|
|
|
state.promiseRed.newUser.status,
|
|
|
|