forked from parseablehq/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseGetLogStreamList.tsx
51 lines (47 loc) · 1.19 KB
/
useGetLogStreamList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { getLogStreamList } from '@/api/logStream';
import { useQuery } from 'react-query';
import { AxiosError, isAxiosError } from 'axios';
import Cookies from 'js-cookie';
export const useGetLogStreamList = () => {
const logout = () => {
Cookies.remove('session');
Cookies.remove('username');
window.location.reload();
};
const {
data: getLogStreamListData,
isError: getLogStreamListIsError,
isSuccess: getLogStreamListIsSuccess,
isLoading: getLogStreamListIsLoading,
refetch: getLogStreamListRefetch,
} = useQuery(['fetch-log-stream-list'], () => getLogStreamList(), {
onError: (data: AxiosError) => {
if (isAxiosError(data) && data.response) {
if (data.response && data.response.status === 401) {
logout();
}
}
},
retry: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
});
getLogStreamListData?.data.sort((a, b) => {
const nameA = a.name.toUpperCase();
const nameB = b.name.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
return {
getLogStreamListData,
getLogStreamListIsError,
getLogStreamListIsSuccess,
getLogStreamListIsLoading,
getLogStreamListRefetch,
};
};