diff --git a/libs/shared/lib/insight-sharing/alerting/AlertingForm.tsx b/libs/shared/lib/insight-sharing/alerting/AlertingForm.tsx index 0b53289b63a901fcdc9cd2de4fce294e57540cb1..2ec1ad5b5d199a66f1b26dd18d6063ed3afcb622 100644 --- a/libs/shared/lib/insight-sharing/alerting/AlertingForm.tsx +++ b/libs/shared/lib/insight-sharing/alerting/AlertingForm.tsx @@ -7,6 +7,7 @@ import { Button, Input, LoadingSpinner } from '../../components'; import { EditorState } from 'lexical'; import { MonitorType } from '../components/Sidebar'; import { wsUpdateInsight, wsCreateInsight, wsDeleteInsight } from '../../data-access/broker/wsInsightSharing'; +import { addError } from '../../data-access/store/configSlice'; type Props = { insight: InsightResponse; @@ -45,30 +46,22 @@ export function AlertingForm(props: Props) { const handleSave = async () => { if (!name || name.trim() === '') { - alert('Please enter a name for the alert.'); - return; - } - if (!description || description.trim() === '') { - alert('Please enter a description for the alert.'); - return; - } - if (!editorState) { - alert('Please enter content in the text editor before saving.'); + dispatch(addError('Name is required')); return; } - const alertData : InsightRequest = { + const alertData: InsightRequest = { name, description, recipients, template: JSON.stringify(editorState), saveStateId: session.currentSaveState || '', type: 'alert' as const, - frequency: '' + frequency: '', }; setLoading(true); - + if (props.insight.id) { wsUpdateInsight(props.insight.id, alertData, (data: any, status: string) => { setLoading(false); @@ -124,20 +117,8 @@ export function AlertingForm(props: Props) { return ( <div> <span className="text-lg text-secondary-600 font-bold mb-4">Alert ID: {props.insight.id}</span> - <Input - label="Name" - type="text" - value={name} - onChange={setName} - className="mb-4" - /> - <Input - label="Description" - type="text" - value={description} - onChange={setDescription} - className="mb-4" - /> + <Input label="Name" type="text" value={name} onChange={setName} className="mb-4" /> + <Input label="Description" type="text" value={description} onChange={setDescription} className="mb-4" /> <Accordion defaultOpenAll={true} className="border-t divide-y"> <AccordionItem className="pt-2 pb-4"> <AccordionHead showArrow={false}> @@ -152,8 +133,8 @@ export function AlertingForm(props: Props) { setRecipientInput(String(value)); const recipientList = String(value) .split(/[, ]/) - .map(r => r.trim()) - .filter(r => r.length > 0); + .map((r) => r.trim()) + .filter((r) => r.length > 0); setRecipients(recipientList); }} placeholder="Enter recipient(s)" @@ -183,4 +164,4 @@ export function AlertingForm(props: Props) { </div> </div> ); -} \ No newline at end of file +} diff --git a/libs/shared/lib/insight-sharing/reporting/ReportingForm.tsx b/libs/shared/lib/insight-sharing/reporting/ReportingForm.tsx index 0bff6cbbb0ce52a7d64e8d4cada7b48ca0437b63..fd827f26fec6b7853e1c31dea92e1520a5ae90ad 100644 --- a/libs/shared/lib/insight-sharing/reporting/ReportingForm.tsx +++ b/libs/shared/lib/insight-sharing/reporting/ReportingForm.tsx @@ -7,6 +7,7 @@ import { useAppDispatch, useSessionCache } from '../../data-access'; import { MonitorType } from '../components/Sidebar'; import { EditorState } from 'lexical'; import { wsCreateInsight, wsDeleteInsight, wsUpdateInsight } from '../../data-access/broker/wsInsightSharing'; +import { addError } from '../../data-access/store/configSlice'; type Props = { insight: InsightResponse; @@ -59,15 +60,7 @@ export function ReportingForm(props: Props) { const handleSave = async () => { if (!name || name.trim() === '') { - alert('Please enter a name for the report.'); - return; - } - if (!description || description.trim() === '') { - alert('Please enter a description for the report.'); - return; - } - if (!editorState) { - alert('Please enter content in the text editor before saving.'); + dispatch(addError('Please enter a name for the report.')); return; } @@ -77,7 +70,7 @@ export function ReportingForm(props: Props) { recipients, frequency, template: JSON.stringify(editorState), - saveStateId: session.currentSaveState || "", + saveStateId: session.currentSaveState || '', type: 'report' as const, }; @@ -107,7 +100,7 @@ export function ReportingForm(props: Props) { alert('Failed to create report.'); } }); - } + } }; const handleDelete = async () => { @@ -136,20 +129,8 @@ export function ReportingForm(props: Props) { ) : ( <div> <span className="text-lg text-secondary-600 font-bold mb-4">Report ID: {props.insight.id}</span> - <Input - label="Name" - type="text" - value={name} - onChange={handleSetName} - className="mb-4" - /> - <Input - label="Description" - type="text" - value={description} - onChange={handleSetDescription} - className="mb-4" - /> + <Input label="Name" type="text" value={name} onChange={handleSetName} className="mb-4" /> + <Input label="Description" type="text" value={description} onChange={handleSetDescription} className="mb-4" /> <Accordion defaultOpenAll={true} className="border-t divide-y"> <AccordionItem className="pt-2 pb-4"> <AccordionHead showArrow={false}> @@ -164,8 +145,8 @@ export function ReportingForm(props: Props) { setRecipientInput(String(value)); const recipientList = String(value) .split(/[, ]/) - .map(r => r.trim()) - .filter(r => r.length > 0); + .map((r) => r.trim()) + .filter((r) => r.length > 0); setRecipients(recipientList); }} placeholder="Enter recipient(s)" @@ -210,4 +191,4 @@ export function ReportingForm(props: Props) { </div> </div> ); -} \ No newline at end of file +}