2021-03-23 19:15:47 -07:00
|
|
|
import {
|
|
|
|
FETCH_TOKENS_SUCCESS,
|
|
|
|
REVOKE_TOKEN_SUCCESS,
|
2021-08-21 17:37:28 -07:00
|
|
|
} from '../actions/security';
|
2021-03-23 19:15:47 -07:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
|
|
|
tokens: ImmutableList(),
|
|
|
|
});
|
|
|
|
|
2021-08-03 12:29:36 -07:00
|
|
|
const deleteToken = (state, tokenId) => {
|
|
|
|
return state.update('tokens', tokens => {
|
|
|
|
return tokens.filterNot(token => token.get('id') === tokenId);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-23 19:15:47 -07:00
|
|
|
export default function security(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case FETCH_TOKENS_SUCCESS:
|
|
|
|
return state.set('tokens', fromJS(action.tokens));
|
|
|
|
case REVOKE_TOKEN_SUCCESS:
|
2021-08-03 12:29:36 -07:00
|
|
|
return deleteToken(state, action.id);
|
2021-03-23 19:15:47 -07:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|