From d6878f4f142ce4c9f8ef51fd4debd814beaf6ab6 Mon Sep 17 00:00:00 2001 From: Samed <sbalcioglu@graphpolaris.com> Date: Mon, 9 Dec 2024 13:51:15 +0100 Subject: [PATCH] chore: added correct alerts & confirmation msg --- libs/shared/lib/insight-sharing/FormAlert.tsx | 13 ++++++++----- libs/shared/lib/insight-sharing/FormReport.tsx | 13 ++++++++----- .../lib/insight-sharing/components/AddItem.tsx | 6 ++++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libs/shared/lib/insight-sharing/FormAlert.tsx b/libs/shared/lib/insight-sharing/FormAlert.tsx index e010d4474..4f4d2c6af 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 759737574..e41546b2f 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 fe8f3f173..b207b9ec6 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)) } }); }; -- GitLab