|
@@ -1,4 +1,4 @@
|
|
-import {CUpdateForm, CUsersList, SearchUserInput, CUpdateAdminForm} from "./index";
|
|
|
|
|
|
+import {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, actionLogin } from "../reducers";
|
|
actionUserUpdate,getData, actionLogin } from "../reducers";
|
|
@@ -10,29 +10,43 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
|
|
import { NewAuth } from "../reducers/actionAuthLog";
|
|
import { NewAuth } from "../reducers/actionAuthLog";
|
|
|
|
|
|
|
|
|
|
-const YourProfile = ({state, updatedUser = {}, isImg, token, onLogin, onLogout, updateImg,
|
|
|
|
|
|
+const YourProfile = ({state, updateStatus, updatedUser = {}, newImg, token, onLogin, onLogout, updateImg,
|
|
updateUser, isUserAdmin = {}, status, data = {}, getData,
|
|
updateUser, isUserAdmin = {}, status, data = {}, getData,
|
|
match:{params:{_id}}, isAdmin = [], isOwner = {}, newPicture = "clear"}) => {
|
|
match:{params:{_id}}, isAdmin = [], isOwner = {}, newPicture = "clear"}) => {
|
|
|
|
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
|
|
|
|
- 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 [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);
|
|
- const [isUpdatePage, changePage] = useState(false);
|
|
|
|
- const [newImage, getImage] = useState({});
|
|
|
|
|
|
+ // const [isUpdatePage, changePage] = useState(false);
|
|
|
|
+ // 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])
|
|
|
|
|
|
+ useEffect(
|
|
|
|
+ async() => {
|
|
|
|
+
|
|
|
|
+ if(updateStatus == "RESOLVED" && updatedUser && updatedUser.data && updatedUser.data.UserUpsert) {
|
|
|
|
+
|
|
|
|
+ if(!isAdmin || (isAdmin && isOwner.id == data._id)){
|
|
|
|
+
|
|
|
|
+ await onLogin(newLogin|| data.login, password || nowPassword);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ window.location.reload()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }, [updateStatus])
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
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);
|
|
- const [showAdminUpdate, onAdmin] = useState(false);
|
|
|
|
const [searchInput, changeValue] = useState("Пошук");
|
|
const [searchInput, changeValue] = useState("Пошук");
|
|
|
|
|
|
|
|
|
|
@@ -82,12 +96,12 @@ const YourProfile = ({state, updatedUser = {}, isImg, token, onLogin, onLogout,
|
|
|
|
|
|
|
|
|
|
{(!isAdmin || (isAdmin && isOwner.id == data._id))&&
|
|
{(!isAdmin || (isAdmin && isOwner.id == data._id))&&
|
|
- <input onChange = {(e) => superPassword(e.target.value)} placeholder = "Пароль для зміни даних"/>}
|
|
|
|
|
|
+ <input type = "password" 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) => changePassword2(e.target.value)} placeholder = "Повторіть пароль"/>
|
|
|
|
|
|
+ <input type = "password" onChange = {(e) => changePassword(e.target.value)} placeholder = "Новий пароль"/>
|
|
|
|
+ <input type = "password" onChange = {(e) => changePassword2(e.target.value)} placeholder = "Повторіть пароль"/>
|
|
<input type="file" name="photo" id='photo'
|
|
<input type="file" name="photo" id='photo'
|
|
onChange={(ev) => {
|
|
onChange={(ev) => {
|
|
updateImg(ev.target.files[0])
|
|
updateImg(ev.target.files[0])
|
|
@@ -95,16 +109,13 @@ const YourProfile = ({state, updatedUser = {}, isImg, token, onLogin, onLogout,
|
|
changeImg(true);
|
|
changeImg(true);
|
|
}
|
|
}
|
|
}/>
|
|
}/>
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
<button disabled = {(newPicture == "PENDING") ||
|
|
<button disabled = {(newPicture == "PENDING") ||
|
|
( !isAdmin && !nowPassword) ||
|
|
( !isAdmin && !nowPassword) ||
|
|
((isAdmin && isOwner.id == data._id) && !nowPassword )}
|
|
((isAdmin && isOwner.id == data._id) && !nowPassword )}
|
|
onClick = {
|
|
onClick = {
|
|
() => {
|
|
() => {
|
|
|
|
|
|
- let newUser = {}
|
|
|
|
|
|
+ let newUser = {};
|
|
newUser._id = data._id;
|
|
newUser._id = data._id;
|
|
if(nick){
|
|
if(nick){
|
|
newUser.nick = nick;
|
|
newUser.nick = nick;
|
|
@@ -121,29 +132,13 @@ const YourProfile = ({state, updatedUser = {}, isImg, token, onLogin, onLogout,
|
|
if(isUpdateImg) {
|
|
if(isUpdateImg) {
|
|
|
|
|
|
newUser.avatar = {};
|
|
newUser.avatar = {};
|
|
- newUser.avatar._id = isImg._id;
|
|
|
|
- newUser.avatar.url = isImg._url;
|
|
|
|
|
|
+ newUser.avatar._id = newImg._id;
|
|
|
|
+ newUser.avatar.url = newImg._url;
|
|
}
|
|
}
|
|
updateUser(newUser);
|
|
updateUser(newUser);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
- if(!isAdmin || (isAdmin && isOwner.id == data._id)){
|
|
|
|
-
|
|
|
|
- onLogin(newLogin|| data.login, password || nowPassword);
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- window.location.reload();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}}>Зберегти</button>
|
|
}}>Зберегти</button>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@@ -181,6 +176,9 @@ const mapStateToProps = state => ({
|
|
state.promiseRed.newUser.payload && state.promiseRed.newUser.payload.data &&
|
|
state.promiseRed.newUser.payload && state.promiseRed.newUser.payload.data &&
|
|
state.promiseRed.newUser.payload,
|
|
state.promiseRed.newUser.payload,
|
|
|
|
|
|
|
|
+ updateStatus: state.promiseRed && state.promiseRed.newUser &&
|
|
|
|
+ state.promiseRed.newUser.status,
|
|
|
|
+
|
|
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 &&
|
|
@@ -190,7 +188,7 @@ const mapStateToProps = state => ({
|
|
isOwner: state.auth && state.auth.payload && state.auth.payload.sub &&
|
|
isOwner: state.auth && state.auth.payload && state.auth.payload.sub &&
|
|
state.auth.payload.sub,
|
|
state.auth.payload.sub,
|
|
|
|
|
|
- isImg: state.promiseRed && state.promiseRed.photo &&
|
|
|
|
|
|
+ newImg: state.promiseRed && state.promiseRed.photo &&
|
|
state.promiseRed.photo.payload && state.promiseRed.photo.payload,
|
|
state.promiseRed.photo.payload && state.promiseRed.photo.payload,
|
|
|
|
|
|
isAdmin: state.auth && state.auth.payload && state.auth.payload.sub &&
|
|
isAdmin: state.auth && state.auth.payload && state.auth.payload.sub &&
|