2020-01-13 01:03:22 -06:00
|
|
|
|
import { createSlice } from '@reduxjs/toolkit';
|
|
|
|
|
|
|
|
|
|
import { ApiKeysState } from 'app/types';
|
2018-09-25 09:23:43 -05:00
|
|
|
|
|
2018-09-26 06:45:04 -05:00
|
|
|
|
export const initialApiKeysState: ApiKeysState = {
|
2021-12-16 05:46:09 -06:00
|
|
|
|
hasFetched: false,
|
|
|
|
|
includeExpired: false,
|
2018-09-26 06:45:04 -05:00
|
|
|
|
keys: [],
|
2021-12-16 05:46:09 -06:00
|
|
|
|
keysIncludingExpired: [],
|
2018-09-26 06:45:04 -05:00
|
|
|
|
searchQuery: '',
|
|
|
|
|
};
|
2018-09-25 09:23:43 -05:00
|
|
|
|
|
2020-01-13 01:03:22 -06:00
|
|
|
|
const apiKeysSlice = createSlice({
|
|
|
|
|
name: 'apiKeys',
|
|
|
|
|
initialState: initialApiKeysState,
|
|
|
|
|
reducers: {
|
|
|
|
|
apiKeysLoaded: (state, action): ApiKeysState => {
|
2021-12-16 05:46:09 -06:00
|
|
|
|
const { keys, keysIncludingExpired } = action.payload;
|
|
|
|
|
const includeExpired =
|
|
|
|
|
action.payload.keys.length === 0 && action.payload.keysIncludingExpired.length > 0
|
|
|
|
|
? true
|
|
|
|
|
: state.includeExpired;
|
|
|
|
|
return { ...state, hasFetched: true, keys, keysIncludingExpired, includeExpired };
|
2020-01-13 01:03:22 -06:00
|
|
|
|
},
|
|
|
|
|
setSearchQuery: (state, action): ApiKeysState => {
|
2018-09-26 06:45:04 -05:00
|
|
|
|
return { ...state, searchQuery: action.payload };
|
2020-01-13 01:03:22 -06:00
|
|
|
|
},
|
2021-12-16 05:46:09 -06:00
|
|
|
|
includeExpiredToggled: (state): ApiKeysState => {
|
|
|
|
|
return { ...state, includeExpired: !state.includeExpired };
|
|
|
|
|
},
|
|
|
|
|
isFetching: (state): ApiKeysState => {
|
|
|
|
|
return { ...state, hasFetched: false };
|
|
|
|
|
},
|
2020-01-13 01:03:22 -06:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-16 05:46:09 -06:00
|
|
|
|
export const { apiKeysLoaded, includeExpiredToggled, isFetching, setSearchQuery } = apiKeysSlice.actions;
|
2020-01-13 01:03:22 -06:00
|
|
|
|
|
|
|
|
|
export const apiKeysReducer = apiKeysSlice.reducer;
|
2018-09-25 09:23:43 -05:00
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
apiKeys: apiKeysReducer,
|
|
|
|
|
};
|