redux to react-redux
This commit is contained in:
@@ -1,37 +1,5 @@
|
||||
const initialState = {
|
||||
showDishList: false,
|
||||
loggedIn: false,
|
||||
userData: {
|
||||
jwt: "",
|
||||
firstname: "",
|
||||
lastname: "",
|
||||
userId: "",
|
||||
userEmail: "",
|
||||
billing: {
|
||||
NIP: "",
|
||||
adress: "",
|
||||
companyName: "",
|
||||
},
|
||||
restaurants: [],
|
||||
isRestaurant: false
|
||||
},
|
||||
dialogs: {
|
||||
regulamin: false,
|
||||
},
|
||||
backdrop: false,
|
||||
tempData: {},
|
||||
filters: {
|
||||
types: [],
|
||||
tags: []
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
@@ -49,7 +17,7 @@ const data = (state = initialState, action) => {
|
||||
companyName: action.payload.companyName,
|
||||
},
|
||||
restaurants: action.payload.restaurants,
|
||||
isRestaurant: action.payload.isRestaurant
|
||||
isRestaurant: action.payload.isRestaurant,
|
||||
},
|
||||
});
|
||||
case "SET_LOGGEDOUT":
|
||||
@@ -68,29 +36,17 @@ const data = (state = initialState, action) => {
|
||||
companyName: "",
|
||||
},
|
||||
restaurants: [],
|
||||
isRestaurant: false
|
||||
isRestaurant: false,
|
||||
},
|
||||
});
|
||||
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":
|
||||
const index = state.userData.restaurants.findIndex((restaurant) => restaurant._id === action.payload._id);
|
||||
const index = state.userData.restaurants.findIndex(
|
||||
(restaurant) => restaurant._id === action.payload._id
|
||||
);
|
||||
return (state = {
|
||||
...state,
|
||||
userData: {
|
||||
@@ -98,16 +54,25 @@ const data = (state = initialState, action) => {
|
||||
restaurants: [
|
||||
...state.userData.restaurants.slice(0, index),
|
||||
action.payload,
|
||||
...state.userData.restaurants.slice(index + 1)
|
||||
...state.userData.restaurants.slice(index + 1),
|
||||
],
|
||||
},
|
||||
});
|
||||
case "SET_NEW_TOKEN":
|
||||
return (state = {...state, userData: {...state.userData, jwt: action.payload}})
|
||||
return (state = {
|
||||
...state,
|
||||
userData: { ...state.userData, jwt: action.payload },
|
||||
});
|
||||
case "SET_TYPES":
|
||||
return (state = {...state, filters: {...state.filters, types: action.payload}})
|
||||
return (state = {
|
||||
...state,
|
||||
filters: { ...state.filters, types: action.payload },
|
||||
});
|
||||
case "SET_TAGS":
|
||||
return (state = {...state, filters: {...state.filters, tags: action.payload}})
|
||||
return (state = {
|
||||
...state,
|
||||
filters: { ...state.filters, tags: action.payload },
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user