2025-09-05 16:19:31 +09:00
|
|
|
"use client";
|
2025-09-05 11:30:27 +09:00
|
|
|
|
2025-09-09 11:35:05 +09:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import DataFlowList from "@/components/dataflow/DataFlowList";
|
2025-10-16 15:05:24 +09:00
|
|
|
import { FlowEditor } from "@/components/dataflow/node-editor/FlowEditor";
|
2025-09-05 16:19:31 +09:00
|
|
|
import { useAuth } from "@/hooks/useAuth";
|
2025-09-26 01:28:51 +09:00
|
|
|
import { toast } from "sonner";
|
2026-03-03 16:04:11 +09:00
|
|
|
import { showErrorToast } from "@/lib/utils/toastUtils";
|
2025-10-16 15:05:24 +09:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { ArrowLeft } from "lucide-react";
|
2025-09-09 11:35:05 +09:00
|
|
|
|
2025-10-16 15:05:24 +09:00
|
|
|
type Step = "list" | "editor";
|
2025-09-05 11:30:27 +09:00
|
|
|
|
|
|
|
|
export default function DataFlowPage() {
|
|
|
|
|
const { user } = useAuth();
|
2025-09-09 11:35:05 +09:00
|
|
|
const [currentStep, setCurrentStep] = useState<Step>("list");
|
2025-10-16 15:05:24 +09:00
|
|
|
const [loadingFlowId, setLoadingFlowId] = useState<number | null>(null);
|
2025-09-09 11:35:05 +09:00
|
|
|
|
2025-10-16 15:05:24 +09:00
|
|
|
const handleLoadFlow = async (flowId: number | null) => {
|
|
|
|
|
if (flowId === null) {
|
|
|
|
|
setLoadingFlowId(null);
|
|
|
|
|
setCurrentStep("editor");
|
|
|
|
|
return;
|
2025-09-09 11:35:05 +09:00
|
|
|
}
|
|
|
|
|
|
2025-10-16 15:05:24 +09:00
|
|
|
try {
|
|
|
|
|
setLoadingFlowId(flowId);
|
|
|
|
|
setCurrentStep("editor");
|
2026-03-19 15:07:07 +09:00
|
|
|
toast.success("플로우를 불러왔어요");
|
2025-10-16 15:05:24 +09:00
|
|
|
} catch (error: any) {
|
2026-03-19 15:07:07 +09:00
|
|
|
console.error("플로우 불러오기 실패:", error);
|
|
|
|
|
showErrorToast("플로우를 불러오는 데 실패했어요", error, {
|
|
|
|
|
guidance: "네트워크 연결을 확인해 주세요.",
|
|
|
|
|
});
|
2025-09-09 11:35:05 +09:00
|
|
|
}
|
|
|
|
|
};
|
2025-09-05 11:30:27 +09:00
|
|
|
|
2025-10-16 15:05:24 +09:00
|
|
|
const handleBackToList = () => {
|
|
|
|
|
setCurrentStep("list");
|
|
|
|
|
setLoadingFlowId(null);
|
2025-09-09 11:35:05 +09:00
|
|
|
};
|
|
|
|
|
|
2026-03-19 15:07:07 +09:00
|
|
|
if (currentStep === "editor") {
|
2025-10-16 15:05:24 +09:00
|
|
|
return (
|
2025-12-30 17:45:38 +09:00
|
|
|
<div className="bg-background fixed inset-0 z-50">
|
2025-10-16 15:05:24 +09:00
|
|
|
<div className="flex h-full flex-col">
|
2026-03-19 15:07:07 +09:00
|
|
|
<div className="bg-background flex items-center gap-4 border-b px-5 py-3">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={handleBackToList}
|
|
|
|
|
className="text-muted-foreground hover:text-foreground flex items-center gap-2 text-sm"
|
|
|
|
|
>
|
2025-10-16 15:05:24 +09:00
|
|
|
<ArrowLeft className="h-4 w-4" />
|
|
|
|
|
목록으로
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-09-26 01:28:51 +09:00
|
|
|
|
2025-10-24 15:40:08 +09:00
|
|
|
<div className="flex-1 overflow-hidden">
|
2026-03-19 15:07:07 +09:00
|
|
|
<FlowEditor
|
|
|
|
|
key={loadingFlowId || "new"}
|
|
|
|
|
initialFlowId={loadingFlowId}
|
|
|
|
|
/>
|
2025-10-16 15:05:24 +09:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-09-05 11:30:27 +09:00
|
|
|
|
|
|
|
|
return (
|
2026-03-19 15:07:07 +09:00
|
|
|
<div className="h-full overflow-y-auto">
|
|
|
|
|
<div className="mx-auto w-full max-w-[1400px] space-y-6 p-4 sm:p-6 pb-20">
|
2025-10-16 15:05:24 +09:00
|
|
|
<DataFlowList onLoadFlow={handleLoadFlow} />
|
2025-09-09 11:35:05 +09:00
|
|
|
</div>
|
2025-09-05 11:30:27 +09:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|