Skip to content

Commit

Permalink
fix(kms): add clear notifications before trigger new notif
Browse files Browse the repository at this point in the history
ref: MANAGER-15377

Signed-off-by: Vincent BONMARCHAND <[email protected]>
  • Loading branch information
vovh authored and Romain Jamet committed Oct 25, 2024
1 parent f262440 commit 4b381f1
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -50,6 +50,7 @@ export const ServiceKeyDeactivateModal = ({
okmsId,
keyId,
onSuccess: () => {
clearNotifications();
addSuccess(
t('key_management_service_service-keys_deactivation_success'),
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -49,6 +49,7 @@ export const ServiceKeyEditNameModal = ({
okmsId,
keyId,
onSuccess: () => {
clearNotifications();
addSuccess(
t('key_management_service_service-keys_update_name_success'),
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -43,6 +43,7 @@ export const useUpdateOkmsServiceKey = ({
onSuccess();
},
onError: (result: ApiError) => {
clearNotifications();
addError(
t('key_management_service_service-keys_update_error', {
error: result.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +42,7 @@ const useServiceKeyActionsList = (
okmsId: okms.id,
keyId: okmsKey?.id,
onSuccess: () => {
clearNotifications();
addSuccess(
t('key_management_service_service-keys_reactivate_success'),
true,
Expand Down

0 comments on commit 4b381f1

Please sign in to comment.