@@ -11,7 +11,6 @@ import {
1111 useQueryClient ,
1212} from '@tanstack/react-query'
1313import { getNextWorkflowColor } from '@/lib/workflows/colors'
14- import { buildDefaultWorkflowArtifacts } from '@/lib/workflows/defaults'
1514import { deploymentKeys } from '@/hooks/queries/deployments'
1615import { fetchDeploymentVersionState } from '@/hooks/queries/utils/fetch-deployment-version-state'
1716import { getFolderMap } from '@/hooks/queries/utils/folder-cache'
@@ -105,6 +104,8 @@ interface CreateWorkflowResult {
105104 workspaceId : string
106105 folderId ?: string | null
107106 sortOrder : number
107+ startBlockId ?: string
108+ subBlockValues ?: Record < string , Record < string , unknown > >
108109}
109110
110111export function useCreateWorkflow ( ) {
@@ -144,19 +145,6 @@ export function useCreateWorkflow() {
144145
145146 logger . info ( `Successfully created workflow ${ workflowId } ` )
146147
147- const { workflowState } = buildDefaultWorkflowArtifacts ( )
148-
149- const stateResponse = await fetch ( `/api/workflows/${ workflowId } /state` , {
150- method : 'PUT' ,
151- headers : { 'Content-Type' : 'application/json' } ,
152- body : JSON . stringify ( workflowState ) ,
153- } )
154-
155- if ( ! stateResponse . ok ) {
156- const text = await stateResponse . text ( )
157- logger . error ( 'Failed to persist default workflow state:' , text )
158- }
159-
160148 return {
161149 id : workflowId ,
162150 name : createdWorkflow . name ,
@@ -165,6 +153,8 @@ export function useCreateWorkflow() {
165153 workspaceId,
166154 folderId : createdWorkflow . folderId ,
167155 sortOrder : createdWorkflow . sortOrder ?? 0 ,
156+ startBlockId : createdWorkflow . startBlockId ,
157+ subBlockValues : createdWorkflow . subBlockValues ,
168158 }
169159 } ,
170160 onMutate : async ( variables ) => {
@@ -247,13 +237,14 @@ export function useCreateWorkflow() {
247237 } )
248238 }
249239
250- const { subBlockValues } = buildDefaultWorkflowArtifacts ( )
251- useSubBlockStore . setState ( ( state ) => ( {
252- workflowValues : {
253- ...state . workflowValues ,
254- [ data . id ] : subBlockValues ,
255- } ,
256- } ) )
240+ if ( data . subBlockValues ) {
241+ useSubBlockStore . setState ( ( state ) => ( {
242+ workflowValues : {
243+ ...state . workflowValues ,
244+ [ data . id ] : data . subBlockValues ! ,
245+ } ,
246+ } ) )
247+ }
257248
258249 logger . info ( `[CreateWorkflow] Success, replaced temp entry ${ tempId } ` )
259250 } ,
0 commit comments