diff --git a/libs/shared/lib/insight-sharing/FormAlert.tsx b/libs/shared/lib/insight-sharing/FormAlert.tsx index e010d447486b2ddc4f9bd8fc8f4f33b304805011..4f4d2c6af236227bcb4864117b27da519025f2af 100644 --- a/libs/shared/lib/insight-sharing/FormAlert.tsx +++ b/libs/shared/lib/insight-sharing/FormAlert.tsx @@ -11,7 +11,7 @@ import { import { useAppDispatch, useSessionCache } from '@graphpolaris/shared/lib/data-access'; import { Button, Input, LoadingSpinner } from '../components'; import { wsUpdateInsight, wsCreateInsight, wsDeleteInsight } from '@graphpolaris/shared/lib/data-access/broker/wsInsightSharing'; -import { addError } from '@graphpolaris/shared/lib/data-access/store/configSlice'; +import { addError, addSuccess } from '@graphpolaris/shared/lib/data-access/store/configSlice'; import { SerializedEditorState } from 'lexical'; type Props = { @@ -80,10 +80,11 @@ export function FormAlert(props: Props) { setLoading(false); if (status === 'success') { dispatch(updateInsight(data)); + dispatch(addSuccess('Alert updated successfully')); console.log('Alert updated successfully'); } else { console.error('Failed to update alert:', data); - alert('Failed to update alert.'); + dispatch(addError('Failed to update alert.')); } }); } else { @@ -91,11 +92,12 @@ export function FormAlert(props: Props) { setLoading(false); if (status === 'success') { dispatch(addInsight(data)); + dispatch(addSuccess('Alert created successfully')); console.log('Alert created successfully'); if (props.setActive) props.setActive(data.id); } else { console.error('Failed to create alert:', data); - alert('Failed to create alert.'); + dispatch(addError('Failed to create alert.')); } }); } @@ -103,7 +105,7 @@ export function FormAlert(props: Props) { const handleDelete = async () => { if (!props.insight.id) { - alert('Cannot delete an alert without an ID.'); + dispatch(addError('Cannot delete an alert without an ID.')); return; } @@ -113,10 +115,11 @@ export function FormAlert(props: Props) { if (status === 'success') { dispatch(deleteInsight({ id: props.insight.id })); if (props.setActive) props.setActive(''); + dispatch(addSuccess('Alert deleted successfully')); console.log('Alert deleted successfully'); } else { console.error('Failed to delete alert:', data); - alert('Failed to delete alert.'); + dispatch(addError('Failed to delete alert')); } }); }; diff --git a/libs/shared/lib/insight-sharing/FormReport.tsx b/libs/shared/lib/insight-sharing/FormReport.tsx index 7597375748b34c231dcd56b115ca613bbaaa1ccb..e41546b2f5551551b62724a13846b031004640b8 100644 --- a/libs/shared/lib/insight-sharing/FormReport.tsx +++ b/libs/shared/lib/insight-sharing/FormReport.tsx @@ -11,7 +11,7 @@ import { import { useAppDispatch, useSessionCache } from '@graphpolaris/shared/lib/data-access'; import { SerializedEditorState } from 'lexical'; import { wsCreateInsight, wsDeleteInsight, wsUpdateInsight } from '@graphpolaris/shared/lib/data-access/broker/wsInsightSharing'; -import { addError } from '@graphpolaris/shared/lib/data-access/store/configSlice'; +import { addError, addSuccess } from '@graphpolaris/shared/lib/data-access/store/configSlice'; type Props = { insight: InsightResponse; @@ -91,10 +91,11 @@ export function FormReport(props: Props) { setLoading(false); if (status === 'success') { dispatch(updateInsight(data)); + dispatch(addSuccess('Report updated successfully')); console.log('Report updated successfully'); } else { console.error('Failed to update report:', data); - alert('Failed to update report.'); + dispatch(addError('Failed to update alert')); } }); } else { @@ -103,11 +104,12 @@ export function FormReport(props: Props) { setLoading(false); if (status === 'success') { dispatch(updateInsight(data)); + dispatch(addSuccess('Report created successfully')); console.log('Report created successfully'); if (props.setActive) props.setActive(data.id); } else { console.error('Failed to create report:', data); - alert('Failed to create report.'); + dispatch(addError('Failed to create alert')); } }); } @@ -115,7 +117,7 @@ export function FormReport(props: Props) { const handleDelete = async () => { if (!props.insight.id) { - alert('Cannot delete a report without an ID.'); + dispatch(addError('Cannot delete a report without an ID.')); return; } @@ -125,10 +127,11 @@ export function FormReport(props: Props) { if (status === 'success') { dispatch(deleteInsight({ id: props.insight.id })); props.setActive(''); + dispatch(addSuccess('Report deleted successfully')); console.log('Report deleted successfully'); } else { console.error('Failed to delete report:', data); - alert('Failed to delete report.'); + dispatch(addError('Failed to delete report')); } }); }; diff --git a/libs/shared/lib/insight-sharing/components/AddItem.tsx b/libs/shared/lib/insight-sharing/components/AddItem.tsx index fe8f3f173f6caaa956ed770dc776725661d4539e..b207b9ec6c890ed167495615fac412fc2ebfe35c 100644 --- a/libs/shared/lib/insight-sharing/components/AddItem.tsx +++ b/libs/shared/lib/insight-sharing/components/AddItem.tsx @@ -4,6 +4,7 @@ import { MonitorType as InsightType, MonitorType } from './Sidebar'; import { useAppDispatch, useSessionCache } from '../../data-access'; import { addInsight } from '../../data-access/store/insightSharingSlice'; import { wsCreateInsight } from '../../data-access/broker/wsInsightSharing'; +import { addError, addSuccess, } from '@graphpolaris/shared/lib/data-access/store/configSlice'; type Props = { setAdding: (val: false | MonitorType) => void; @@ -19,7 +20,7 @@ export function AddItem(props: Props) { const handleSave = async () => { if (!name.trim()) { - alert('Please enter a name.'); + dispatch(addError('Name is required')); return; } @@ -38,9 +39,10 @@ export function AddItem(props: Props) { dispatch(addInsight(data)); props.setActive(data.id); props.setAdding(false); + dispatch(addSuccess('Succesfully created ' + props.type)); } else { console.error('Failed to create insight:', data); - alert('Failed to create new ' + props.type); + dispatch(addError('Failed to create new ' + props.type)) } }); };