//notifications //delete restaurant //change picture //redesigned data store
107 lines
2.6 KiB
JavaScript
107 lines
2.6 KiB
JavaScript
const initialState = {
|
|
showDishList: false,
|
|
loggedIn: false,
|
|
username: "",
|
|
userId: "",
|
|
userEmail: "",
|
|
userData: {
|
|
jwt: "",
|
|
firstname: "",
|
|
lastname: "",
|
|
userId: "",
|
|
userEmail: "",
|
|
billing: {
|
|
NIP: "",
|
|
adress: "",
|
|
companyName: "",
|
|
},
|
|
restaurants: [],
|
|
},
|
|
dialogs: {
|
|
regulamin: false,
|
|
},
|
|
backdrop: false,
|
|
tempData: {},
|
|
};
|
|
|
|
const data = (state = initialState, action) => {
|
|
switch (action.type) {
|
|
case "SET_DISHLIST_VISIBLE":
|
|
return (state = { ...state, showDishList: true });
|
|
case "SET_DISHLIST_HIDDEN":
|
|
return (state = { ...state, showDishList: false });
|
|
case "SET_LOGGEDIN":
|
|
return (state = {
|
|
...state,
|
|
loggedIn: true,
|
|
userData: {
|
|
jwt: action.payload.jwt,
|
|
firstname: action.payload.firstname,
|
|
lastname: action.payload.lastname,
|
|
userId: action.payload.userId,
|
|
userEmail: action.payload.email,
|
|
billing: {
|
|
NIP: action.payload.NIP,
|
|
adress: action.payload.adress,
|
|
companyName: action.payload.companyName,
|
|
},
|
|
restaurants: action.payload.restaurants,
|
|
},
|
|
});
|
|
case "SET_LOGGEDOUT":
|
|
return (state = {
|
|
...state,
|
|
loggedIn: false,
|
|
userData: {
|
|
jwt: "",
|
|
firstname: "",
|
|
lastname: "",
|
|
userId: "",
|
|
userEmail: "",
|
|
billing: {
|
|
NIP: "",
|
|
adress: "",
|
|
companyName: "",
|
|
},
|
|
restaurants: [],
|
|
},
|
|
});
|
|
case "DIALOG_REGULAMIN_SHOW":
|
|
return (state = {
|
|
...state,
|
|
dialogs: { ...state.dialogs, regulamin: true },
|
|
});
|
|
case "DIALOG_REGULAMIN_HIDE":
|
|
return (state = {
|
|
...state,
|
|
dialogs: { ...state.dialogs, regulamin: false },
|
|
});
|
|
case "SET_TEMP_DATA":
|
|
return (state = { ...state, tempData: action.payload });
|
|
case "CLEAR_TEMP_DATA":
|
|
return (state = { ...state, tempData: {} });
|
|
case "SHOW_BACKDROP":
|
|
return (state = { ...state, backdrop: true });
|
|
case "HIDE_BACKDROP":
|
|
return (state = { ...state, backdrop: false });
|
|
case "UPDATE_RESTAURANT":
|
|
return (state = {
|
|
...state,
|
|
userData: {
|
|
...state.userData,
|
|
restaurants: state.userData.restaurants.map((restaurant) => {
|
|
if (restaurant._id === action.payload._id) {
|
|
return action.payload;
|
|
} else {
|
|
return restaurant;
|
|
}
|
|
}),
|
|
},
|
|
});
|
|
default:
|
|
return state;
|
|
}
|
|
};
|
|
|
|
export default data;
|