Show error when trying to create user with a duplicate email address
This commit is contained in:
parent
aaa40f4638
commit
009bf37556
|
@ -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.")
|
||||||
|
|
Loading…
Reference in New Issue