Skip to content

Commit c36074a

Browse files
committed
cleanup
1 parent 5ffd047 commit c36074a

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

apps/sim/app/workspace/[workspaceId]/w/hooks/use-import-workflow.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
5252
const workflowName = extractWorkflowName(content, filename)
5353
clearDiff()
5454

55-
const parsedContent = JSON.parse(content)
5655
const workflowColor =
57-
parsedContent.state?.metadata?.color || parsedContent.metadata?.color || '#3972F6'
56+
(workflowData.metadata as { color?: string } | undefined)?.color || '#3972F6'
5857

5958
const result = await createWorkflowMutation.mutateAsync({
6059
name: workflowName,
@@ -66,12 +65,16 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
6665
})
6766
const newWorkflowId = result.id
6867

69-
await fetch(`/api/workflows/${newWorkflowId}/state`, {
68+
const stateResponse = await fetch(`/api/workflows/${newWorkflowId}/state`, {
7069
method: 'PUT',
7170
headers: { 'Content-Type': 'application/json' },
7271
body: JSON.stringify(workflowData),
7372
})
7473

74+
if (!stateResponse.ok) {
75+
logger.error(`Failed to save workflow state for ${newWorkflowId}`)
76+
}
77+
7578
if (workflowData.variables) {
7679
const variablesArray = Array.isArray(workflowData.variables)
7780
? workflowData.variables
@@ -94,11 +97,15 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
9497
}
9598
}
9699

97-
await fetch(`/api/workflows/${newWorkflowId}/variables`, {
100+
const variablesResponse = await fetch(`/api/workflows/${newWorkflowId}/variables`, {
98101
method: 'POST',
99102
headers: { 'Content-Type': 'application/json' },
100103
body: JSON.stringify({ variables: variablesRecord }),
101104
})
105+
106+
if (!variablesResponse.ok) {
107+
logger.error(`Failed to save variables for ${newWorkflowId}`)
108+
}
102109
}
103110
}
104111

apps/sim/app/workspace/[workspaceId]/w/hooks/use-import-workspace.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,8 @@ export function useImportWorkspace({ onSuccess }: UseImportWorkspaceProps = {})
160160
const workflowName = extractWorkflowName(workflow.content, workflow.name)
161161
clearDiff()
162162

163-
const parsedContent = JSON.parse(workflow.content)
164163
const workflowColor =
165-
parsedContent.state?.metadata?.color || parsedContent.metadata?.color || '#3972F6'
164+
(workflowData.metadata as { color?: string } | undefined)?.color || '#3972F6'
166165

167166
const createWorkflowResponse = await fetch('/api/workflows', {
168167
method: 'POST',
@@ -216,11 +215,18 @@ export function useImportWorkspace({ onSuccess }: UseImportWorkspaceProps = {})
216215
}
217216
}
218217

219-
await fetch(`/api/workflows/${newWorkflow.id}/variables`, {
220-
method: 'POST',
221-
headers: { 'Content-Type': 'application/json' },
222-
body: JSON.stringify({ variables: variablesRecord }),
223-
})
218+
const variablesResponse = await fetch(
219+
`/api/workflows/${newWorkflow.id}/variables`,
220+
{
221+
method: 'POST',
222+
headers: { 'Content-Type': 'application/json' },
223+
body: JSON.stringify({ variables: variablesRecord }),
224+
}
225+
)
226+
227+
if (!variablesResponse.ok) {
228+
logger.error(`Failed to save variables for ${newWorkflow.id}`)
229+
}
224230
}
225231
}
226232

0 commit comments

Comments
 (0)