0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-25 01:02:47 +00:00

"Updated admin notification management: added error handling and styling, modified notification add and lookup functionality, and refactored server-side API routes and error handling."

This commit is contained in:
Víctor Losada Hernández
2024-09-14 23:58:47 +02:00
parent 9bf28f1433
commit ebc3b4ee66
7 changed files with 121 additions and 112 deletions

View File

@@ -24,20 +24,27 @@ const NotificationAdd = ()=>{
const stopAt = new Date(stopAtRef.current.value);
// Basic validation
if(!dismissKey || !title || !text || !startAt || !stopAt) {
setState((prevState)=>({
if (!dismissKey || !title || !text || isNaN(startAt.getTime()) || isNaN(stopAt.getTime())) {
setState((prevState) => ({
...prevState,
error : 'All fields are required!',
error: 'All fields are required',
}));
return;
}
if (startAt >= stopAt) {
setState((prevState) => ({
...prevState,
error: 'End date must be after the start date!',
}));
return;
}
const data = {
dismissKey,
title,
text,
startAt : startAt?.toISOString() ?? '',
stopAt : stopAt?.stopAt.toISOString() ?? '',
stopAt : stopAt?.toISOString() ?? '',
};
try {
@@ -56,10 +63,11 @@ const NotificationAdd = ()=>{
...update,
searching : false,
}));
} catch (err) {
} catch (error) {
console.log(error.response.body.message);
setState((prevState)=>({
...prevState,
error : `Error saving notification: ${err.message}`,
error : `Error saving notification: ${error.response.body.message}`,
searching : false,
}));
}
@@ -110,7 +118,6 @@ const NotificationAdd = ()=>{
<i className={`fas ${state.searching ? 'fa-spin fa-spinner' : 'fa-save'}`} />
Save Notification
</button>
{state.error && <div className='error'>{state.error}</div>}
</div>
);

View File

@@ -25,6 +25,7 @@
min-height : 7em;
max-height : 20em;
resize : vertical;
padding : 10px;
}
}