forked from extern/bruno
43 lines
1004 B
JavaScript
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;
|