MCPcopy Create free account
hub / github.com/WardAnalytics/WardGraph / CreateGraphDialog

Function CreateGraphDialog

src/components/common/CreateGraphDialog.tsx:21–86  ·  view source on GitHub ↗
({
  isOpen,
  setOpen,
  graphInfo,
})

Source from the content-addressed store, hash-verified

19}
20
21const CreateGraphDialog: FC<CreateGraphDialogProps> = ({
22 isOpen,
23 setOpen,
24 graphInfo,
25}) => {
26 const navigate = useNavigate();
27 const { user } = useAuthState();
28 const closeDialog = () => {
29 setOpen(false);
30 };
31 const [graphName, setGraphName] = useState<string>("");
32
33 const createGraph = useCallback(async () => {
34 if (!user) {
35 throw new Error("No user found for creating graph");
36 }
37 const graph: PersonalGraph = {
38 name: graphName,
39 data: graphInfo || {
40 addresses: [],
41 edges: [],
42 tags: [],
43 averageRisk: 0,
44 totalVolume: 0,
45 },
46 };
47 createPersonalGraph(user.uid, graph).then((uid) => {
48 // Reset the graph name and close the dialog
49 setGraphName("");
50 setOpen(false);
51 navigate(`/saved-graph/${uid}`);
52 });
53 }, [graphName]);
54
55 return (
56 <Modal isOpen={isOpen} closeModal={closeDialog} size="md">
57 <div className="flex items-center justify-between border-b border-gray-200 pb-3">
58 <h3 className="flex flex-row items-center gap-x-1.5 text-lg font-semibold leading-6 text-gray-900">
59 Create a new graph
60 </h3>
61
62 <XMarkIcon
63 className="h-11 w-11 cursor-pointer rounded-full p-1.5 text-gray-400 transition-all duration-300 hover:bg-gray-100"
64 aria-hidden="true"
65 onClick={closeDialog}
66 />
67 </div>
68 <span className="mt-3 flex flex-row gap-x-2">
69 {/** Graph name input and button to create. Either clicking the button or pressing enter will create the graph and navigate to the saved graph page */}
70 <input
71 type="text"
72 value={graphName}
73 onChange={(e) => setGraphName(e.target.value)}
74 placeholder="Graph name"
75 className="w-full rounded-md border-0 px-3 text-sm font-semibold leading-6 text-gray-900 ring-1 ring-inset ring-gray-300 transition-all placeholder:text-gray-400 focus:outline focus:outline-[3px] focus:outline-blue-200 focus:ring-2 focus:ring-blue-400"
76 onKeyDown={(event) => {
77 if (event.key === "Enter") {
78 createGraph();

Callers

nothing calls this directly

Calls 2

createPersonalGraphFunction · 0.90
useAuthStateFunction · 0.85

Tested by

no test coverage detected