web client v0.5
//notifications //delete restaurant //change picture //redesigned data store
This commit is contained in:
@@ -81,7 +81,9 @@ export const fetchRestaurant = (id) => {
|
||||
dispatch(push("/restaurant"));
|
||||
dispatch(fetchAllDishes(id));
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
.catch((err) =>
|
||||
dispatch(notification("Nie udało się pobrać restauracji.", "error"))
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -103,11 +105,41 @@ export const fetchAllDishes = (id) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const refreshUserData = (token) => {
|
||||
return function (dispatch) {
|
||||
axios({
|
||||
url: backend + "user/refresh",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"x-auth-token": token,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch(
|
||||
toggles.setLoggedIn(
|
||||
response.data.firstname,
|
||||
response.data.lastname,
|
||||
token,
|
||||
response.data.id,
|
||||
response.data.email,
|
||||
response.data.NIP,
|
||||
response.data.adress,
|
||||
response.data.companyName,
|
||||
response.data.restaurants
|
||||
)
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const tryLogin = (username, password) => {
|
||||
const data = { email: username, password: password };
|
||||
|
||||
return function (dispatch) {
|
||||
dispatch(toggles.setLoginResult(""));
|
||||
dispatch(toggles.showBackdrop());
|
||||
axios
|
||||
.post(backend + "user/login", data)
|
||||
.then((response) => {
|
||||
@@ -125,21 +157,22 @@ export const tryLogin = (username, password) => {
|
||||
response.data.restaurants
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(`Witaj ${response.data.firstname}!`, "success"));
|
||||
dispatch(push("/"));
|
||||
})
|
||||
.catch((err) => {
|
||||
if (!err.response) {
|
||||
console.log(err);
|
||||
} else if (err.response.status === 404) {
|
||||
dispatch(
|
||||
toggles.setLoginResult(
|
||||
"Użytkownik o podanym adresie email nie istnieje."
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification("Użytkownik nie istnieje :(", "error"));
|
||||
} else if (err.response.status === 401) {
|
||||
dispatch(toggles.setLoginResult("Podane hasło jest nieprawidłowe"));
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification("Błędne dane logowania :(", "error"));
|
||||
} else {
|
||||
dispatch(toggles.setLoginResult("Błąd serwera..."));
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification("Błąd serwera :(", "error"));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -148,17 +181,16 @@ export const tryLogin = (username, password) => {
|
||||
export const remindPassword = (email) => {
|
||||
return function (dispatch) {
|
||||
const data = { email: email };
|
||||
dispatch(toggles.setReminderResult(""));
|
||||
dispatch(toggles.showReminderCircle());
|
||||
dispatch(toggles.showBackdrop());
|
||||
axios
|
||||
.post(backend + "user/forgotpassword", data)
|
||||
.then((response) => {
|
||||
dispatch(toggles.hideReminderCircle());
|
||||
dispatch(toggles.setReminderResult(response.data));
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(response.data, "info"));
|
||||
})
|
||||
.catch((e) => {
|
||||
dispatch(toggles.hideReminderCircle());
|
||||
dispatch(toggles.setReminderResult(e.response.data));
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(e.response.data, "error"));
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -170,59 +202,60 @@ export const changePassword = (email, password, token) => {
|
||||
email: email,
|
||||
newPass: password,
|
||||
};
|
||||
dispatch(toggles.setResetResult(""));
|
||||
dispatch(toggles.showResetCircle());
|
||||
dispatch(toggles.showBackdrop());
|
||||
axios
|
||||
.post(backend + "user/resetpass", data)
|
||||
.then((response) => {
|
||||
dispatch(toggles.hideResetCircle());
|
||||
dispatch(toggles.setResetResult(response.data));
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(response.data, "info"));
|
||||
})
|
||||
.catch((e) => {
|
||||
dispatch(toggles.hideResetCircle());
|
||||
dispatch(toggles.setResetResult(e.response.data));
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(e.response.data, "error"));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
return function (dispatch) {
|
||||
dispatch(notification("Poprawnie wylogowano.", "success"));
|
||||
dispatch(toggles.setLoggedOut());
|
||||
};
|
||||
};
|
||||
|
||||
export const tryRegister = (data) => {
|
||||
return function (dispatch) {
|
||||
dispatch(toggles.setRegisterResult(""));
|
||||
dispatch(toggles.showRegisterCircle());
|
||||
dispatch(toggles.showBackdrop());
|
||||
axios
|
||||
.post(backend + "user/register", data)
|
||||
.then((response) => {
|
||||
if (response.status === 201) {
|
||||
dispatch(
|
||||
toggles.setRegisterResult(
|
||||
"Dziękujemy za rejestrację. Teraz możesz zalogować się do swojego konta."
|
||||
notification(
|
||||
"Rejestracja przebiegła pomyślnie, możesz teraz zalogować się do swojego konta.",
|
||||
"success"
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideRegisterCircle());
|
||||
dispatch(toggles.hideRegisterForm());
|
||||
dispatch(toggles.hideBackdrop());
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response.status === 500) {
|
||||
dispatch(
|
||||
toggles.setRegisterResult(
|
||||
"Wystąpił nieoczekiwany błąd serwera, przepraszamy..."
|
||||
notification(
|
||||
"Wystąpił nieoczekiwany błąd serwera, przepraszamy...",
|
||||
"error"
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideRegisterCircle());
|
||||
dispatch(toggles.hideBackdrop());
|
||||
} else if (err.response.status === 409) {
|
||||
dispatch(
|
||||
toggles.setRegisterResult(
|
||||
"Adres email jest już zajęty, proszę użyć innego."
|
||||
notification(
|
||||
"Adres email jest już zajęty, proszę użyć innego.",
|
||||
"error"
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideRegisterCircle());
|
||||
dispatch(toggles.hideBackdrop());
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -240,3 +273,24 @@ export const clearTempData = () => {
|
||||
type: "CLEAR_TEMP_DATA",
|
||||
};
|
||||
};
|
||||
|
||||
export const notification = (message, type) => {
|
||||
return function (dispatch) {
|
||||
dispatch(
|
||||
toggles.enqueueSnackbar({
|
||||
message: message,
|
||||
options: {
|
||||
key: new Date().getTime() + Math.random(),
|
||||
variant: type,
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export const updateRestaurant = (restaurant) => {
|
||||
return {
|
||||
type: "UPDATE_RESTAURANT",
|
||||
payload: restaurant,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user