From 0af52a6d8bce4bfb9b5d73b2f3aedc9bcaf59f28 Mon Sep 17 00:00:00 2001 From: balaji-jr Date: Mon, 29 Jan 2024 14:42:07 +0530 Subject: [PATCH] ISSUE-185 - rm all snackbar triggers --- src/hooks/useAlertsEditor.tsx | 36 +--------- src/hooks/useCacheToggle.tsx | 19 +----- src/hooks/useDeleteLogStream.tsx | 26 +------- src/hooks/useGetAbout.tsx | 18 ----- src/hooks/useGetLogStreamList.tsx | 16 ----- src/hooks/useLogStream.tsx | 42 +----------- src/hooks/useLogStreamStats.tsx | 16 ----- src/hooks/useRetentionEditor.tsx | 36 +--------- src/hooks/useRole.tsx | 77 +-------------------- src/hooks/useUser.tsx | 107 +----------------------------- 10 files changed, 10 insertions(+), 383 deletions(-) diff --git a/src/hooks/useAlertsEditor.tsx b/src/hooks/useAlertsEditor.tsx index 158c1105..10ae468e 100644 --- a/src/hooks/useAlertsEditor.tsx +++ b/src/hooks/useAlertsEditor.tsx @@ -1,10 +1,8 @@ import { useMutation, useQuery } from 'react-query'; import { getLogStreamAlerts, putLogStreamAlerts } from '@/api/logStream'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; +import { IconFileAlert } from '@tabler/icons-react'; import { notifications } from '@mantine/notifications'; import useMountedState from './useMountedState'; -import { isAxiosError, AxiosError } from 'axios'; export const useAlertsEditor = (streamName: string) => { const [alertQuery, setAlertQuery] = useMountedState(''); @@ -13,30 +11,7 @@ export const useAlertsEditor = (streamName: string) => { mutate: updateLogStreamAlerts, data: alertQueryData, isSuccess: updateLogStreamIsSuccess, - } = useMutation((data: string) => putLogStreamAlerts(streamName, data), { - onSuccess: () => { - notifyApi({ - color: 'green', - message: 'Alert Added.', - icon: , - }); - }, - onError: (data: AxiosError) => { - if (isAxiosError(data) && data.response) { - const error = data.response.data; - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: `Error occurred, please check your query and try again ${error}`, - icon: , - autoClose: 3000, - }, - true, - ); - } - }, - }); + } = useMutation((data: string) => putLogStreamAlerts(streamName, data), {}); const { data: getLogAlertData, @@ -44,13 +19,6 @@ export const useAlertsEditor = (streamName: string) => { isSuccess: getLogAlertIsSuccess, isLoading: getLogAlertIsLoading, } = useQuery(['fetch-log-stream-alert', streamName, updateLogStreamIsSuccess], () => getLogStreamAlerts(streamName), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get log streams alert', - icon: , - }); - }, onSuccess: (data) => { setAlertQuery(JSON.stringify(data?.data)); }, diff --git a/src/hooks/useCacheToggle.tsx b/src/hooks/useCacheToggle.tsx index 20865dfd..7c384a09 100644 --- a/src/hooks/useCacheToggle.tsx +++ b/src/hooks/useCacheToggle.tsx @@ -1,27 +1,10 @@ import { useMutation, useQuery } from 'react-query'; import { getCachingStatus, updateCaching } from '@/api/caching'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; export const useCacheToggle = (streamName: string) => { const { mutate: updateCacheStatus, isSuccess: updateCacheIsSuccess } = useMutation( ({ type }: { type: boolean }) => updateCaching(streamName, type), - { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to change cache setting', - icon: , - }); - }, - onSuccess: () => { - notifyApi({ - color: 'green', - message: 'Succesfully updated cache setting', - icon: , - }); - }, - }, + {}, ); const { data: checkCacheData } = useQuery( diff --git a/src/hooks/useDeleteLogStream.tsx b/src/hooks/useDeleteLogStream.tsx index a3a7ccc9..c9455a95 100644 --- a/src/hooks/useDeleteLogStream.tsx +++ b/src/hooks/useDeleteLogStream.tsx @@ -1,7 +1,5 @@ import { useMutation } from 'react-query'; import { deleteLogStream } from '@/api/logStream'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; export const useDeleteLogStream = () => { const { @@ -9,29 +7,7 @@ export const useDeleteLogStream = () => { isSuccess: deleteLogStreamIsSuccess, isError: deleteLogStreamIsError, isLoading: deleteLogStreamIsLoading, - } = useMutation((data: { deleteStream: string }) => deleteLogStream(data.deleteStream), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Stream was deleted', - message: 'Successfully Deleted', - icon: , - autoClose: 8000, - }); - }, - onError: () => { - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: 'Error occurred while deleting stream', - icon: , - autoClose: 2000, - }, - true, - ); - }, - }); + } = useMutation((data: { deleteStream: string }) => deleteLogStream(data.deleteStream), {}); return { deleteLogStreamMutation, diff --git a/src/hooks/useGetAbout.tsx b/src/hooks/useGetAbout.tsx index b991a733..fea561ba 100644 --- a/src/hooks/useGetAbout.tsx +++ b/src/hooks/useGetAbout.tsx @@ -1,7 +1,5 @@ import { getCurrentAbout } from '@/api/about'; import { useQuery } from 'react-query'; -import { notifyApi } from '@/utils/notification'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; export const useAbout = () => { const { @@ -10,22 +8,6 @@ export const useAbout = () => { isSuccess: getAboutIsSuccess, isLoading: getAboutIsLoading, } = useQuery(['fetch-about'], () => getCurrentAbout(), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get log streams alert', - icon: , - }); - }, - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Streams was loaded', - message: 'Successfully Loaded', - icon: , - autoClose: 1000, - }); - }, retry: false, refetchOnWindowFocus: false, refetchOnMount: false, diff --git a/src/hooks/useGetLogStreamList.tsx b/src/hooks/useGetLogStreamList.tsx index 5c440f6c..3bb9f59f 100644 --- a/src/hooks/useGetLogStreamList.tsx +++ b/src/hooks/useGetLogStreamList.tsx @@ -1,7 +1,5 @@ import { getLogStreamList } from '@/api/logStream'; import { useQuery } from 'react-query'; -import { IconFileAlert, IconCheck } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; import { AxiosError, isAxiosError } from 'axios'; import Cookies from 'js-cookie'; @@ -24,22 +22,8 @@ export const useGetLogStreamList = () => { if (data.response && data.response.status === 401) { logout(); } - notifyApi({ - color: 'red', - message: 'Failed to get log streams alert', - icon: , - }); } }, - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Streams was loaded', - message: 'Successfully Loaded', - icon: , - autoClose: 1000, - }); - }, retry: false, refetchOnWindowFocus: false, refetchOnMount: false, diff --git a/src/hooks/useLogStream.tsx b/src/hooks/useLogStream.tsx index b8450e68..478fdf52 100644 --- a/src/hooks/useLogStream.tsx +++ b/src/hooks/useLogStream.tsx @@ -1,6 +1,4 @@ import { useMutation, useQuery } from 'react-query'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; import { deleteLogStream, getLogStreamList } from '@/api/logStream'; export const useLogStream = () => { @@ -9,29 +7,7 @@ export const useLogStream = () => { isSuccess: deleteLogStreamIsSuccess, isError: deleteLogStreamIsError, isLoading: deleteLogStreamIsLoading, - } = useMutation((data: { deleteStream: string }) => deleteLogStream(data.deleteStream), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Stream was deleted', - message: 'Successfully Deleted', - icon: , - autoClose: 8000, - }); - }, - onError: () => { - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: 'Error occurred while deleting stream', - icon: , - autoClose: 2000, - }, - true, - ); - }, - }); + } = useMutation((data: { deleteStream: string }) => deleteLogStream(data.deleteStream), {}); const { data: getLogStreamListData, @@ -40,22 +16,6 @@ export const useLogStream = () => { isLoading: getLogStreamListIsLoading, refetch: getLogStreamListRefetch, } = useQuery(['fetch-log-stream-list', deleteLogStreamIsSuccess], () => getLogStreamList(), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get log streams alert', - icon: , - }); - }, - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Streams was loaded', - message: 'Successfully Loaded', - icon: , - autoClose: 1000, - }); - }, retry: false, refetchOnWindowFocus: false, refetchOnMount: false, diff --git a/src/hooks/useLogStreamStats.tsx b/src/hooks/useLogStreamStats.tsx index 680ea891..b9359a32 100644 --- a/src/hooks/useLogStreamStats.tsx +++ b/src/hooks/useLogStreamStats.tsx @@ -1,7 +1,5 @@ import { useQuery } from 'react-query'; import { getLogStreamStats } from '@/api/logStream'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; export const useLogStreamStats = (streamName: string) => { const { @@ -10,20 +8,6 @@ export const useLogStreamStats = (streamName: string) => { isError: getLogStreamStatsDataIsError, isLoading: getLogStreamStatsDataIsLoading, } = useQuery(['fetch-log-stream-stats', streamName], () => getLogStreamStats(streamName), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get log streams stats', - icon: , - }); - }, - onSuccess: () => { - notifyApi({ - color: 'green', - message: 'Successfully fetched log streams stats', - icon: , - }); - }, retry: false, enabled: streamName !== '', }); diff --git a/src/hooks/useRetentionEditor.tsx b/src/hooks/useRetentionEditor.tsx index 57513932..93311725 100644 --- a/src/hooks/useRetentionEditor.tsx +++ b/src/hooks/useRetentionEditor.tsx @@ -1,10 +1,8 @@ import { useMutation, useQuery } from 'react-query'; import { getLogStreamRetention, putLogStreamRetention } from '@/api/logStream'; -import { notifyApi } from '@/utils/notification'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; +import { IconFileAlert } from '@tabler/icons-react'; import { notifications } from '@mantine/notifications'; import useMountedState from './useMountedState'; -import { isAxiosError, AxiosError } from 'axios'; export const useRetentionEditor = (streamName: string) => { const [retentionQuery, setRetentionQuery] = useMountedState(''); @@ -13,30 +11,7 @@ export const useRetentionEditor = (streamName: string) => { mutate: updateLogStreamRetention, data: retentionEditorData, isSuccess: updateLogRetentionIsSuccess, - } = useMutation((data: string) => putLogStreamRetention(streamName, data), { - onSuccess: () => { - notifyApi({ - color: 'green', - message: 'Retention Added.', - icon: , - }); - }, - onError: (data: AxiosError) => { - if (isAxiosError(data) && data.response) { - const error = data.response.data; - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: `Error occurred, please check your query and try again ${error}`, - icon: , - autoClose: 3000, - }, - true, - ); - } - }, - }); + } = useMutation((data: string) => putLogStreamRetention(streamName, data), {}); const { data: getLogRetentionData, @@ -47,13 +22,6 @@ export const useRetentionEditor = (streamName: string) => { ['fetch-log-stream-retention', streamName, updateLogRetentionIsSuccess], () => getLogStreamRetention(streamName), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get log streams retention', - icon: , - }); - }, onSuccess: (data) => { setRetentionQuery(JSON.stringify(data?.data)); }, diff --git a/src/hooks/useRole.tsx b/src/hooks/useRole.tsx index e1cf0a2e..0922a84a 100644 --- a/src/hooks/useRole.tsx +++ b/src/hooks/useRole.tsx @@ -1,6 +1,4 @@ import { useMutation, useQuery, useQueryClient } from 'react-query'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; import { deleteRole, getDefaultRole, getRole, getRoles, putDeafultRole, putRole } from '@/api/roles'; import Cookies from 'js-cookie'; @@ -14,29 +12,7 @@ export const useRole = () => { isError: updateRoleIsError, isLoading: updateRoleIsLoading, data: updateRoleData, - } = useMutation((data: { userName: string; privilege: object[] }) => putRole(data.userName, data.privilege), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Role was udpated', - message: 'Successfully updated', - icon: , - autoClose: 8000, - }); - }, - onError: () => { - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: 'Error occurred while updating role', - icon: , - autoClose: 2000, - }, - true, - ); - }, - }); + } = useMutation((data: { userName: string; privilege: object[] }) => putRole(data.userName, data.privilege), {}); const { mutate: deleteRoleMutation, @@ -44,26 +20,7 @@ export const useRole = () => { isError: deleteRoleIsError, isLoading: deleteRoleIsLoading, } = useMutation((data: { roleName: string }) => deleteRole(data.roleName), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Role was deleted', - message: 'Successfully Deleted', - icon: , - autoClose: 8000, - }); - }, onError: () => { - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: 'Error occurred while deleting role', - icon: , - autoClose: 2000, - }, - true, - ); queryClient.invalidateQueries(['fetch-roles']); }, }); @@ -75,14 +32,6 @@ export const useRole = () => { isLoading: getRolesIsLoading, refetch: getRolesRefetch, } = useQuery(['fetch-roles', username, updateRoleIsSuccess, deleteRoleIsSuccess], () => getRoles(), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get Roles', - icon: , - }); - }, - onSuccess: () => {}, retry: false, refetchOnWindowFocus: false, }); @@ -94,14 +43,6 @@ export const useRole = () => { isLoading: getRoleIsLoading, mutate: getRoleMutation, } = useMutation((data: { roleName: string }) => getRole(data?.roleName), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get Roles', - icon: , - }); - }, - onSuccess: () => {}, retry: false, }); @@ -112,14 +53,6 @@ export const useRole = () => { isLoading: updateDefaultRoleIsLoading, mutate: updateDefaultRoleMutation, } = useMutation((data: { roleName: string }) => putDeafultRole(data?.roleName), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get Roles', - icon: , - }); - }, - onSuccess: () => {}, retry: false, }); @@ -130,14 +63,6 @@ export const useRole = () => { isLoading: getDefaultRoleIsLoading, mutate: getDefaultRoleMutation, } = useMutation(() => getDefaultRole(), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get Roles', - icon: , - }); - }, - onSuccess: () => {}, retry: false, }); diff --git a/src/hooks/useUser.tsx b/src/hooks/useUser.tsx index 79aec83c..28ec8e41 100644 --- a/src/hooks/useUser.tsx +++ b/src/hooks/useUser.tsx @@ -1,6 +1,4 @@ import { useMutation, useQuery } from 'react-query'; -import { IconCheck, IconFileAlert } from '@tabler/icons-react'; -import { notifyApi } from '@/utils/notification'; import { deleteUser, getUserRoles, getUsers, postUser, postUserResetPassword, putUserRoles } from '@/api/users'; import { isAxiosError, AxiosError } from 'axios'; import useMountedState from './useMountedState'; @@ -17,29 +15,10 @@ export const useUser = () => { data: createUserData, reset: createUserReset, } = useMutation((data: { userName: string; roles: object[] }) => postUser(data.userName, data.roles), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'User was created', - message: 'Successfully created', - icon: , - autoClose: 3000, - }); - }, onError: (data: AxiosError) => { if (isAxiosError(data) && data.response) { const error = data.response.data as string; setCreateUserError(error); - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: `${error}`, - icon: , - autoClose: 2000, - }, - true, - ); } }, }); @@ -50,29 +29,7 @@ export const useUser = () => { isError: deleteUserIsError, isLoading: deleteUserIsLoading, data: deleteUserData, - } = useMutation((data: { userName: string }) => deleteUser(data.userName), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'User was deleted', - message: 'Successfully deleted', - icon: , - autoClose: 3000, - }); - }, - onError: () => { - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: 'Error occurred while deleting user', - icon: , - autoClose: 2000, - }, - true, - ); - }, - }); + } = useMutation((data: { userName: string }) => deleteUser(data.userName), {}); const { mutate: updateUserMutation, @@ -80,32 +37,7 @@ export const useUser = () => { isError: updateUserIsError, isLoading: updateUserIsLoading, data: udpateUserData, - } = useMutation((data: { userName: string; roles: string[] }) => putUserRoles(data.userName, data.roles), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'User was updated', - message: 'Successfully updated', - icon: , - autoClose: 3000, - }); - }, - onError: (data: AxiosError) => { - if (isAxiosError(data) && data.response) { - const error = data.response.data; - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: `${error}`, - icon: , - autoClose: 2000, - }, - true, - ); - } - }, - }); + } = useMutation((data: { userName: string; roles: string[] }) => putUserRoles(data.userName, data.roles), {}); const { mutate: updateUserPasswordMutation, @@ -114,29 +46,10 @@ export const useUser = () => { isLoading: updateUserPasswordIsLoading, data: udpateUserPasswordData, } = useMutation((data: { userName: string }) => postUserResetPassword(data.userName), { - onSuccess: () => { - notifyApi({ - color: 'green', - title: 'Password was Changed', - message: 'Successfully Changed', - icon: , - autoClose: 3000, - }); - }, onError: (data: AxiosError) => { if (isAxiosError(data) && data.response) { const error = data.response.data as string; setResetPasswordError(error); - notifyApi( - { - color: 'red', - title: 'Error occurred', - message: `${error}`, - icon: , - autoClose: 2000, - }, - true, - ); } }, }); @@ -148,14 +61,6 @@ export const useUser = () => { isLoading: getUserIsLoading, refetch: getUserRefetch, } = useQuery(['fetch-user', createUserIsSuccess, deleteUserIsSuccess], () => getUsers(), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get user', - icon: , - }); - }, - onSuccess: () => {}, retry: false, }); @@ -166,14 +71,6 @@ export const useUser = () => { isLoading: getUserRolesIsLoading, mutate: getUserRolesMutation, } = useMutation((data: { userName: string }) => getUserRoles(data?.userName), { - onError: () => { - notifyApi({ - color: 'red', - message: 'Failed to get Roles', - icon: , - }); - }, - onSuccess: () => {}, retry: false, });