31 lines
708 B
JavaScript
31 lines
708 B
JavaScript
import * as React from 'react';
|
|
|
|
import api from 'helpers/api';
|
|
import { useMutation } from '@tanstack/react-query';
|
|
|
|
export default function useFlows({ flowName, page }, { onSuccess }) {
|
|
const abortControllerRef = React.useRef(new AbortController());
|
|
|
|
React.useEffect(() => {
|
|
abortControllerRef.current = new AbortController();
|
|
|
|
return () => {
|
|
abortControllerRef.current?.abort();
|
|
};
|
|
}, [flowName]);
|
|
|
|
const query = useMutation({
|
|
mutationFn: async () => {
|
|
const { data } = await api.get('/v1/flows', {
|
|
params: { name: flowName, page },
|
|
signal: abortControllerRef.current.signal,
|
|
});
|
|
|
|
return data;
|
|
},
|
|
onSuccess,
|
|
});
|
|
|
|
return query;
|
|
}
|