Projekt

Obecné

Profil

Stáhnout (988 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
import { AlertColor } from '@mui/material'
2
import { createSlice } from '@reduxjs/toolkit'
3

    
4
export interface NotificationState {
5
    message?: string
6
    severity: AlertColor
7
    autohideSecs?: number
8
}
9

    
10
const initialState = {
11
    message: undefined,
12
    severity: 'info',
13
    autohideSecs: undefined
14
}
15

    
16
const notificationSlice = createSlice({
17
    name: 'notification',
18
    initialState,
19
    reducers: {
20
        showNotification: (state, action) => ({
21
            ...state,
22
            message: action.payload.message,
23
            severity: action.payload.severity,
24
            autohideSecs: action.payload.autohideSecs,
25
        }),
26
        // consumes the message so it is not displayed after the page gets refreshed
27
        consumeNotification: (state) => ({
28
            ...initialState,
29
        }),
30
    },
31
})
32

    
33
const notificationReducer = notificationSlice.reducer
34
export const { showNotification, consumeNotification } =
35
    notificationSlice.actions
36
export default notificationReducer
(2-2/2)