refactor(Flows): utilize useQuery over useMutation

This commit is contained in:
Ali BARIN
2025-01-20 15:38:21 +00:00
parent 08c1abe193
commit b237b2a2bc
7 changed files with 26 additions and 75 deletions

View File

@@ -12,8 +12,8 @@ export default function useDeleteFlow(flowId) {
return data;
},
onSuccess: () => {
queryClient.invalidateQueries({
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['flows'],
});
},

View File

@@ -12,8 +12,8 @@ export default function useDuplicateFlow(flowId) {
return data;
},
onSuccess: () => {
queryClient.invalidateQueries({
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['flows'],
});
},

View File

@@ -0,0 +1,18 @@
import api from 'helpers/api';
import { useQuery } from '@tanstack/react-query';
export default function useFlows({ flowName, page }) {
const query = useQuery({
queryKey: ['flows', flowName, { page }],
queryFn: async ({ signal }) => {
const { data } = await api.get('/v1/flows', {
params: { name: flowName, page },
signal,
});
return data;
},
});
return query;
}

View File

@@ -1,30 +0,0 @@
import * as React from 'react';
import api from 'helpers/api';
import { useMutation } from '@tanstack/react-query';
export default function useLazyFlows({ flowName, page }, { onSettled }) {
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;
},
onSettled,
});
return query;
}