Show error when trying to create user with a duplicate email address

This commit is contained in:
Andrew Kingston 2021-02-23 10:33:26 +00:00
parent f54734c3bf
commit 3430048c9b
1 changed files with 19 additions and 1 deletions

View File

@ -34,11 +34,26 @@
} }
const saveRow = async () => { const saveRow = async () => {
errors = []
// Do some basic front end validation first
if (!row.email) {
errors = [...errors, { message: "Email is required" }]
}
if (!row.password) {
errors = [...errors, { message: "Password is required" }]
}
if (!row.roleId) {
errors = [...errors, { message: "Role is required" }]
}
if (errors.length) {
return false
}
const rowResponse = await backendApi.saveRow( const rowResponse = await backendApi.saveRow(
{ ...row, tableId: table._id }, { ...row, tableId: table._id },
table._id table._id
) )
if (rowResponse.errors) { if (rowResponse.errors) {
if (Array.isArray(rowResponse.errors)) { if (Array.isArray(rowResponse.errors)) {
errors = rowResponse.errors.map(error => ({ message: error })) errors = rowResponse.errors.map(error => ({ message: error }))
@ -48,6 +63,9 @@
.flat() .flat()
} }
return false return false
} else if (rowResponse.status === 400 && rowResponse.message) {
errors = [{ message: rowResponse.message }]
return false
} }
notifier.success("User saved successfully.") notifier.success("User saved successfully.")