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