fix invalid mail form

This commit is contained in:
“spicecat” 2022-08-18 10:50:18 -04:00
commit 82ed5cbf9a
2 changed files with 12 additions and 4 deletions

View file

@ -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,
});
}

View file

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