From 4b381f1db32a8c071e2fea1eb1f2dc4969690d36 Mon Sep 17 00:00:00 2001 From: Vincent BONMARCHAND Date: Wed, 16 Oct 2024 16:19:08 +0200 Subject: [PATCH] fix(kms): add clear notifications before trigger new notif ref: MANAGER-15377 Signed-off-by: Vincent BONMARCHAND --- .../modals/ServiceKeyDeactivateModal.component.tsx | 3 ++- .../serviceKey/modals/ServiceKeyEditNameModal.component.tsx | 3 ++- .../src/data/hooks/useCreateOkmsCredential.ts | 4 +++- .../src/data/hooks/useCreateOkmsServiceKey.ts | 4 +++- .../src/data/hooks/useDeleteOkmsCredential.ts | 5 +++-- .../src/data/hooks/useDeleteOkmsServiceKey.ts | 4 +++- .../src/data/hooks/useUpdateOkmsServiceKey.ts | 3 ++- .../src/hooks/serviceKey/useServiceKeyActionsList.tsx | 3 ++- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyDeactivateModal.component.tsx b/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyDeactivateModal.component.tsx index 5f82a23d1bc9..72326d854947 100644 --- a/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyDeactivateModal.component.tsx +++ b/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyDeactivateModal.component.tsx @@ -38,7 +38,7 @@ export const ServiceKeyDeactivateModal = ({ const [deactivationReason, setDeactivationReason] = useState< OkmsServiceKeyDeactivationReason >(); - const { addSuccess } = useNotifications(); + const { addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/serviceKeys'); const { t: tCommon } = useTranslation('key-management-service/common'); @@ -50,6 +50,7 @@ export const ServiceKeyDeactivateModal = ({ okmsId, keyId, onSuccess: () => { + clearNotifications(); addSuccess( t('key_management_service_service-keys_deactivation_success'), true, diff --git a/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyEditNameModal.component.tsx b/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyEditNameModal.component.tsx index a09d93f4f0a4..7b259e3df195 100644 --- a/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyEditNameModal.component.tsx +++ b/packages/manager/apps/key-management-service/src/components/serviceKey/modals/ServiceKeyEditNameModal.component.tsx @@ -37,7 +37,7 @@ export const ServiceKeyEditNameModal = ({ }: ServiceKeyEditNameModalProps) => { const [serviceKeyName, setServiceKeyName] = useState(name); const serviceKeyNameError = validateServiceKeyName(serviceKeyName); - const { addSuccess } = useNotifications(); + const { addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/serviceKeys'); const { t: tCommon } = useTranslation('key-management-service/common'); @@ -49,6 +49,7 @@ export const ServiceKeyEditNameModal = ({ okmsId, keyId, onSuccess: () => { + clearNotifications(); addSuccess( t('key_management_service_service-keys_update_name_success'), true, diff --git a/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsCredential.ts b/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsCredential.ts index 42061cf963ab..db078b5a7e0c 100644 --- a/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsCredential.ts +++ b/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsCredential.ts @@ -21,7 +21,7 @@ export const useCreateOkmsCredential = ({ onError, }: CreateOkmsCredentialParams) => { const queryClient = useQueryClient(); - const { addError, addSuccess } = useNotifications(); + const { addError, addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/credential'); @@ -34,10 +34,12 @@ export const useCreateOkmsCredential = ({ await queryClient.invalidateQueries({ queryKey: getOkmsCredentialsQueryKey(okmsId), }); + clearNotifications(); addSuccess(t('key_management_service_credential_create_success'), true); onSuccess?.(credential); }, onError: (result: ApiError) => { + clearNotifications(); addError( t('key_management_service_credential_create_error', { error: result.message, diff --git a/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsServiceKey.ts b/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsServiceKey.ts index 5240c813572b..302f2c2e1193 100644 --- a/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsServiceKey.ts +++ b/packages/manager/apps/key-management-service/src/data/hooks/useCreateOkmsServiceKey.ts @@ -20,7 +20,7 @@ export const useCreateOkmsServiceKey = ({ onError, }: CreateOkmsServiceKeyParams) => { const queryClient = useQueryClient(); - const { addError, addSuccess } = useNotifications(); + const { addError, addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/serviceKeys'); @@ -32,10 +32,12 @@ export const useCreateOkmsServiceKey = ({ await queryClient.invalidateQueries({ queryKey: getOkmsServiceKeyResourceListQueryKey(okmsId), }); + clearNotifications(); addSuccess(t('key_management_service_service-keys_create_success'), true); onSuccess?.(); }, onError: (result: ApiError) => { + clearNotifications(); addError( t('key_management_service_service-keys_create_error', { error: result.message, diff --git a/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsCredential.ts b/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsCredential.ts index 81d86113ea6e..8c78bc28a4c8 100644 --- a/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsCredential.ts +++ b/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsCredential.ts @@ -22,7 +22,7 @@ export const useDeleteOkmsCredential = ({ onError, }: IUseDeleteOkmsCredential) => { const queryClient = useQueryClient(); - const { addError, addSuccess } = useNotifications(); + const { addError, addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/credential'); const { mutate, isPending } = useMutation({ @@ -34,11 +34,12 @@ export const useDeleteOkmsCredential = ({ await queryClient.invalidateQueries({ queryKey: getOkmsCredentialsQueryKey(okmsId), }); - + clearNotifications(); addSuccess(t('key_management_service_credential_delete_success'), true); onSuccess(); }, onError: (result: ApiError) => { + clearNotifications(); addError( t('key_management_service_credential_delete_error', { error: result.message, diff --git a/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsServiceKey.ts b/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsServiceKey.ts index fb4aa0b96f45..d65425fec7c1 100644 --- a/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsServiceKey.ts +++ b/packages/manager/apps/key-management-service/src/data/hooks/useDeleteOkmsServiceKey.ts @@ -23,7 +23,7 @@ export const useDeleteOkmsServiceKey = ({ onError, }: DeleteOkmsServiceKeyParams) => { const queryClient = useQueryClient(); - const { addError, addSuccess } = useNotifications(); + const { addError, addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/serviceKeys'); @@ -39,10 +39,12 @@ export const useDeleteOkmsServiceKey = ({ await queryClient.invalidateQueries({ queryKey: getOkmsServiceKeyResourceQueryKey({ okmsId, keyId }), }); + clearNotifications(); addSuccess(t('key_management_service_service-keys_delete_success'), true); onSuccess(); }, onError: (result: ApiError) => { + clearNotifications(); addError( t('key_management_service_service-keys_delete_error', { error: result.message, diff --git a/packages/manager/apps/key-management-service/src/data/hooks/useUpdateOkmsServiceKey.ts b/packages/manager/apps/key-management-service/src/data/hooks/useUpdateOkmsServiceKey.ts index 58b220130222..a4df369e1ec4 100644 --- a/packages/manager/apps/key-management-service/src/data/hooks/useUpdateOkmsServiceKey.ts +++ b/packages/manager/apps/key-management-service/src/data/hooks/useUpdateOkmsServiceKey.ts @@ -24,7 +24,7 @@ export const useUpdateOkmsServiceKey = ({ onError, }: UpdateOkmsServiceKeyParams) => { const queryClient = useQueryClient(); - const { addError } = useNotifications(); + const { addError, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/serviceKeys'); @@ -43,6 +43,7 @@ export const useUpdateOkmsServiceKey = ({ onSuccess(); }, onError: (result: ApiError) => { + clearNotifications(); addError( t('key_management_service_service-keys_update_error', { error: result.message, diff --git a/packages/manager/apps/key-management-service/src/hooks/serviceKey/useServiceKeyActionsList.tsx b/packages/manager/apps/key-management-service/src/hooks/serviceKey/useServiceKeyActionsList.tsx index 03b7d9cd568e..818f8c4de944 100644 --- a/packages/manager/apps/key-management-service/src/hooks/serviceKey/useServiceKeyActionsList.tsx +++ b/packages/manager/apps/key-management-service/src/hooks/serviceKey/useServiceKeyActionsList.tsx @@ -21,7 +21,7 @@ const useServiceKeyActionsList = ( isListMode?: boolean, ) => { const { t } = useTranslation('key-management-service/serviceKeys'); - const { addSuccess } = useNotifications(); + const { addSuccess, clearNotifications } = useNotifications(); const navigate = useNavigate(); const { deleteKmsServiceKey, @@ -42,6 +42,7 @@ const useServiceKeyActionsList = ( okmsId: okms.id, keyId: okmsKey?.id, onSuccess: () => { + clearNotifications(); addSuccess( t('key_management_service_service-keys_reactivate_success'), true,