7
7
Textarea ,
8
8
Button ,
9
9
Link ,
10
- Stack ,
10
+ VStack ,
11
11
} from "@chakra-ui/react" ;
12
12
import { LuExternalLink } from "react-icons/lu" ;
13
13
import { Field } from "../components/ui/field" ;
@@ -23,15 +23,12 @@ const ShareAProject = () => {
23
23
youtube_video_link : "" ,
24
24
tags : [ ] ,
25
25
} ) ;
26
- const [ errors , setErrors ] = useState ( {
27
- github_link : "" ,
28
- youtube_video_link : "" ,
29
- } ) ;
30
26
31
27
const validateUrl = ( url ) => {
32
28
const urlPattern = / ^ ( h t t p s ? : \/ \/ ) ? ( [ \w - ] + ( \. [ \w - ] + ) + ) ( \/ [ \w - . ] * ) * ( \? .+ ) ? $ / ;
33
29
return urlPattern . test ( url ) ;
34
30
} ;
31
+
35
32
const handleSubmit = async ( e ) => {
36
33
e . preventDefault ( ) ;
37
34
if ( newProject . tags . length === 0 ) {
@@ -43,51 +40,38 @@ const ShareAProject = () => {
43
40
label : "x" ,
44
41
} ,
45
42
} ) ;
46
- //console.log("Please select at least one framework/language.");
47
43
return ;
48
44
}
49
- const newErrors = { } ;
50
45
51
46
// Validate GitHub URL (Required)
52
47
if ( ! newProject . github_link || ! validateUrl ( newProject . github_link ) ) {
53
- newErrors . github_link = "Please provide a valid GitHub repository URL." ;
48
+ toaster . create ( {
49
+ title : "Please provide a valid GitHub repository URL." ,
50
+ type : "warning" ,
51
+ duration : 4000 ,
52
+ action : {
53
+ label : "x" ,
54
+ } ,
55
+ } ) ;
56
+ return ;
54
57
}
55
58
56
59
// Validate Live Demo URL (Optional, only if provided)
57
60
if (
58
61
newProject . youtube_video_link &&
59
62
! validateUrl ( newProject . youtube_video_link )
60
63
) {
61
- newErrors . youtube_video_link = "Please provide a valid Live Demo URL." ;
62
- }
63
- console . log ( Object . keys ( newErrors ) . length ) ;
64
- if ( Object . keys ( newErrors ) . length > 0 ) {
65
- setErrors ( newErrors ) ; // Display errors
66
-
67
- if ( errors . github_link ) {
68
- console . log ( errors . github_link ) ;
69
- toaster . create ( {
70
- title : errors . github_link ,
71
- type : "warning" ,
72
- duration : 4000 ,
73
- action : {
74
- label : "x" ,
75
- } ,
76
- } ) ;
77
- }
78
- if ( errors . youtube_video_link ) {
79
- console . log ( errors . youtube_video_link ) ;
80
- toaster . create ( {
81
- title : errors . youtube_video_link ,
82
- type : "warning" ,
83
- duration : 4000 ,
84
- action : {
85
- label : "x" ,
86
- } ,
87
- } ) ;
88
- }
64
+ toaster . create ( {
65
+ title : "Please provide a valid Live Demo URL." ,
66
+ type : "warning" ,
67
+ duration : 4000 ,
68
+ action : {
69
+ label : "x" ,
70
+ } ,
71
+ } ) ;
89
72
return ;
90
73
}
74
+
91
75
try {
92
76
const response = await fetch ( "http://localhost:8001/api/v1/addProject" , {
93
77
method : "POST" ,
@@ -99,7 +83,7 @@ const ShareAProject = () => {
99
83
} ) ;
100
84
if ( response . ok ) {
101
85
toaster . create ( {
102
- title : "Project submitted succesfully !" ,
86
+ title : "Project submitted successfully !" ,
103
87
type : "success" ,
104
88
duration : 8000 ,
105
89
action : {
@@ -115,7 +99,6 @@ const ShareAProject = () => {
115
99
} ) ;
116
100
} else {
117
101
console . error ( "Failed to add project:" , response . statusText ) ;
118
- //console.error("Failed to submit project");
119
102
}
120
103
} catch ( error ) {
121
104
toaster . create ( {
@@ -137,7 +120,7 @@ const ShareAProject = () => {
137
120
: [ ...prev . tags , value ] ,
138
121
} ) ) ;
139
122
} ;
140
- //const isSubmitEnabled = newProject.tags.length > 0;
123
+
141
124
return (
142
125
< form onSubmit = { handleSubmit } >
143
126
< div className = "share-project-container" >
@@ -317,8 +300,8 @@ const ShareAProject = () => {
317
300
}
318
301
/>
319
302
</ Field >
320
- < Field marginBottom = { "20%" } marginTop = { 10 } >
321
- < Stack direction = "row" h = "20" >
303
+ < Field marginBottom = { "20%" } marginTop = { 10 } display = 'flex' alignItems = 'center' >
304
+ < VStack direction = "row" h = "20" justifyContent = "center" alignItems = "center ">
322
305
< Button
323
306
className = "sp-button"
324
307
variant = "solid"
@@ -328,12 +311,12 @@ const ShareAProject = () => {
328
311
SUBMIT PROJECT
329
312
</ Button >
330
313
< Link
331
- style = { { fontSize : "20px" , color : "#63E9EE" , padding : "40px" } }
314
+ style = { { fontSize : "20px" , color : "#63E9EE" , alignItems : "center" , display : 'flex' } }
332
315
href = "/explore-project"
333
316
>
334
317
Go to explore projects < LuExternalLink />
335
318
</ Link >
336
- </ Stack >
319
+ </ VStack >
337
320
</ Field >
338
321
< Toaster />
339
322
</ div >
0 commit comments