refactor: rewrite useAutomatischInfo with RQ and REST API
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
import * as React from 'react';
|
||||
import { AutomatischInfoContext } from 'contexts/AutomatischInfo';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAutomatischInfo() {
|
||||
const automatischInfoContext = React.useContext(AutomatischInfoContext);
|
||||
return {
|
||||
isCloud: automatischInfoContext.isCloud,
|
||||
isMation: automatischInfoContext.isMation,
|
||||
loading: automatischInfoContext.loading,
|
||||
};
|
||||
const query = useQuery({
|
||||
/**
|
||||
* The data doesn't change by user actions, but only by server deployments.
|
||||
* So we can set the `staleTime` to Infinity
|
||||
**/
|
||||
staleTime: Infinity,
|
||||
queryKey: ['automatischInfo'],
|
||||
queryFn: async (payload, signal) => {
|
||||
const { data } = await api.get('/v1/automatisch/info', null, { signal });
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
|
Reference in New Issue
Block a user