From f08f6ca0a9d337efff280d4d1669a41b5d9c31c2 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Thu, 2 Sep 2021 22:28:11 +0200 Subject: finish translations, force maximize --- helpers/submitForm.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'helpers/submitForm.js') diff --git a/helpers/submitForm.js b/helpers/submitForm.js index 77b283d..631c174 100644 --- a/helpers/submitForm.js +++ b/helpers/submitForm.js @@ -1,11 +1,31 @@ -import fetchJson from 'lib/fetchJson' +import fetchJson from 'helpers/fetchJson' const submitForm = async (e, url, mutateUser, setErrorMsg) => { e.preventDefault() + const isRegister = url.includes('register') + if ( + isRegister && e.currentTarget.password_confirm + && e.currentTarget.password_confirm.value + !== e.currentTarget.password.value + ) { + setErrorMsg('passwords_not_match') + return + } else { + setErrorMsg() + } + const body = { email: e.currentTarget.email.value, password: e.currentTarget.password.value, + ...(e.currentTarget.language + ? {language: e.currentTarget.language.value} + : {} + ), + ...(e.currentTarget.theme + ? {theme: e.currentTarget.theme.value} + : {} + ), } try { @@ -17,9 +37,7 @@ const submitForm = async (e, url, mutateUser, setErrorMsg) => { }) ) } catch (err) { - url.includes('login') - ? setErrorMsg('Could not log in') - : setErrorMsg('Could not register user') + setErrorMsg(isRegister ? 'register_error' : 'login_error') } } -- cgit v1.2.3