feat: add useTriggerSubsteps and useActionSubsteps with RQ
This commit is contained in:
@@ -38,6 +38,8 @@ import isEmpty from 'helpers/isEmpty';
|
||||
import { StepPropType } from 'propTypes/propTypes';
|
||||
import useTriggers from 'hooks/useTriggers';
|
||||
import useActions from 'hooks/useActions';
|
||||
import useTriggerSubsteps from 'hooks/useTriggerSubsteps';
|
||||
import useActionSubsteps from 'hooks/useActionsSubsteps';
|
||||
|
||||
const validIcon = <CheckCircleIcon color="success" />;
|
||||
const errorIcon = <ErrorIcon color="error" />;
|
||||
@@ -153,7 +155,24 @@ function FlowStep(props) {
|
||||
({ 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 }) => {
|
||||
onChange(step);
|
||||
|
22
packages/web/src/hooks/useActionsSubsteps.js
Normal file
22
packages/web/src/hooks/useActionsSubsteps.js
Normal 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;
|
||||
}
|
22
packages/web/src/hooks/useTriggerSubsteps.js
Normal file
22
packages/web/src/hooks/useTriggerSubsteps.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user