From 6d103fc406cce3c71157f4fc7ac496434b6b0f11 Mon Sep 17 00:00:00 2001 From: joshchen984 Date: Wed, 6 Dec 2023 13:44:11 -0500 Subject: [PATCH] Add success alert when adding / editing note --- client/src/Admin/AddDateNotesDialog.tsx | 8 ++++++++ client/src/Admin/EditDateNotesDialog.tsx | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/client/src/Admin/AddDateNotesDialog.tsx b/client/src/Admin/AddDateNotesDialog.tsx index f0cbbcfe..43c52c7c 100644 --- a/client/src/Admin/AddDateNotesDialog.tsx +++ b/client/src/Admin/AddDateNotesDialog.tsx @@ -14,6 +14,8 @@ import React, { useEffect, useState } from 'react'; import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import theme from '../assets/theme'; +import useAlert from '../util/hooks/useAlert'; +import AlertType from '../util/types/alert'; interface IAdminNotesRow { key: string; @@ -45,6 +47,7 @@ function AddDateNotesDialog({ open, setOpen, addDate, table }: AddDateProps) { const [coachNextSteps, setCoachNextSteps] = useState(''); const [error, setError] = useState(false); const [errorMessage, setErrorMessage] = useState(''); + const { setAlert } = useAlert(); useEffect(() => { if (date) { @@ -60,6 +63,10 @@ function AddDateNotesDialog({ open, setOpen, addDate, table }: AddDateProps) { }, [date, table]); const handleSubmit = () => { + if (!date) { + setErrorMessage('Please provide a date'); + setError(true); + } if (!date || error) { return; } @@ -77,6 +84,7 @@ function AddDateNotesDialog({ open, setOpen, addDate, table }: AddDateProps) { setCoachObservations(''); setCoachNextSteps(''); setOpen(false); + setAlert('Note added successfully!', AlertType.SUCCESS); }; const handleClose = () => { diff --git a/client/src/Admin/EditDateNotesDialog.tsx b/client/src/Admin/EditDateNotesDialog.tsx index 0f93d5a7..28367deb 100644 --- a/client/src/Admin/EditDateNotesDialog.tsx +++ b/client/src/Admin/EditDateNotesDialog.tsx @@ -11,6 +11,8 @@ import { } from '@mui/material'; import dayjs from 'dayjs'; import React, { useEffect, useState } from 'react'; +import useAlert from '../util/hooks/useAlert'; +import AlertType from '../util/types/alert'; interface IAdminNotesRow { key: string; @@ -47,6 +49,7 @@ function EditDateDialog({ const [studentNextSteps, setStudentNextSteps] = useState(''); const [coachObservations, setCoachObservations] = useState(''); const [coachNextSteps, setCoachNextSteps] = useState(''); + const { setAlert } = useAlert(); useEffect(() => { if (date) { @@ -78,6 +81,7 @@ function EditDateDialog({ setCoachObservations(''); setCoachNextSteps(''); setOpen(false); + setAlert('Note edited successfully!', AlertType.SUCCESS); }; return (