|
@@ -1,6 +1,5 @@
|
|
|
-import {gqlLogin, gqlRegistration} from "../../shared/services&utilits/gqlRequest";
|
|
|
+import {actionAboutMe, gqlLogin, gqlRegistration} from "../../shared/services&utilits/gqlRequest";
|
|
|
import {jwtDecode} from "../../shared/services&utilits/utilits";
|
|
|
-import {Link} from "react-router-dom";
|
|
|
|
|
|
export const changeAuthData = authData => ({
|
|
|
type: "CHANGE_AUTH_DATA",
|
|
@@ -13,11 +12,9 @@ export const setError = error => ({
|
|
|
})
|
|
|
|
|
|
export const changeAuthDataAsync = ({login, password, authType, navigateCallback}) => {
|
|
|
- console.log(navigateCallback)
|
|
|
return async (dispatch) => {
|
|
|
let response = ""
|
|
|
if (authType === "signUp") {
|
|
|
- console.log("Регистрация")
|
|
|
response = await gqlRegistration(login, password)
|
|
|
if (!response.ok) {
|
|
|
dispatch(setError("Server is not answer"))
|
|
@@ -26,17 +23,16 @@ export const changeAuthDataAsync = ({login, password, authType, navigateCallback
|
|
|
const responseData = await response.json();
|
|
|
console.log(responseData)
|
|
|
const user = responseData.data.createUser;
|
|
|
-
|
|
|
+ console.log(user)
|
|
|
if (user) {
|
|
|
dispatch(changeAuthDataAsync({login, password, authType: "signIn", navigateCallback}))
|
|
|
+
|
|
|
} else {
|
|
|
dispatch(setError("Login is already exist"))
|
|
|
}
|
|
|
}
|
|
|
if (authType === "signIn") {
|
|
|
- console.log(login,password)
|
|
|
response = await gqlLogin(login, password)
|
|
|
- console.log(response)
|
|
|
if (!response.ok) {
|
|
|
dispatch(setError("Server is not answer"))
|
|
|
}
|
|
@@ -47,20 +43,33 @@ export const changeAuthDataAsync = ({login, password, authType, navigateCallback
|
|
|
if (jwtDecode(token)){
|
|
|
localStorage.authToken = token
|
|
|
}
|
|
|
- // console.log(jwtDecode(token))
|
|
|
-
|
|
|
|
|
|
if (!token) {
|
|
|
dispatch(setError("Wrong login or password"))
|
|
|
} else {
|
|
|
dispatch(changeAuthData({token: token, user: jwtDecode(token)}))
|
|
|
dispatch(setError(null))
|
|
|
- console.log(navigateCallback)
|
|
|
navigateCallback("../profile")
|
|
|
}
|
|
|
}
|
|
|
- if (authType === "ownerData") {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+export const setActiveUserDataAsync = (id) => {
|
|
|
+ return async (dispatch) => {
|
|
|
+ let response = ""
|
|
|
+
|
|
|
+ response = await actionAboutMe(id)
|
|
|
+
|
|
|
+ if (!response.ok) {
|
|
|
+ dispatch(setError("No user data received"))
|
|
|
+ }
|
|
|
+ const responseData = await response.json();
|
|
|
+ console.log(responseData)
|
|
|
+ dispatch(setActiveUserData(responseData.data.UserFindOne))
|
|
|
+ }
|
|
|
+};
|
|
|
+export const setActiveUserData =(data)=>({
|
|
|
+ type: "SET_ACTIVE_USER_DATA",
|
|
|
+ payload: data,
|
|
|
+} )
|