import React, { useState, useCallback } from "react"; import { useLocation } from "react-router-dom"; import { nanoid } from "nanoid"; import "./assets/css/style.css"; import imageStart from "./assets/images/ILLO_MiniSpot_2-Paths-v2_1080x1080.png"; import PopupListFlow from "./Popups/PopupListFlow"; import { mainNode } from "./data/data"; import App from "./App"; const BuildFlow = () => { const [showPopup, setShowPopup] = useState(true); const location = useLocation(); const [selectedFlow, setSelectedFlow] = useState(null); const query = new URLSearchParams(location.search); const flowName = query.get("flowName"); const handleAddStartPointClick = () => { setShowPopup(true); }; const hidePopup = () => { setShowPopup(false); }; const handleSelectFlow = (flow) => { setSelectedFlow(flow); // Lưu flow đã chọn hidePopup(); // Ẩn popup sau khi chọn flow // Tìm node khớp với flow trong mainNode const selectedMainNode = mainNode.find((node) => node.key === flow); if (selectedMainNode) { // Tạo một node từ mainNode const newNode = { id: `${selectedMainNode.id}`, // Sử dụng id từ mainNode type: "input", data: { label: (
{selectedMainNode.name}
), }, position: { ...selectedMainNode.position }, // Vị trí từ mainNode }; // Tạo node add-node const addNode = { id: "2", key: "add-node", type: "default", data: { label: (
+ Add a journey point
), }, position: { x: selectedMainNode.position.x, y: selectedMainNode.position.y + 180, }, className: "contact-exits", }; // Kết nối giữa node và add-node const newEdge = { id: `edge-${selectedMainNode.id}-add-node`, source: `${selectedMainNode.id}`, target: "2", type: "custom", data: { onAddNodeCallback }, }; // Cập nhật state với node mới, add-node, và edge setNodes((nds) => [newNode, addNode]); setEdges((eds) => [newEdge]); } }; return ( <> {!selectedFlow ? ( <>

Building Flow: {flowName}

How will a contact start their journey?

This is what kicks off your contact's journey. You choose the starting point, then contacts who meet the criteria will enter your map and begin their journey.

{showPopup && ( setShowPopup(false)} /> )}
) : ( )} ); }; export default BuildFlow;