summaryrefslogtreecommitdiff
path: root/client/src/slices/snackbarSlice.ts
blob: 82532ec9689439e03b351169dc1b897d093f1210 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { createSlice } from '@reduxjs/toolkit';
import type { AlertColor } from '@mui/material/Alert/Alert';
import type { RootState } from '../store';

export interface SnackbarState {
  open: boolean;
  message: string;
  severity?: AlertColor;
}

const initialState: SnackbarState = {
  open: false,
  message: '',
};

export const snackbarSlice = createSlice({
  name: 'snackbar',
  initialState,
  reducers: {
    showSnackbar: (state, action) => {
      state.open = true;
      state.message = action.payload.message;
      state.severity = action.payload.severity;
    },
    hideSnackbar: (state) => {
      state.open = false;
    },
  },
});

export const { showSnackbar, hideSnackbar } = snackbarSlice.actions;
export const selectSnackbarState = (state: RootState) => state.snackbar;
export default snackbarSlice.reducer;