bruno/renderer/providers/Auth/reducer.js
2022-03-07 20:02:39 +05:30

43 lines
1004 B
JavaScript

import produce from 'immer';
const reducer = (state, action) => {
switch (action.type) {
case 'WHOAMI_SUCCESS': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = action.user;
draft.lastStateTransition = 'WHOAMI_SUCCESS';
});
}
case 'WHOAMI_ERROR': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = null;
draft.lastStateTransition = 'WHOAMI_ERROR';
});
}
case 'LOGIN_SUCCESS': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = action.user;
draft.lastStateTransition = 'LOGIN_SUCCESS';
});
}
case 'LOGOUT_SUCCESS': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = null;
draft.lastStateTransition = 'LOGOUT_SUCCESS';
});
}
default: {
return state;
}
}
};
export default reducer;