summaryrefslogtreecommitdiff
path: root/client/src/slices/snackbarSlice.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/slices/snackbarSlice.ts')
-rw-r--r--client/src/slices/snackbarSlice.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/client/src/slices/snackbarSlice.ts b/client/src/slices/snackbarSlice.ts
new file mode 100644
index 0000000..eca9575
--- /dev/null
+++ b/client/src/slices/snackbarSlice.ts
@@ -0,0 +1,32 @@
+import { createSlice } from '@reduxjs/toolkit';
+import type { RootState } from '../store';
+
+export interface SnackbarState {
+ open: boolean;
+ message: string;
+ severity?: 'success' | 'error';
+}
+
+const initialState: SnackbarState = {
+ open: false,
+ message: '',
+};
+
+export const snackbarSlice = createSlice({
+ name: 'snackbar',
+ initialState,
+ reducers: {
+ open(state, action) {
+ state.open = true;
+ state.message = action.payload.message;
+ state.severity = action.payload.severity;
+ },
+ close(state) {
+ state.open = false;
+ },
+ },
+});
+
+export const { open, close } = snackbarSlice.actions;
+export const selectSnackbarState = (state: RootState) => state.snackbar;
+export default snackbarSlice.reducer;