This commit is contained in:
chamikaJ
2025-04-17 18:28:54 +05:30
parent f583291d8a
commit 8825b0410a
2837 changed files with 241385 additions and 127578 deletions

View File

@@ -0,0 +1,30 @@
// src/hooks/useAlert.ts
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { alertService } from '@/services/alerts/alertService';
import { showAlert } from '@/services/alerts/alertSlice';
import { AlertType } from '@/types/alert.types';
export const useAlert = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
const show = (type: AlertType, title: string, message: string, duration?: number) => {
// Update Redux state
dispatch(showAlert({ type, title, message, duration }));
// Show alert via service
alertService[type](title, message, duration);
};
return {
success: (title: string, message: string, duration?: number) =>
show('success', title, message, duration),
error: (title: string, message: string, duration?: number) =>
show('error', title, message, duration),
info: (title: string, message: string, duration?: number) =>
show('info', title, message, duration),
warning: (title: string, message: string, duration?: number) =>
show('warning', title, message, duration),
clearAll: alertService.clearAll,
};
};