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);