From d3d21feced38b36a3b370d44ebf94cf40e928178 Mon Sep 17 00:00:00 2001
From: alihadi-mazeh <113048174+alihadi-mazeh@users.noreply.github.com>
Date: Mon, 23 Jan 2023 09:55:36 -0500
Subject: [PATCH] Added duplicate email error to Admin User Create (#4618)

* Added a toast error to account for duplicate emails when creating a user from the admin panel

* eslint fixes
---
 .../mutations/admin/manage_users/useAdminCreateUser.jsx   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/app/javascript/hooks/mutations/admin/manage_users/useAdminCreateUser.jsx b/app/javascript/hooks/mutations/admin/manage_users/useAdminCreateUser.jsx
index 9e19ddb0..f12c541c 100644
--- a/app/javascript/hooks/mutations/admin/manage_users/useAdminCreateUser.jsx
+++ b/app/javascript/hooks/mutations/admin/manage_users/useAdminCreateUser.jsx
@@ -14,8 +14,12 @@ export default function useAdminCreateUser({ onSettled }) {
         queryClient.invalidateQueries('getAdminUsers');
         toast.success(t('toast.success.user.user_created'));
       },
-      onError: () => {
-        toast.error(t('toast.error.problem_completing_action'));
+      onError: (err) => {
+        if (err.response.data.errors === 'EmailAlreadyExists') {
+          toast.error(t('toast.error.users.email_exists'));
+        } else {
+          toast.error(t('toast.error.problem_completing_action'));
+        }
       },
       onSettled,
     },
-- 
GitLab