aboutsummaryrefslogtreecommitdiffstats
path: root/helpers/submitForm.js
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/submitForm.js')
-rw-r--r--helpers/submitForm.js26
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')
}
}