@@ -12,50 +12,46 @@ import { Checkbox } from "../components/ui/checkbox";
12
12
import { Toaster , toaster } from "../components/ui/toaster" ;
13
13
14
14
const ShareAProject = ( ) => {
15
+ const token = JSON . parse ( localStorage . getItem ( "auth" ) ) ;
15
16
const [ newProject , setNewProject ] = useState ( {
16
- title : "" ,
17
- githubURL : "" ,
17
+ name : "" ,
18
18
description : "" ,
19
- frameworks : [ ] ,
20
- liveDemoURL : "" ,
21
- comments : "" ,
22
- date : "" ,
19
+ github_link : "" ,
20
+ youtube_video_link : "" ,
21
+ tags : [ ] ,
23
22
} ) ;
24
23
25
24
const handleSubmit = async ( e ) => {
26
25
e . preventDefault ( ) ;
26
+
27
27
try {
28
- const response = await fetch ( "http://localhost:8001/addproject " , {
28
+ const response = await fetch ( "http://localhost:8001/api/v1/addProject " , {
29
29
method : "POST" ,
30
30
headers : {
31
31
"Content-Type" : "application/json" ,
32
+ Authorization : `Bearer ${ token } ` , // Include the token in the Authorization header
32
33
} ,
33
- body : JSON . stringify ( {
34
- ...newProject ,
35
- date : new Date ( ) . toISOString ( ) ,
36
- } ) ,
34
+ body : JSON . stringify ( newProject ) ,
37
35
} ) ;
38
- console . log ( newProject ) ;
39
36
if ( response . ok ) {
40
37
toaster . create ( {
41
38
title : "Project submitted succesfully!" ,
42
39
type : "success" ,
43
- duration : 4000 ,
40
+ duration : 8000 ,
44
41
action : {
45
42
label : "x" ,
46
43
} ,
47
44
} ) ;
48
45
setNewProject ( {
49
- title : "" ,
50
- githubURL : "" ,
46
+ name : "" ,
51
47
description : "" ,
52
- frameworks : [ ] ,
53
- liveDemoURL : "" ,
54
- comments : "" ,
55
- date : "" ,
48
+ github_link : "" ,
49
+ youtube_video_link : "" ,
50
+ tags : [ ] ,
56
51
} ) ;
57
52
} else {
58
- console . error ( "Failed to submit project" ) ;
53
+ console . error ( "Failed to add project:" , response . statusText ) ;
54
+ //console.error("Failed to submit project");
59
55
}
60
56
} catch ( error ) {
61
57
toaster . create ( {
@@ -72,9 +68,9 @@ const ShareAProject = () => {
72
68
const handleCheckboxChange = ( value ) => {
73
69
setNewProject ( ( prev ) => ( {
74
70
...prev ,
75
- frameworks : prev . frameworks . includes ( value )
76
- ? prev . frameworks . filter ( ( framework ) => framework !== value )
77
- : [ ...prev . frameworks , value ] ,
71
+ tags : prev . tags . includes ( value )
72
+ ? prev . tags . filter ( ( tags ) => tags !== value )
73
+ : [ ...prev . tags , value ] ,
78
74
} ) ) ;
79
75
} ;
80
76
@@ -116,9 +112,9 @@ const ShareAProject = () => {
116
112
backgroundColor = "rgba(255, 255, 255, 0.16)"
117
113
placeholder = "Enter your Project"
118
114
borderRadius = "8px"
119
- value = { newProject . title }
115
+ value = { newProject . name }
120
116
onChange = { ( e ) =>
121
- setNewProject ( { ...newProject , title : e . target . value } )
117
+ setNewProject ( { ...newProject , name : e . target . value } )
122
118
}
123
119
/>
124
120
</ Field >
@@ -145,8 +141,8 @@ const ShareAProject = () => {
145
141
</ Field >
146
142
< Fieldset . Root >
147
143
< CheckboxGroup
148
- key = { newProject . frameworks . length }
149
- defaultValue = { newProject . frameworks }
144
+ key = { newProject . tags . length }
145
+ defaultValue = { newProject . tags }
150
146
name = "framework"
151
147
>
152
148
< Fieldset . Legend
@@ -163,7 +159,7 @@ const ShareAProject = () => {
163
159
value = "React"
164
160
colorPalette = "cyan"
165
161
variant = "solid"
166
- checked = { newProject . frameworks . includes ( "React" ) }
162
+ checked = { newProject . tags . includes ( "React" ) }
167
163
onChange = { ( ) => handleCheckboxChange ( "React" ) }
168
164
>
169
165
< span
@@ -180,7 +176,7 @@ const ShareAProject = () => {
180
176
value = "Node.js"
181
177
colorPalette = "green"
182
178
variant = "solid"
183
- checked = { newProject . frameworks . includes ( "Node.js" ) }
179
+ checked = { newProject . tags . includes ( "Node.js" ) }
184
180
onChange = { ( ) => handleCheckboxChange ( "Node.js" ) }
185
181
>
186
182
< span
@@ -197,7 +193,7 @@ const ShareAProject = () => {
197
193
value = "HTML / CSS"
198
194
colorPalette = "purple"
199
195
variant = "solid"
200
- checked = { newProject . frameworks . includes ( "HTML / CSS" ) }
196
+ checked = { newProject . tags . includes ( "HTML / CSS" ) }
201
197
onChange = { ( ) => handleCheckboxChange ( "HTML / CSS" ) }
202
198
>
203
199
< span
@@ -228,9 +224,9 @@ const ShareAProject = () => {
228
224
backgroundColor = "rgba(255, 255, 255, 0.16)"
229
225
placeholder = "Enter your Github repository URL"
230
226
borderRadius = "8px"
231
- value = { newProject . githubURL }
227
+ value = { newProject . github_link }
232
228
onChange = { ( e ) =>
233
- setNewProject ( { ...newProject , githubURL : e . target . value } )
229
+ setNewProject ( { ...newProject , github_link : e . target . value } )
234
230
}
235
231
/>
236
232
</ Field >
@@ -248,9 +244,12 @@ const ShareAProject = () => {
248
244
backgroundColor = "rgba(255, 255, 255, 0.16)"
249
245
placeholder = "Enter your Live Demo URL (Optional)"
250
246
borderRadius = "8px"
251
- value = { newProject . liveDemoURL }
247
+ value = { newProject . youtube_video_link }
252
248
onChange = { ( e ) =>
253
- setNewProject ( { ...newProject , liveDemoURL : e . target . value } )
249
+ setNewProject ( {
250
+ ...newProject ,
251
+ youtube_video_link : e . target . value ,
252
+ } )
254
253
}
255
254
/>
256
255
</ Field >
@@ -269,10 +268,10 @@ const ShareAProject = () => {
269
268
placeholder = "Do you have any comments? (Optional)"
270
269
borderRadius = "8px"
271
270
border = "2px solid white"
272
- value = { newProject . comments }
271
+ /* value={newProject.comments}
273
272
onChange={(e) =>
274
273
setNewProject({ ...newProject, comments: e.target.value })
275
- }
274
+ }*/
276
275
/>
277
276
< Button className = "sp-button" variant = "solid" type = "submit" >
278
277
SUBMIT PROJECT
0 commit comments