From cda0506e120a2c2e1b26bca9f5e5dafbe26a8350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Yoshida?= Date: Wed, 13 Dec 2023 22:22:15 -0300 Subject: [PATCH] =?UTF-8?q?[ADD]:=20per=C3=ADodo=20de=20matr=C3=ADcula=20a?= =?UTF-8?q?tual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/Home/index.js | 2 ++ frontend/src/pages/RegistrationPeriod/index.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/Home/index.js b/frontend/src/pages/Home/index.js index 64b7d1c7..9b3e9416 100644 --- a/frontend/src/pages/Home/index.js +++ b/frontend/src/pages/Home/index.js @@ -85,6 +85,8 @@ const Home = () => { Período de Matrícula Atual:{" "} {`${new Date(currentRegistrationPeriod.start).toLocaleDateString()} às ${new Date( + currentRegistrationPeriod.start + ).toLocaleTimeString()} - ${new Date(currentRegistrationPeriod.end).toLocaleDateString()} às ${new Date( currentRegistrationPeriod.end ).toLocaleTimeString()}`} diff --git a/frontend/src/pages/RegistrationPeriod/index.js b/frontend/src/pages/RegistrationPeriod/index.js index 0a98d911..fc0ac7c3 100644 --- a/frontend/src/pages/RegistrationPeriod/index.js +++ b/frontend/src/pages/RegistrationPeriod/index.js @@ -60,7 +60,19 @@ const RegistrationPeriod = () => { }), endTime: yup .string() - .required("A hora de término é obrigatória"), + .required("A hora de término é obrigatória") + .test('isAfterStart', 'A hora de término deve ser posterior à hora de início', function (endTime) { + const { startDate, startTime, endDate } = this.parent; + + if (endDate === startDate) { + const startDateTime = new Date(`${startDate}T${startTime}`); + const endDateTime = new Date(`${endDate}T${endTime}`); + + return endDateTime > startDateTime; + } + + return true; + }), }), onSubmit: async (values) => { console.log(values);