Files
worklenz/worklenz-frontend/src/services/alerts/alertSlice.ts
chamikaJ 8825b0410a init
2025-04-17 18:28:54 +05:30

44 lines
1.1 KiB
TypeScript

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;