const initialState = { showDishList: false, loggedIn: false, jwt: "", username: "", userId: "", userEmail: "", dialogs: { logIn: false, register: false, newRestaurant: true, contact: false, pricing: false, regulamin: false, registerCircularProgress: false, registerForm: true, registerResult: "", loginResult: "", }, }; 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 "DIALOG_LOGIN_VISIBLE": return (state = { ...state, dialogs: { ...state.dialogs, logIn: true } }); case "SET_LOGGEDIN": return (state = { ...state, loggedIn: true, username: action.payload.username, jwt: action.payload.jwt, userEmail: action.payload.email, userId: action.payload.id, }); case "SET_LOGGEDOUT": return (state = { ...state, loggedIn: false, username: "", jwt: "", userEmail: "", userId: "", }); case "DIALOG_LOGIN_HIDDEN": return (state = { ...state, dialogs: { ...state.dialogs, logIn: false }, }); case "DIALOG_REGISTER_VISIBLE": return (state = { ...state, dialogs: { ...state.dialogs, register: true }, }); case "DIALOG_REGISTER_HIDDEN": return (state = { ...state, dialogs: { ...state.dialogs, register: false }, }); case "DIALOG_REGULAMIN_VISIBLE": return (state = { ...state, dialogs: { ...state.dialogs, regulamin: true }, }); case "DIALOG_REGULAMIN_HIDDEN": return (state = { ...state, dialogs: { ...state.dialogs, regulamin: false }, }); case "DIALOG_REGISTER_CIRCLE_SHOW": return (state = { ...state, dialogs: { ...state.dialogs, registerCircularProgress: true }, }); case "DIALOG_REGISTER_CIRCLE_HIDE": return (state = { ...state, dialogs: { ...state.dialogs, registerCircularProgress: false }, }); case "DIALOG_REGISTER_FORM_HIDE": return (state = { ...state, dialogs: { ...state.dialogs, registerForm: false }, }); case "DIALOG_REGISTER_SET_RESULT": return (state = { ...state, dialogs: { ...state.dialogs, registerResult: action.payload }, }); case "DIALOG_LOGIN_SET_RESULT": return (state = { ...state, dialogs: { ...state.dialogs, loginResult: action.payload }, }); default: return state; } }; export default data;