refactor: rewrite parameters of RQ hooks
This commit is contained in:
@@ -40,12 +40,14 @@ function AddNewAppConnection(props) {
|
|||||||
const [appName, setAppName] = React.useState('');
|
const [appName, setAppName] = React.useState('');
|
||||||
const [isLoading, setIsLoading] = React.useState(false);
|
const [isLoading, setIsLoading] = React.useState(false);
|
||||||
|
|
||||||
const { data: apps, mutate } = useLazyApps({
|
const { data: apps, mutate } = useLazyApps(
|
||||||
appName,
|
{ appName },
|
||||||
onSuccess: () => {
|
{
|
||||||
setIsLoading(false);
|
onSuccess: () => {
|
||||||
|
setIsLoading(false);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
const fetchData = React.useMemo(() => debounce(mutate, 300), [mutate]);
|
const fetchData = React.useMemo(() => debounce(mutate, 300), [mutate]);
|
||||||
|
|
||||||
|
@@ -161,17 +161,17 @@ function FlowStep(props) {
|
|||||||
({ key }) => key === step.key,
|
({ key }) => key === step.key,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data: triggerSubsteps } = useTriggerSubsteps(
|
const { data: triggerSubsteps } = useTriggerSubsteps({
|
||||||
app?.key,
|
appKey: app?.key,
|
||||||
actionOrTrigger?.key,
|
triggerKey: actionOrTrigger?.key,
|
||||||
);
|
});
|
||||||
|
|
||||||
const triggerSubstepsData = triggerSubsteps?.data || [];
|
const triggerSubstepsData = triggerSubsteps?.data || [];
|
||||||
|
|
||||||
const { data: actionSubsteps } = useActionSubsteps(
|
const { data: actionSubsteps } = useActionSubsteps({
|
||||||
app?.key,
|
appKey: app?.key,
|
||||||
actionOrTrigger?.key,
|
actionKey: actionOrTrigger?.key,
|
||||||
);
|
});
|
||||||
|
|
||||||
const actionSubstepsData = actionSubsteps?.data || [];
|
const actionSubstepsData = actionSubsteps?.data || [];
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
|
|
||||||
import api from 'helpers/api';
|
import api from 'helpers/api';
|
||||||
|
|
||||||
export default function useActionSubsteps(appKey, actionKey) {
|
export default function useActionSubsteps({ appKey, actionKey }) {
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['actionSubsteps', appKey, actionKey],
|
queryKey: ['actionSubsteps', appKey, actionKey],
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
|
@@ -3,11 +3,15 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
import api from 'helpers/api';
|
import api from 'helpers/api';
|
||||||
|
|
||||||
export default function useApps(variables) {
|
export default function useApps(variables) {
|
||||||
|
const trueOnlyVariables = Object.fromEntries(
|
||||||
|
Object.entries(variables).filter(([_, value]) => value === true),
|
||||||
|
);
|
||||||
|
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['apps', variables],
|
queryKey: ['apps', trueOnlyVariables],
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
const { data } = await api.get('/v1/apps', {
|
const { data } = await api.get('/v1/apps', {
|
||||||
params: variables,
|
params: trueOnlyVariables,
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query';
|
|||||||
import api from 'helpers/api';
|
import api from 'helpers/api';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export default function useLazyApps({ appName, onSuccess }) {
|
export default function useLazyApps({ appName } = {}, { onSuccess }) {
|
||||||
const abortControllerRef = React.useRef(new AbortController());
|
const abortControllerRef = React.useRef(new AbortController());
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -15,7 +15,7 @@ export default function useLazyApps({ appName, onSuccess }) {
|
|||||||
}, [appName]);
|
}, [appName]);
|
||||||
|
|
||||||
const query = useMutation({
|
const query = useMutation({
|
||||||
mutationFn: async ({ payload }) => {
|
mutationFn: async () => {
|
||||||
const { data } = await api.get('/v1/apps', {
|
const { data } = await api.get('/v1/apps', {
|
||||||
params: { name: appName },
|
params: { name: appName },
|
||||||
signal: abortControllerRef.current.signal,
|
signal: abortControllerRef.current.signal,
|
||||||
|
@@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
|
|
||||||
import api from 'helpers/api';
|
import api from 'helpers/api';
|
||||||
|
|
||||||
export default function useTriggerSubsteps(appKey, triggerKey) {
|
export default function useTriggerSubsteps({ appKey, triggerKey }) {
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['triggerSubsteps', appKey, triggerKey],
|
queryKey: ['triggerSubsteps', appKey, triggerKey],
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
|
Reference in New Issue
Block a user