diff options
author | 2021-09-02 22:28:11 +0200 | |
---|---|---|
committer | 2021-09-02 23:54:56 +0200 | |
commit | f08f6ca0a9d337efff280d4d1669a41b5d9c31c2 (patch) | |
tree | 7dee778ba742deb5f499f2aa08a1ba040606d633 /helpers/submitForm.js | |
parent | 9f74c550927671f4ded301d0cf3e9d592716375c (diff) | |
download | my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.gz my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.bz2 my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.zip |
finish translations, force maximize
Diffstat (limited to 'helpers/submitForm.js')
-rw-r--r-- | helpers/submitForm.js | 26 |
1 files changed, 22 insertions, 4 deletions
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') } } |