feat: create flow with trigger app

This commit is contained in:
Ali BARIN
2022-01-30 01:24:42 +01:00
committed by Ömer Faruk Aydın
parent 131d33916a
commit 700d0bfd32
7 changed files with 43 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -16,7 +16,8 @@ export const APP_FLOWS = (appKey: string): string => `/app/${appKey}/flows`;
export const APP_FLOWS_PATTERN = '/app/:appKey/flows';
export const EDITOR = '/editor';
export const CREATE_FLOW = '/editor/create';
export const CREATE_FLOW ='/editor/create';
export const CREATE_FLOW_WITH_APP = (appKey: string) => `/editor/create?appKey=${appKey}`;
export const FLOW_EDITOR = (flowId: string): string => `/editor/${flowId}`;
export const FLOWS = '/flows';

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client';
export const CREATE_FLOW = gql`
mutation createFlow {
createFlow {
mutation createFlow($input: FlowInput) {
createFlow(input: $input) {
id
name
}

View File

@@ -70,9 +70,9 @@ export default function Application(): React.ReactElement {
linkProps,
ref,
) {
return <Link ref={ref} to={URLS.CREATE_FLOW} {...linkProps} />;
return <Link ref={ref} to={URLS.CREATE_FLOW_WITH_APP(appKey)} {...linkProps} />;
}),
[],
[appKey],
);
return (

View File

@@ -1,5 +1,5 @@
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useMutation } from '@apollo/client';
import CircularProgress from '@mui/material/CircularProgress';
import Typography from '@mui/material/Typography';
@@ -11,22 +11,29 @@ import { CREATE_FLOW } from 'graphql/mutations/create-flow';
import Box from '@mui/material/Box';
export default function CreateFlow(): React.ReactElement {
const [searchParams] = useSearchParams();
const navigate = useNavigate();
const formatMessage = useFormatMessage();
const [createFlow] = useMutation(CREATE_FLOW);
const appKey = searchParams.get('appKey');
React.useEffect(() => {
async function initiate() {
const response = await createFlow();
const response = await createFlow({
variables: {
input: {
triggerAppKey: appKey,
}
}
});
const flowId = response.data?.createFlow?.id;
setTimeout(() => {
navigate(URLS.FLOW_EDITOR(flowId));
}, 1234);
navigate(URLS.FLOW_EDITOR(flowId));
}
initiate();
}, [createFlow, navigate]);
}, [createFlow, navigate, appKey]);
return (
<Box sx={{ display: 'flex', flex: 1, height: '100vh', justifyContent: 'center', alignItems: 'center', gap: 2 }}>