1
- import { Button } from "@ /components/ui/button" ;
1
+ import { Button } from "../.. /components/ui/button" ;
2
2
import {
3
3
Dialog ,
4
4
DialogContent ,
@@ -7,48 +7,74 @@ import {
7
7
DialogHeader ,
8
8
DialogTitle ,
9
9
DialogTrigger ,
10
- } from "@ /components/ui/dialog" ;
11
- import { Input } from "@ /components/ui/input" ;
12
- import { Label } from "@ /components/ui/label" ;
10
+ } from "../.. /components/ui/dialog" ;
11
+ import { Input } from "../.. /components/ui/input" ;
12
+ import { Label } from "../.. /components/ui/label" ;
13
13
import { Plus } from "lucide-react" ;
14
+ import { useState } from "react" ;
15
+
16
+ export function AddStageModal ( { setNodes } ) {
17
+ const [ open , setOpen ] = useState ( false ) ;
14
18
15
- export function AddStageModal ( ) {
16
19
return (
17
- < Dialog >
20
+ < Dialog open = { open } onOpenChange = { setOpen } >
18
21
< DialogTrigger asChild >
19
22
< Button size = "sm" >
20
23
< Plus />
21
24
Add New Stage
22
25
</ Button >
23
26
</ DialogTrigger >
24
27
< DialogContent className = "sm:max-w-[425px]" >
25
- < DialogHeader >
26
- < DialogTitle > Add new Stage</ DialogTitle >
27
- < DialogDescription >
28
- A stage is basically compilation of admins
29
- </ DialogDescription >
30
- </ DialogHeader >
31
- < div className = "grid gap-6" >
32
- < div className = "grid items-center gap-1" >
33
- < Label htmlFor = "name" > Name</ Label >
34
- < Input
35
- id = "name"
36
- className = "w-full"
37
- placeholder = "Enter name of the stage"
38
- />
39
- </ div >
40
- < div className = "grid items-center gap-1" >
41
- < Label htmlFor = "username" > Username</ Label >
42
- < Input
43
- id = "username"
44
- className = "w-full"
45
- placeholder = "Enter admins for the stage"
46
- />
28
+ < form
29
+ className = "space-y-4"
30
+ onSubmit = { ( e ) => {
31
+ e . preventDefault ( ) ;
32
+
33
+ const formData = new FormData ( e . target ) ;
34
+ const name = formData . get ( "name" ) ;
35
+
36
+ if ( ! name ) {
37
+ alert ( "Name is required!" ) ;
38
+ return ;
39
+ }
40
+
41
+ const newNode = {
42
+ id : `node-${ Date . now ( ) } ` ,
43
+ type : "LabeledGroupNode" ,
44
+ style : {
45
+ width : 400 ,
46
+ height : 250 ,
47
+ backgroundColor : "rgba(240,240,240,0.25)" ,
48
+ } ,
49
+ position : { x : 100 , y : 100 } ,
50
+ data : { label : name , setNodes } , // Pass setNodes through the data property
51
+ } ;
52
+
53
+ setNodes ( ( prevNodes ) => [ ...prevNodes , newNode ] ) ;
54
+ setOpen ( false ) ;
55
+ } }
56
+ >
57
+ < DialogHeader >
58
+ < DialogTitle > Add new Stage</ DialogTitle >
59
+ < DialogDescription >
60
+ A stage is basically a compilation of processes.
61
+ </ DialogDescription >
62
+ </ DialogHeader >
63
+ < div className = "grid gap-6" >
64
+ < div className = "grid items-center gap-1" >
65
+ < Label htmlFor = "name" > Name</ Label >
66
+ < Input
67
+ id = "name"
68
+ name = "name"
69
+ className = "w-full"
70
+ placeholder = "Enter name of the stage"
71
+ />
72
+ </ div >
47
73
</ div >
48
- </ div >
49
- < DialogFooter >
50
- < Button type = "submit" > Create Stage </ Button >
51
- </ DialogFooter >
74
+ < DialogFooter >
75
+ < Button type = "submit" > Create Stage </ Button >
76
+ </ DialogFooter >
77
+ </ form >
52
78
</ DialogContent >
53
79
</ Dialog >
54
80
) ;
0 commit comments