init
This commit is contained in:
43
worklenz-frontend/src/services/alerts/alertSlice.ts
Normal file
43
worklenz-frontend/src/services/alerts/alertSlice.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { AlertConfig, AlertState, AlertType } from '@/types/alert.types';
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { notification } from 'antd';
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
const initialState: AlertState = {
|
||||
activeAlerts: new Set(),
|
||||
config: {
|
||||
position: 'topRight',
|
||||
duration: 4.5,
|
||||
maxCount: 5,
|
||||
},
|
||||
};
|
||||
|
||||
const alertSlice = createSlice({
|
||||
name: 'alert',
|
||||
initialState,
|
||||
reducers: {
|
||||
showAlert: (
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
type: AlertType;
|
||||
title: string;
|
||||
message: string;
|
||||
duration?: number;
|
||||
}>
|
||||
) => {
|
||||
if (!state.activeAlerts.has(action.payload.message)) {
|
||||
state.activeAlerts.add(action.payload.message);
|
||||
}
|
||||
},
|
||||
hideAlert: (state, action: PayloadAction<string>) => {
|
||||
state.activeAlerts.delete(action.payload);
|
||||
},
|
||||
updateAlertConfig: (state, action: PayloadAction<Partial<AlertConfig>>) => {
|
||||
state.config = { ...state.config, ...action.payload };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { showAlert, hideAlert, updateAlertConfig } = alertSlice.actions;
|
||||
|
||||
export default alertSlice.reducer;
|
||||
Reference in New Issue
Block a user