-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7c03f0
commit d7b2744
Showing
12 changed files
with
496 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,41 @@ | ||
import { toast } from "sonner"; | ||
import reactFlowToWorkflow from "./reactFlowToWorkflow"; | ||
import useStore from "~/app/states/store"; | ||
export async function saveWorkflow() { | ||
const nodes = useStore.getState().nodes; | ||
const edges = useStore.getState().edges; | ||
const { workflowResponse: workflow, errors } = await reactFlowToWorkflow({ | ||
nodes, | ||
edges, | ||
}); | ||
|
||
export async function saveWorkflow(workflow: WorkflowResponse) { | ||
const promise = fetch("/api/workflow", { | ||
const responsePromise = fetch("/api/workflow", { | ||
method: "POST", | ||
body: JSON.stringify(workflow), | ||
}) | ||
.then((res) => { | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
if (data.errors) { | ||
throw new Error("Error saving workflow"); | ||
} | ||
return data; | ||
}); | ||
toast.promise(promise, { | ||
}); | ||
|
||
toast.promise(responsePromise, { | ||
loading: "Saving workflow...", | ||
success: (_data) => { | ||
return `${workflow.name} saved successfully`; | ||
}, | ||
success: (_data) => `${workflow.name} saved successfully`, | ||
error: "Error saving workflow", | ||
}); | ||
return promise; | ||
} | ||
|
||
const response = await responsePromise; | ||
const data = await response.json(); | ||
|
||
if (data.errors) { | ||
throw new Error("Error saving workflow"); | ||
} | ||
|
||
useStore.setState((state) => ({ | ||
...state, | ||
flowState: { | ||
...state.flowState, | ||
description: data.description, | ||
name: data.name, | ||
id: data.id, | ||
}, | ||
})); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.