Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-185 - rm all snackbar triggers #191

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions src/hooks/useAlertsEditor.tsx
Original file line number Diff line number Diff line change
@@ -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<string | undefined>('');
Expand All @@ -13,44 +11,14 @@ 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: <IconCheck size="1rem" />,
});
},
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: <IconFileAlert size="1rem" />,
autoClose: 3000,
},
true,
);
}
},
});
} = useMutation((data: string) => putLogStreamAlerts(streamName, data), {});

const {
data: getLogAlertData,
isError: getLogAlertIsError,
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: <IconFileAlert size="1rem" />,
});
},
onSuccess: (data) => {
setAlertQuery(JSON.stringify(data?.data));
},
Expand Down
19 changes: 1 addition & 18 deletions src/hooks/useCacheToggle.tsx
Original file line number Diff line number Diff line change
@@ -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: <IconFileAlert size="1rem" />,
});
},
onSuccess: () => {
notifyApi({
color: 'green',
message: 'Succesfully updated cache setting',
icon: <IconCheck size="1rem" />,
});
},
},
{},
);

const { data: checkCacheData } = useQuery(
Expand Down
26 changes: 1 addition & 25 deletions src/hooks/useDeleteLogStream.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
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 {
mutate: deleteLogStreamMutation,
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: <IconCheck size="1rem" />,
autoClose: 8000,
});
},
onError: () => {
notifyApi(
{
color: 'red',
title: 'Error occurred',
message: 'Error occurred while deleting stream',
icon: <IconFileAlert size="1rem" />,
autoClose: 2000,
},
true,
);
},
});
} = useMutation((data: { deleteStream: string }) => deleteLogStream(data.deleteStream), {});

return {
deleteLogStreamMutation,
Expand Down
18 changes: 0 additions & 18 deletions src/hooks/useGetAbout.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: <IconFileAlert size="1rem" />,
});
},
onSuccess: () => {
notifyApi({
color: 'green',
title: 'Streams was loaded',
message: 'Successfully Loaded',
icon: <IconCheck size="1rem" />,
autoClose: 1000,
});
},
retry: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
Expand Down
16 changes: 0 additions & 16 deletions src/hooks/useGetLogStreamList.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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: <IconFileAlert size="1rem" />,
});
}
},
onSuccess: () => {
notifyApi({
color: 'green',
title: 'Streams was loaded',
message: 'Successfully Loaded',
icon: <IconCheck size="1rem" />,
autoClose: 1000,
});
},
retry: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
Expand Down
42 changes: 1 addition & 41 deletions src/hooks/useLogStream.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand All @@ -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: <IconCheck size="1rem" />,
autoClose: 8000,
});
},
onError: () => {
notifyApi(
{
color: 'red',
title: 'Error occurred',
message: 'Error occurred while deleting stream',
icon: <IconFileAlert size="1rem" />,
autoClose: 2000,
},
true,
);
},
});
} = useMutation((data: { deleteStream: string }) => deleteLogStream(data.deleteStream), {});

const {
data: getLogStreamListData,
Expand All @@ -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: <IconFileAlert size="1rem" />,
});
},
onSuccess: () => {
notifyApi({
color: 'green',
title: 'Streams was loaded',
message: 'Successfully Loaded',
icon: <IconCheck size="1rem" />,
autoClose: 1000,
});
},
retry: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
Expand Down
16 changes: 0 additions & 16 deletions src/hooks/useLogStreamStats.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: <IconFileAlert size="1rem" />,
});
},
onSuccess: () => {
notifyApi({
color: 'green',
message: 'Successfully fetched log streams stats',
icon: <IconCheck size="1rem" />,
});
},
retry: false,
enabled: streamName !== '',
});
Expand Down
36 changes: 2 additions & 34 deletions src/hooks/useRetentionEditor.tsx
Original file line number Diff line number Diff line change
@@ -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<string | undefined>('');
Expand All @@ -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: <IconCheck size="1rem" />,
});
},
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: <IconFileAlert size="1rem" />,
autoClose: 3000,
},
true,
);
}
},
});
} = useMutation((data: string) => putLogStreamRetention(streamName, data), {});

const {
data: getLogRetentionData,
Expand All @@ -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: <IconFileAlert size="1rem" />,
});
},
onSuccess: (data) => {
setRetentionQuery(JSON.stringify(data?.data));
},
Expand Down
Loading
Loading