diff --git a/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/AddFlowModal.tsx b/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/AddFlowModal.tsx index db618bab3..911c1e782 100644 --- a/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/AddFlowModal.tsx +++ b/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/AddFlowModal.tsx @@ -12,8 +12,10 @@ import { toast } from '@/components/ui/use-toast'; export function AddFlowModal() { const [modalOpen, setModalOpen] = useState(false); const { id: copilotId } = useCopilot() + const [loading, setLoading] = useState(false) // this should create new flow on the server and then update the state async function onSubmit(e: React.FormEvent) { + setLoading(true) e.preventDefault(); const data = new FormData(e.currentTarget); const [name, description] = [ @@ -21,25 +23,35 @@ export function AddFlowModal() { data.get("description")?.toString(), ]; if (name && description) { - const { data } = await createWorkflowByBotId(copilotId, { - info: {}, - name, - description, - on_failure: [], - steps: [], on_success: [], - requires_confirmation: true, opencopilot: { - version: "0.0.1", - }, - }) - if (data.workflow_id) { + try { + const { data } = await createWorkflowByBotId(copilotId, { + info: {}, + name, + description, + on_failure: [], + steps: [], on_success: [], + requires_confirmation: true, opencopilot: { + version: "0.0.1", + }, + }) + if (data.workflow_id) { + toast({ + title: 'Flow created', + description: 'Your flow has been created', + variant: 'success' + }) + } + mutateFlows(copilotId); + setLoading(false) + setModalOpen(false); + } catch (error) { + setLoading(false); toast({ - title: 'Flow created', - description: 'Your flow has been created', - variant: 'success' + title: 'Error', + description: 'Something went wrong', + variant: 'destructive' }) } - mutateFlows(copilotId); - setModalOpen(false); } } return ( @@ -70,9 +82,9 @@ export function AddFlowModal() { className="my-2" /> - + Cancel diff --git a/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/WorkflowsList.tsx b/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/WorkflowsList.tsx index e1254b73c..113addde2 100644 --- a/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/WorkflowsList.tsx +++ b/dashboard/app/(copilot)/copilot/[copilot_id]/flows/_parts/WorkflowsList.tsx @@ -17,7 +17,7 @@ export function WorkflowsList({ copilot_id }: { copilot_id: string }) { return (
    { - isLoading ? : _.isEmpty(flows?.workflows) ? + isLoading ? : _.isEmpty(flows?.workflows) ?

    No flows yet

    : flows?.workflows.map((flow, i) => ( diff --git a/dashboard/app/(copilot)/copilot/[copilot_id]/flows/page.tsx b/dashboard/app/(copilot)/copilot/[copilot_id]/flows/page.tsx index f5d0ac67a..547933ab7 100644 --- a/dashboard/app/(copilot)/copilot/[copilot_id]/flows/page.tsx +++ b/dashboard/app/(copilot)/copilot/[copilot_id]/flows/page.tsx @@ -16,12 +16,12 @@ function SaveBtn() { const { state } = useController(); const [isEditing, workflowId] = useIsEditing(); const [loading, setLoading] = useState(false) + const { id: copilotId } = useCopilot(); async function handleSave() { if (!workflowId || !state.name || !state.description) return; + setLoading(true) try { - setLoading(true) - const { data } = await updateWorkflowById(workflowId, { - ...state, + const flow = { name: state.name, description: state.description, steps: state.steps, @@ -29,7 +29,14 @@ function SaveBtn() { version: "0.0.1" }, requires_confirmation: true, - }) + on_failure: [], + on_success: [], + opencopilot: { + version: "0.0.1", + }, + bot_id: copilotId + } + const { data } = await updateWorkflowById(workflowId, flow) if (data) { mutate(data._id) toast({ @@ -40,6 +47,7 @@ function SaveBtn() { } catch (error) { setLoading(false) } + setLoading(false) } return isEditing ? : null } @@ -55,6 +63,10 @@ function DeleteBtn() { const resp = await deleteWorkflowById(workflowId); if (resp.status === 200) { mutateFlows(copilotId) + toast({ + title: "Deleted successfully", + variant: "success" + }) reset() } } catch (error) { diff --git a/dashboard/components/domain/flows-editor/editor/PathButton.tsx b/dashboard/components/domain/flows-editor/editor/PathButton.tsx index c4ff6ee02..388c10e4d 100644 --- a/dashboard/components/domain/flows-editor/editor/PathButton.tsx +++ b/dashboard/components/domain/flows-editor/editor/PathButton.tsx @@ -50,7 +50,7 @@ export function PathButton({ path }: { path: TransformedPath }) { if (isPresentInNodes(method.method)) { return; } - const node: NodeData = { + const node: NodeData & { operation: string } = { id: `${path.path}-${method.method}`, path: path.path, method: method.method, @@ -59,6 +59,7 @@ export function PathButton({ path }: { path: TransformedPath }) { tags: method.tags, summary: method.summary, operationId: method.operationId, + operation: "REQUEST", } if (mode.type === "append-node") {