web client v 0.1
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import axios from "axios";
|
||||
import * as toggles from "./toggles";
|
||||
import { push } from "connected-react-router";
|
||||
|
||||
const backend = "http://localhost:4000/";
|
||||
|
||||
const autocomplete = (input) => {
|
||||
@@ -23,7 +25,6 @@ export const fetchAutocomplete = (input) => {
|
||||
const cities = Array.from(response.data.cities);
|
||||
const restaurants = Array.from(response.data.restaurants);
|
||||
const options = cities.concat(restaurants);
|
||||
|
||||
dispatch(autocomplete(options));
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -40,7 +41,7 @@ export const fetchSearch = (input) => {
|
||||
const data = response.data;
|
||||
if (Object.keys(data).length > 0) {
|
||||
dispatch(setSearchResults(data));
|
||||
dispatch(setAppMode("APP_SEARCH_RESULTS"));
|
||||
dispatch(push("/results"));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -63,12 +64,6 @@ export const setSearchQuery = (input) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const setAppMode = (mode) => {
|
||||
return {
|
||||
type: mode,
|
||||
};
|
||||
};
|
||||
|
||||
export const setRestaurant = (restaurant) => {
|
||||
return {
|
||||
type: "SET_RESTAURANT",
|
||||
@@ -83,7 +78,7 @@ export const fetchRestaurant = (id) => {
|
||||
.then((response) => {
|
||||
dispatch(setRestaurant(response.data));
|
||||
dispatch(toggles.hideDishes());
|
||||
dispatch(setAppMode("APP_RESTAURANT"));
|
||||
dispatch(push("/restaurant"));
|
||||
dispatch(fetchAllDishes(id));
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
@@ -112,11 +107,11 @@ export const tryLogin = (username, password) => {
|
||||
const data = { email: username, password: password };
|
||||
|
||||
return function (dispatch) {
|
||||
dispatch(toggles.setLoginResult(""));
|
||||
axios
|
||||
.post(backend + "user/login", data)
|
||||
.then((response) => {
|
||||
const jwt = response.headers["x-auth-token"];
|
||||
console.log(response.headers);
|
||||
dispatch(
|
||||
toggles.setLoggedIn(
|
||||
response.data.firstname,
|
||||
@@ -125,7 +120,7 @@ export const tryLogin = (username, password) => {
|
||||
response.data.email
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideLoginDialog());
|
||||
dispatch(push("/"));
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response.status === 404) {
|
||||
@@ -143,6 +138,46 @@ export const tryLogin = (username, password) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const remindPassword = (email) => {
|
||||
return function (dispatch) {
|
||||
const data = { email: email };
|
||||
dispatch(toggles.setReminderResult(""));
|
||||
dispatch(toggles.showReminderCircle());
|
||||
axios
|
||||
.post(backend + "user/forgotpassword", data)
|
||||
.then((response) => {
|
||||
dispatch(toggles.hideReminderCircle());
|
||||
dispatch(toggles.setReminderResult(response.data));
|
||||
})
|
||||
.catch((e) => {
|
||||
dispatch(toggles.hideReminderCircle());
|
||||
dispatch(toggles.setReminderResult(e.response.data));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const changePassword = (email, password, token) => {
|
||||
return function (dispatch) {
|
||||
const data = {
|
||||
token: token,
|
||||
email: email,
|
||||
newPass: password,
|
||||
};
|
||||
dispatch(toggles.setResetResult(""));
|
||||
dispatch(toggles.showResetCircle());
|
||||
axios
|
||||
.post(backend + "user/resetpass", data)
|
||||
.then((response) => {
|
||||
dispatch(toggles.hideResetCircle());
|
||||
dispatch(toggles.setResetResult(response.data));
|
||||
})
|
||||
.catch((e) => {
|
||||
dispatch(toggles.hideResetCircle());
|
||||
dispatch(toggles.setResetResult(e.response.data));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
return function (dispatch) {
|
||||
dispatch(toggles.setLoggedOut());
|
||||
@@ -151,6 +186,7 @@ export const logout = () => {
|
||||
|
||||
export const tryRegister = (data) => {
|
||||
return function (dispatch) {
|
||||
dispatch(toggles.setRegisterResult(""));
|
||||
dispatch(toggles.showRegisterCircle());
|
||||
axios
|
||||
.post(backend + "user/register", data)
|
||||
|
||||
Reference in New Issue
Block a user