From dbbc6f6038299d246fc0d31b5554034638cad691 Mon Sep 17 00:00:00 2001 From: Wes <169498386+wes-mil@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:08:07 -0500 Subject: [PATCH] BED-5066: resolve TS errors Raise name error on duplicate SSO slug --- cmd/api/src/database/sso_providers.go | 2 ++ .../src/components/CreateUserForm/CreateUserForm.tsx | 11 +++++++---- .../src/components/UpdateUserForm/UpdateUserForm.tsx | 11 +++++++---- .../src/components/UpsertOIDCProviderForm.tsx | 8 ++++---- .../UpsertSAMLProviderForm/UpsertSAMLProviderForm.tsx | 8 ++++---- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/cmd/api/src/database/sso_providers.go b/cmd/api/src/database/sso_providers.go index c8ba65419..85826e107 100644 --- a/cmd/api/src/database/sso_providers.go +++ b/cmd/api/src/database/sso_providers.go @@ -65,6 +65,8 @@ func (s *BloodhoundDB) CreateSSOProvider(ctx context.Context, name string, authP if result.Error != nil { if strings.Contains(result.Error.Error(), "duplicate key value violates unique constraint \"sso_providers_name_key\"") { return fmt.Errorf("%w: %v", ErrDuplicateSSOProviderName, tx.Error) + } else if strings.Contains(result.Error.Error(), "duplicate key value violates unique constraint \"sso_providers_slug_key\"") { + return fmt.Errorf("%w: %v", ErrDuplicateSSOProviderName, tx.Error) } } diff --git a/packages/javascript/bh-shared-ui/src/components/CreateUserForm/CreateUserForm.tsx b/packages/javascript/bh-shared-ui/src/components/CreateUserForm/CreateUserForm.tsx index 25405fe15..036ba5e6a 100644 --- a/packages/javascript/bh-shared-ui/src/components/CreateUserForm/CreateUserForm.tsx +++ b/packages/javascript/bh-shared-ui/src/components/CreateUserForm/CreateUserForm.tsx @@ -75,10 +75,13 @@ const CreateUserForm: React.FC<{ if (error.response?.data?.errors[0]?.message.toLowerCase().includes('principal name')) { setError('principal', { type: 'custom', message: 'Principal name is already in use.' }); } else { - setError('generic', { type: 'custom', message: `A conflict has occured.` }); + setError('root.generic', { type: 'custom', message: `A conflict has occured.` }); } } else { - setError('generic', { type: 'custom', message: 'An unexpected error occurred. Please try again.' }); + setError('root.generic', { + type: 'custom', + message: 'An unexpected error occurred. Please try again.', + }); } } }, [authenticationMethod, setValue, error, setError]); @@ -349,9 +352,9 @@ const CreateUserForm: React.FC<{ )} /> - {!!errors.generic && ( + {!!errors.root?.generic && ( - {errors.generic.message} + {errors.root.generic.message} )} diff --git a/packages/javascript/bh-shared-ui/src/components/UpdateUserForm/UpdateUserForm.tsx b/packages/javascript/bh-shared-ui/src/components/UpdateUserForm/UpdateUserForm.tsx index ff00f2113..3c8c4c7a3 100644 --- a/packages/javascript/bh-shared-ui/src/components/UpdateUserForm/UpdateUserForm.tsx +++ b/packages/javascript/bh-shared-ui/src/components/UpdateUserForm/UpdateUserForm.tsx @@ -162,10 +162,13 @@ const UpdateUserFormInner: React.FC<{ if (error.response?.data?.errors[0]?.message.toLowerCase().includes('principal name')) { setError('principal', { type: 'custom', message: 'Principal name is already in use.' }); } else { - setError('generic', { type: 'custom', message: `A conflict has occured.` }); + setError('root.generic', { type: 'custom', message: `A conflict has occured.` }); } } else { - setError('generic', { type: 'custom', message: 'An unexpected error occurred. Please try again.' }); + setError('root.generic', { + type: 'custom', + message: 'An unexpected error occurred. Please try again.', + }); } } }, [authenticationMethod, setValue, error, setError]); @@ -372,9 +375,9 @@ const UpdateUserFormInner: React.FC<{ )} /> - {!!errors.generic && ( + {!!errors.root?.generic && ( - {errors.generic.message} + {errors.root.generic.message} )} diff --git a/packages/javascript/bh-shared-ui/src/components/UpsertOIDCProviderForm.tsx b/packages/javascript/bh-shared-ui/src/components/UpsertOIDCProviderForm.tsx index 27c80f4b5..6048c9113 100644 --- a/packages/javascript/bh-shared-ui/src/components/UpsertOIDCProviderForm.tsx +++ b/packages/javascript/bh-shared-ui/src/components/UpsertOIDCProviderForm.tsx @@ -46,13 +46,13 @@ const UpsertOIDCProviderForm: FC<{ if (error.response?.data?.errors[0]?.message.toLowerCase().includes('sso provider name')) { setError('name', { type: 'custom', message: 'SSO Provider Name is already in use.' }); } else { - setError('generic', { + setError('root.generic', { type: 'custom', message: 'A conflict has occured.', }); } } else { - setError('generic', { + setError('root.generic', { type: 'custom', message: `Unable to ${oldSSOProvider ? 'update' : 'create new'} OIDC Provider configuration. Please try again.`, }); @@ -134,9 +134,9 @@ const UpsertOIDCProviderForm: FC<{ )} /> - {!!errors.generic && ( + {!!errors.root?.generic && ( - {errors.generic.message} + {errors.root.generic.message} )} diff --git a/packages/javascript/bh-shared-ui/src/components/UpsertSAMLProviderForm/UpsertSAMLProviderForm.tsx b/packages/javascript/bh-shared-ui/src/components/UpsertSAMLProviderForm/UpsertSAMLProviderForm.tsx index 01889cfd6..5fb44001e 100644 --- a/packages/javascript/bh-shared-ui/src/components/UpsertSAMLProviderForm/UpsertSAMLProviderForm.tsx +++ b/packages/javascript/bh-shared-ui/src/components/UpsertSAMLProviderForm/UpsertSAMLProviderForm.tsx @@ -57,13 +57,13 @@ const UpsertSAMLProviderForm: FC<{ if (error.response?.data?.errors[0]?.message.toLowerCase().includes('sso provider name')) { setError('name', { type: 'custom', message: 'SSO Provider Name is already in use.' }); } else { - setError('generic', { + setError('root.generic', { type: 'custom', message: `A conflict has occured.`, }); } } else { - setError('generic', { + setError('root.generic', { type: 'custom', message: `Unable to ${oldSSOProvider ? 'update' : 'create new'} SAML Provider configuration. Please try again.`, }); @@ -147,9 +147,9 @@ const UpsertSAMLProviderForm: FC<{ : 'Upload the Metadata file provided by your SAML Provider'} - {!!errors.generic && ( + {!!errors.root?.generic && ( - {errors.generic.message} + {errors.root.generic.message} )}