2021-02-04 19:15:23 +01:00
|
|
|
import { createSlice } from '@reduxjs/toolkit';
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { ALERT_TYPES } from '../../../../shared/constants/alerts';
|
|
|
|
import { ALERT_STATE } from './enums';
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const name = ALERT_TYPES.invalidCustomNetwork;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
state: ALERT_STATE.CLOSED,
|
|
|
|
networkName: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
// Slice (reducer plus auto-generated actions and action creators)
|
|
|
|
|
|
|
|
const slice = createSlice({
|
|
|
|
name,
|
|
|
|
initialState,
|
|
|
|
reducers: {
|
|
|
|
openAlert: (state, action) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
state.state = ALERT_STATE.OPEN;
|
|
|
|
state.networkName = action.payload;
|
2020-10-06 19:57:02 +02:00
|
|
|
},
|
|
|
|
dismissAlert: (state) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
state.state = ALERT_STATE.CLOSED;
|
|
|
|
state.networkName = '';
|
2020-10-06 19:57:02 +02:00
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { actions, reducer } = slice;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default reducer;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
// Selectors
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export const getAlertState = (state) => state[name].state;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export const getNetworkName = (state) => state[name].networkName;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export const alertIsOpen = (state) => state[name].state !== ALERT_STATE.CLOSED;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
// Actions / action-creators
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { openAlert, dismissAlert } = actions;
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export { openAlert, dismissAlert };
|