mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
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; |