From 11aaa430289ac3d2d62fdbdeeae5e68e51340873 Mon Sep 17 00:00:00 2001 From: Zabilsya Date: Thu, 12 Dec 2024 18:06:31 +0600 Subject: [PATCH] [DOP-21928] add success notifications --- .../connection/api/hooks/useDeleteConnection/index.ts | 3 +++ src/entities/connection/ui/ConnectionTypeForm/index.tsx | 2 +- src/entities/group/api/hooks/useDeleteGroupUser/index.ts | 3 +++ src/entities/queue/api/hooks/useDeleteQueue/index.ts | 3 +++ src/entities/run/api/hooks/useCreateRun/index.ts | 3 +++ src/entities/transfer/api/hooks/useDeleteTransfer/index.ts | 3 +++ src/features/connection/CreateConnection/index.tsx | 1 + src/features/connection/UpdateConnection/index.tsx | 1 + src/features/group/AddGroupUser/index.tsx | 1 + src/features/group/CreateGroup/index.tsx | 3 ++- src/features/group/UpdateGroup/index.tsx | 3 ++- src/features/group/UpdateGroupUser/index.tsx | 1 + src/features/queue/CreateQueue/index.tsx | 1 + src/features/queue/UpdateQueue/index.tsx | 1 + src/shared/ui/ManagedForm/index.tsx | 6 ++++++ src/shared/ui/ManagedForm/types.ts | 2 ++ src/widgets/transfer/CreateTransfer/index.tsx | 1 + src/widgets/transfer/UpdateTransfer/index.tsx | 1 + 18 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/entities/connection/api/hooks/useDeleteConnection/index.ts b/src/entities/connection/api/hooks/useDeleteConnection/index.ts index 071aaa99..b0c8c2cd 100644 --- a/src/entities/connection/api/hooks/useDeleteConnection/index.ts +++ b/src/entities/connection/api/hooks/useDeleteConnection/index.ts @@ -15,6 +15,9 @@ export const useDeleteConnection = (data: DeleteConnectionRequest): UseMutationR onSuccess: () => { queryClient.invalidateQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTIONS] }); queryClient.removeQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTION, data.id] }); + notification.success({ + message: 'Connection was deleted successfully', + }); }, onError: (error) => { notification.error({ diff --git a/src/entities/connection/ui/ConnectionTypeForm/index.tsx b/src/entities/connection/ui/ConnectionTypeForm/index.tsx index 23e090f2..6309b1ff 100644 --- a/src/entities/connection/ui/ConnectionTypeForm/index.tsx +++ b/src/entities/connection/ui/ConnectionTypeForm/index.tsx @@ -15,7 +15,7 @@ export const ConnectionTypeForm = ({ initialType, isRequiredSensitiveFields = tr return ( <> - + - + diff --git a/src/features/group/UpdateGroup/index.tsx b/src/features/group/UpdateGroup/index.tsx index b2436ddc..7dfb9f56 100644 --- a/src/features/group/UpdateGroup/index.tsx +++ b/src/features/group/UpdateGroup/index.tsx @@ -28,6 +28,7 @@ export const UpdateGroup = ({ group }: UpdateGroupProps) => { mutationFunction={handleUpdateGroup} initialValues={getUpdateGroupInitialValues(group)} onSuccess={onSuccess} + successMessage="Group was updated successfully" keysInvalidateQueries={[ [{ queryKey: [GroupQueryKey.GET_GROUPS] }], [{ queryKey: [GroupQueryKey.GET_GROUP, group.id] }], @@ -37,7 +38,7 @@ export const UpdateGroup = ({ group }: UpdateGroupProps) => { - + diff --git a/src/features/group/UpdateGroupUser/index.tsx b/src/features/group/UpdateGroupUser/index.tsx index a11c606f..dc350dd1 100644 --- a/src/features/group/UpdateGroupUser/index.tsx +++ b/src/features/group/UpdateGroupUser/index.tsx @@ -19,6 +19,7 @@ export const UpdateGroupUser = ({ groupId, user, onSuccess, onCancel }: UpdateGr initialValues={getUpdateGroupUserInitialValues(user)} mutationFunction={handleUpdateGroupUser} onSuccess={onSuccess} + successMessage="User role was updated successfully" keysInvalidateQueries={[[{ queryKey: [GroupQueryKey.GET_GROUP_USERS, groupId] }]]} >
diff --git a/src/features/queue/CreateQueue/index.tsx b/src/features/queue/CreateQueue/index.tsx index a44de7cc..9991f971 100644 --- a/src/features/queue/CreateQueue/index.tsx +++ b/src/features/queue/CreateQueue/index.tsx @@ -25,6 +25,7 @@ export const CreateQueue = ({ group }: CreateQueueProps) => { mutationFunction={handleCreateQueue} onSuccess={onSuccess} + successMessage="Queue was created successfully" keysInvalidateQueries={[[{ queryKey: [QueueQueryKey.GET_QUEUES, group.id] }]]} > diff --git a/src/features/queue/UpdateQueue/index.tsx b/src/features/queue/UpdateQueue/index.tsx index 26af4321..4d8199e9 100644 --- a/src/features/queue/UpdateQueue/index.tsx +++ b/src/features/queue/UpdateQueue/index.tsx @@ -27,6 +27,7 @@ export const UpdateQueue = ({ queue, group }: UpdateQueueProps) => { mutationFunction={handleUpdateQueue} initialValues={getUpdateQueueInitialValues(queue)} onSuccess={onSuccess} + successMessage="Queue was updated successfully" keysInvalidateQueries={[ [{ queryKey: [QueueQueryKey.GET_QUEUES, group.id] }], [{ queryKey: [QueueQueryKey.GET_QUEUE, queue.id] }], diff --git a/src/shared/ui/ManagedForm/index.tsx b/src/shared/ui/ManagedForm/index.tsx index 1fc3c917..5e403782 100644 --- a/src/shared/ui/ManagedForm/index.tsx +++ b/src/shared/ui/ManagedForm/index.tsx @@ -13,6 +13,7 @@ export const ManagedForm = ({ children, mutationFunction, onSuccess, + successMessage, keysInvalidateQueries = [], isHiddenLoadingOnSuccess = false, onError = () => undefined, @@ -35,6 +36,11 @@ export const ManagedForm = ({ if (isHiddenLoadingOnSuccess) { setLoading(false); } + if (successMessage) { + notification.success({ + message: successMessage, + }); + } }, onError: (error) => { onError(error); diff --git a/src/shared/ui/ManagedForm/types.ts b/src/shared/ui/ManagedForm/types.ts index 3a4075f8..6071ff01 100644 --- a/src/shared/ui/ManagedForm/types.ts +++ b/src/shared/ui/ManagedForm/types.ts @@ -12,6 +12,8 @@ export interface ManagedFormProps extends Omit, 'form' | 'onF mutationFunction: (params: T) => Promise; /** Callback on success response from request */ onSuccess: (response: R) => void; + /** Notification message text on success response from request */ + successMessage?: string; /** Callback on error response from request */ onError?: (error: unknown) => void; /** Keys for invalidate cache of other requests */ diff --git a/src/widgets/transfer/CreateTransfer/index.tsx b/src/widgets/transfer/CreateTransfer/index.tsx index 85c5c93c..109d45b5 100644 --- a/src/widgets/transfer/CreateTransfer/index.tsx +++ b/src/widgets/transfer/CreateTransfer/index.tsx @@ -27,6 +27,7 @@ export const CreateTransfer = ({ group }: CreateTransferProps) => { initialValues={CREATE_TRANSFER_INITIAL_VALUES} mutationFunction={handleCreateTransfer} onSuccess={onSuccess} + successMessage="Transfer was created successfully" keysInvalidateQueries={[[{ queryKey: [TransferQueryKey.GET_TRANSFERS, group.id] }]]} > diff --git a/src/widgets/transfer/UpdateTransfer/index.tsx b/src/widgets/transfer/UpdateTransfer/index.tsx index 43b6bbdf..0712f7ef 100644 --- a/src/widgets/transfer/UpdateTransfer/index.tsx +++ b/src/widgets/transfer/UpdateTransfer/index.tsx @@ -27,6 +27,7 @@ export const UpdateTransfer = ({ transfer, group }: UpdateTransferProps) => { initialValues={transferInitialValues} mutationFunction={handleUpdateTransfer} onSuccess={onSuccess} + successMessage="Transfer was updated successfully" keysInvalidateQueries={[ [{ queryKey: [TransferQueryKey.GET_TRANSFERS, group.id] }], [{ queryKey: [TransferQueryKey.GET_TRANSFER, transfer.id] }],