|
@@ -1,14 +1,17 @@
|
|
|
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
|
|
|
import { resetAllDevices } from '../../API/exam/deviceActions';
|
|
|
+import emitter from '../../utils/eventEmitter';
|
|
|
|
|
|
interface DeviceState {
|
|
|
status: 'idle' | 'loading' | 'succeeded' | 'failed';
|
|
|
error: string | null;
|
|
|
+ deviceError: string | null;
|
|
|
}
|
|
|
|
|
|
const initialState: DeviceState = {
|
|
|
status: 'idle',
|
|
|
error: null,
|
|
|
+ deviceError: null,
|
|
|
};
|
|
|
|
|
|
export const resetDevices = createAsyncThunk(
|
|
@@ -21,7 +24,11 @@ export const resetDevices = createAsyncThunk(
|
|
|
const deviceSlice = createSlice({
|
|
|
name: 'device',
|
|
|
initialState,
|
|
|
- reducers: {},
|
|
|
+ reducers: {
|
|
|
+ setDeviceError: (state, action) => {
|
|
|
+ state.deviceError = action.payload;
|
|
|
+ },
|
|
|
+ },
|
|
|
extraReducers: (builder) => {
|
|
|
builder
|
|
|
.addCase(resetDevices.pending, (state) => {
|
|
@@ -37,4 +44,11 @@ const deviceSlice = createSlice({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+emitter.on('DEVICE_ERROR', (error) => {
|
|
|
+ deviceSlice.caseReducers.setDeviceError(deviceSlice.getInitialState(), {
|
|
|
+ type: 'device/setDeviceError',
|
|
|
+ payload: error,
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
export default deviceSlice.reducer;
|