From 265485acb1abe785bce0e56e593a86b5e3afc573 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 29 Mar 2020 13:39:17 +0530 Subject: [PATCH] Auto close snackbar. --- components/timetable/AddEntry.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/components/timetable/AddEntry.js b/components/timetable/AddEntry.js index 6be6367..86d1871 100644 --- a/components/timetable/AddEntry.js +++ b/components/timetable/AddEntry.js @@ -47,19 +47,22 @@ function AddEntry({addTimetableEntry, days, day, subjects, navigation }) { } function submit() { - if (subject.id === null) { - setSnackbar({ visible: true, message: "Missing subject." }); - return; - } else if (start === null) { - setSnackbar({ visible: true, message: "Missing start time." }); - return; - } else if (end === null) { - setSnackbar({ visible: true, message: "Missing end time." }); - return; - } else if (count === 0) { - setSnackbar({ visible: true, message: "Missing count." }); + let message = ""; + if (subject.id === null) + message = "Missing Subject"; + else if (start === null) + message = "Missing start time."; + else if (end === null) + message = "Missing end time."; + else if (count === 0) + message = "Missing count."; + + if (message !== "") { + setSnackbar({visible: true, message: message}); + setTimeout(() => setSnackbar({ visible: false, message: null }), 2000); return; } + addTimetableEntry(day, { sub_id: subject.id, count,