feat: use REST API endpoint to create flow

This commit is contained in:
Ali BARIN
2024-09-18 14:51:23 +00:00
parent 1790ef0ee6
commit 2e5dfdbb0d
6 changed files with 39 additions and 47 deletions

View File

@@ -134,10 +134,7 @@ export default function Application() {
color="primary"
size="large"
component={Link}
to={URLS.CREATE_FLOW_WITH_APP_AND_CONNECTION(
appKey,
connectionId,
)}
to={URLS.CREATE_FLOW}
fullWidth
icon={<AddIcon />}
disabled={!allowed}

View File

@@ -1,42 +1,30 @@
import * as React from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useMutation } from '@apollo/client';
import { useNavigate } from 'react-router-dom';
import CircularProgress from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';
import * as URLS from 'config/urls';
import useFormatMessage from 'hooks/useFormatMessage';
import { CREATE_FLOW } from 'graphql/mutations/create-flow';
import useCreateFlow from 'hooks/useCreateFlow';
import Box from '@mui/material/Box';
export default function CreateFlow() {
const [searchParams] = useSearchParams();
const navigate = useNavigate();
const formatMessage = useFormatMessage();
const [createFlow, { error }] = useMutation(CREATE_FLOW);
const appKey = searchParams.get('appKey');
const connectionId = searchParams.get('connectionId');
const { mutateAsync: createFlow, isError } = useCreateFlow();
React.useEffect(() => {
async function initiate() {
const variables = {};
if (appKey) {
variables.triggerAppKey = appKey;
}
if (connectionId) {
variables.connectionId = connectionId;
}
const response = await createFlow({
variables: {
input: variables,
},
});
const flowId = response.data?.createFlow?.id;
const response = await createFlow();
const flowId = response.data?.id;
navigate(URLS.FLOW_EDITOR(flowId), { replace: true });
}
initiate();
}, [createFlow, navigate, appKey, connectionId]);
if (error) {
initiate();
}, [createFlow, navigate]);
if (isError) {
return null;
}