From 82ed5cbf9a800ba5dc1905a7a58118d84e2d97b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cspicecat=E2=80=9D?= Date: Thu, 18 Aug 2022 10:50:18 -0400 Subject: [PATCH] fix invalid mail form --- .../FormControllers/SendMailController.js | 14 +++++++++++--- server/routes/mail/Send.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/controllers/FormControllers/SendMailController.js b/client/src/controllers/FormControllers/SendMailController.js index 018dbd0..54c076f 100644 --- a/client/src/controllers/FormControllers/SendMailController.js +++ b/client/src/controllers/FormControllers/SendMailController.js @@ -23,13 +23,21 @@ export default function SendMailController() { }, []); const sendMail = async (fields) => { - const { error } = await postMail(fields); - if (!error) window.location.reload(false); + const { error, status } = await postMail(fields); + console.log(error, status, 12313); + if (error) { + if (status === 500) + return { receiver: 'Error' }; + else if (status === 404) + return { receiver: 'User not found' }; + } else { + window.location.reload(false); + } }; return Form({ fields: composeMailFields, - onSubmit: sendMail, + validate: sendMail, validationSchema: mailSchema, }); } diff --git a/server/routes/mail/Send.js b/server/routes/mail/Send.js index da52ddd..e2b4a63 100644 --- a/server/routes/mail/Send.js +++ b/server/routes/mail/Send.js @@ -12,7 +12,7 @@ async function Send(req, res) { return res.status(400).send(config.errorIncomplete); } - const cachedReciever = await User.findOne({ username: reciever }); + const cachedReciever = await User.findOne({ username: receiver }); if (!cachedReciever) { return res.status(404).send(config.errorNotFound);