From 009bf3755692af0085149b126e3f857b942844e7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 Feb 2021 10:33:26 +0000 Subject: [PATCH] Show error when trying to create user with a duplicate email address --- .../DataTable/modals/CreateEditUser.svelte | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte index 5753b7d5bb..6467b8e953 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte @@ -34,11 +34,26 @@ } 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( { ...row, tableId: table._id }, table._id ) - if (rowResponse.errors) { if (Array.isArray(rowResponse.errors)) { errors = rowResponse.errors.map(error => ({ message: error })) @@ -48,6 +63,9 @@ .flat() } return false + } else if (rowResponse.status === 400 && rowResponse.message) { + errors = [{ message: rowResponse.message }] + return false } notifier.success("User saved successfully.")