1
+ import {
2
+ Button ,
3
+ FormControl ,
4
+ FormHelperText ,
5
+ FormLabel ,
6
+ Input ,
7
+ useToast
8
+ } from "@chakra-ui/react" ;
9
+ import axios from 'axios' ;
10
+ import { useState } from "react" ;
11
+
12
+
13
+ import { useNavigate } from "react-router" ;
14
+
15
+ export default function CreateProject ( ) {
16
+ const redirect = useNavigate ( ) ;
17
+ const toast = useToast ( ) ;
18
+ const [ name , setName ] = useState ( '' ) ;
19
+ const [ description , setDescription ] = useState ( '' ) ;
20
+ const [ version , setVersion ] = useState ( '' ) ;
21
+ const [ website_url , setWebsite_url ] = useState ( '' ) ;
22
+
23
+ async function handleSubmit ( e ) {
24
+ e . preventDefault ( ) ;
25
+
26
+ const res = await axios . post ( 'http://localhost:4597/v1/projects' , {
27
+ name,
28
+ description,
29
+ version,
30
+ website_url
31
+ } )
32
+
33
+ if ( res . status == 200 ) {
34
+ toast ( {
35
+ title : 'Project created.' ,
36
+ description : "We've created your Project." ,
37
+ status : 'success' ,
38
+ duration : 9000 ,
39
+ isClosable : true ,
40
+ } )
41
+ redirect ( '/projects' )
42
+ }
43
+
44
+ return false ;
45
+ }
46
+
47
+ return (
48
+ < form onSubmit = { handleSubmit } >
49
+ < FormControl >
50
+ < FormLabel > Name</ FormLabel >
51
+ < Input type = 'text' name = 'name' onChange = { ( e ) => setName ( e . target . value ) } />
52
+ < FormHelperText > Project Title.</ FormHelperText >
53
+ </ FormControl >
54
+
55
+ < FormControl >
56
+ < FormLabel > Description</ FormLabel >
57
+ < Input type = 'text' name = 'description' onChange = { ( e ) => setDescription ( e . target . value ) } />
58
+ < FormHelperText > Project description.</ FormHelperText >
59
+ </ FormControl >
60
+
61
+ < FormControl >
62
+ < FormLabel > Version</ FormLabel >
63
+ < Input type = 'text' name = 'version' onChange = { ( e ) => setVersion ( e . target . value ) } />
64
+ < FormHelperText > Project version.</ FormHelperText >
65
+ </ FormControl >
66
+
67
+ < FormControl >
68
+ < FormLabel > Website URL</ FormLabel >
69
+ < Input type = 'text' name = 'website_url' onChange = { ( e ) => setWebsite_url ( e . target . value ) } />
70
+ < FormHelperText > Project version.</ FormHelperText >
71
+ </ FormControl >
72
+
73
+ < Button type = 'submit' > Submit</ Button >
74
+ </ form >
75
+ )
76
+ }
0 commit comments