feat: add useTriggerSubsteps and useActionSubsteps with RQ

This commit is contained in:
Rıdvan Akca
2024-03-05 15:08:10 +03:00
parent c4b2ea125c
commit 5fe3546d2a
3 changed files with 64 additions and 1 deletions

View File

@@ -38,6 +38,8 @@ import isEmpty from 'helpers/isEmpty';
import { StepPropType } from 'propTypes/propTypes'; import { StepPropType } from 'propTypes/propTypes';
import useTriggers from 'hooks/useTriggers'; import useTriggers from 'hooks/useTriggers';
import useActions from 'hooks/useActions'; import useActions from 'hooks/useActions';
import useTriggerSubsteps from 'hooks/useTriggerSubsteps';
import useActionSubsteps from 'hooks/useActionsSubsteps';
const validIcon = <CheckCircleIcon color="success" />; const validIcon = <CheckCircleIcon color="success" />;
const errorIcon = <ErrorIcon color="error" />; const errorIcon = <ErrorIcon color="error" />;
@@ -153,7 +155,24 @@ function FlowStep(props) {
({ key }) => key === step.key, ({ key }) => key === step.key,
); );
const substeps = actionOrTrigger?.substeps || []; const { data: triggerSubsteps } = useTriggerSubsteps(
app?.key,
actionOrTrigger?.key,
);
const triggerSubstepsData = triggerSubsteps?.data || [];
const { data: actionSubsteps } = useActionSubsteps(
app?.key,
actionOrTrigger?.key,
);
const actionSubstepsData = actionSubsteps?.data || [];
const substeps =
triggerSubstepsData.length > 0
? triggerSubstepsData
: actionSubstepsData || [];
const handleChange = React.useCallback(({ step }) => { const handleChange = React.useCallback(({ step }) => {
onChange(step); onChange(step);

View File

@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useActionSubsteps(appKey, actionKey) {
const query = useQuery({
queryKey: ['actionSubsteps', appKey, actionKey],
queryFn: async ({ payload, signal }) => {
const { data } = await api.get(
`/v1/apps/${appKey}/actions/${actionKey}/substeps`,
{
signal,
},
);
return data;
},
enabled: !!appKey,
});
return query;
}

View File

@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useTriggerSubsteps(appKey, triggerKey) {
const query = useQuery({
queryKey: ['triggerSubsteps', appKey, triggerKey],
queryFn: async ({ payload, signal }) => {
const { data } = await api.get(
`/v1/apps/${appKey}/triggers/${triggerKey}/substeps`,
{
signal,
},
);
return data;
},
enabled: !!appKey,
});
return query;
}