1
- import '../css/UploadProject.css'
2
- import PropTypes from 'prop-types' ;
3
- import AddProject from './AddProject' ;
1
+ import React , { useState } from 'react' ;
2
+ import PropTypes from "prop-types" ;
3
+ import { useNavigate } from 'react-router-dom' ;
4
+
5
+
6
+ const UploadProject = ( { mode } ) => {
7
+ const navigate = useNavigate ( ) ;
8
+ const [ formData , setFormData ] = useState ( {
9
+ title : '' ,
10
+ description : '' ,
11
+ githubLink : '' ,
12
+ deploymentLink : '' ,
13
+ projectFiles : null ,
14
+ } ) ;
15
+
16
+ const handleChange = ( e ) => {
17
+ const { name, value, type, files } = e . target ;
18
+ if ( type === 'file' ) {
19
+ setFormData ( ( prevData ) => ( {
20
+ ...prevData ,
21
+ [ name ] : files [ 0 ] ,
22
+ } ) ) ;
23
+ } else {
24
+ setFormData ( ( prevData ) => ( {
25
+ ...prevData ,
26
+ [ name ] : value ,
27
+ } ) ) ;
28
+ }
29
+ } ;
30
+
31
+ const handleSubmit = async ( e ) => {
32
+ e . preventDefault ( ) ;
33
+
34
+ try {
35
+ const response = await fetch ( 'http://localhost:5000/api/showcaseProjects/post-project' , {
36
+ method : 'POST' ,
37
+ headers : {
38
+ 'Content-Type' : 'application/json' ,
39
+ } ,
40
+ body : JSON . stringify ( formData ) ,
41
+ } ) ;
42
+
43
+ if ( ! response . ok ) {
44
+ throw new Error ( 'Failed to submit project' ) ;
45
+ }
46
+
47
+ const data = await response . json ( ) ;
48
+ console . log ( 'Project submitted successfully:' , data ) ;
49
+ navigate ( '/projects' ) ;
50
+
51
+ // Clear the form after submission
52
+ setFormData ( {
53
+ title : '' ,
54
+ description : '' ,
55
+ githubLink : '' ,
56
+ deploymentLink : '' ,
57
+ } ) ;
58
+
59
+ // Optionally, you can redirect the user or display a success message
60
+ } catch ( error ) {
61
+ console . error ( 'Error submitting project:' , error ) ;
62
+ }
63
+ } ;
64
+
65
+ const themeStyles = mode === 'dark' ? 'bg-gray-800 text-white' : 'bg-white text-gray-900' ;
4
66
5
- function UploadProject ( props ) {
6
67
return (
7
- < div >
8
- < div className = "container" >
68
+ < div className = { `container mx-auto p-6 mt-40 mb-12 max-w-3xl shadow-lg rounded-lg ${ themeStyles } ` } >
69
+ < h1 className = { `text-4xl font-bold text-center mb-8 ${ mode === 'dark' ? 'text-white' : 'text-gray-900' } ` } >
70
+ Upload Your Project
71
+ </ h1 >
72
+
73
+ < form onSubmit = { handleSubmit } className = "space-y-6" >
74
+ { /* Project Title */ }
75
+ < div >
76
+ < label htmlFor = "title" className = { `block text-lg font-medium ${ mode === 'dark' ? 'text-gray-300' : 'text-gray-700' } ` } >
77
+ Project Title
78
+ </ label >
79
+ < input
80
+ type = "text"
81
+ id = "title"
82
+ name = "title"
83
+ value = { formData . title }
84
+ onChange = { handleChange }
85
+ className = { `w-full mt-2 p-3 border rounded-md focus:ring-2 focus:ring-blue-500 focus:outline-none ${ mode === 'dark' ? 'bg-gray-700 text-white border-gray-600' : 'bg-white text-gray-900 border-gray-300' } ` }
86
+ placeholder = "Enter your project title"
87
+ required
88
+ />
89
+ </ div >
90
+
91
+ { /* Project Description */ }
92
+ < div >
93
+ < label htmlFor = "description" className = { `block text-lg font-medium ${ mode === 'dark' ? 'text-gray-300' : 'text-gray-700' } ` } >
94
+ Project Description
95
+ </ label >
96
+ < textarea
97
+ id = "description"
98
+ name = "description"
99
+ value = { formData . description }
100
+ onChange = { handleChange }
101
+ className = { `w-full mt-2 p-3 border rounded-md focus:ring-2 focus:ring-blue-500 focus:outline-none ${ mode === 'dark' ? 'bg-gray-700 text-white border-gray-600' : 'bg-white text-gray-900 border-gray-300' } ` }
102
+ placeholder = "Enter a brief description of your project"
103
+ rows = "4"
104
+ required
105
+ > </ textarea >
106
+ </ div >
107
+
108
+ { /* GitHub Link */ }
109
+ < div >
110
+ < label htmlFor = "githubLink" className = { `block text-lg font-medium ${ mode === 'dark' ? 'text-gray-300' : 'text-gray-700' } ` } >
111
+ GitHub Link
112
+ </ label >
113
+ < input
114
+ type = "url"
115
+ id = "githubLink"
116
+ name = "githubLink"
117
+ value = { formData . githubLink }
118
+ onChange = { handleChange }
119
+ className = { `w-full mt-2 p-3 border rounded-md focus:ring-2 focus:ring-blue-500 focus:outline-none ${ mode === 'dark' ? 'bg-gray-700 text-white border-gray-600' : 'bg-white text-gray-900 border-gray-300' } ` }
120
+ placeholder = "Enter your project GitHub link"
121
+ required
122
+ />
123
+ </ div >
124
+
125
+ { /* Deployment Link */ }
126
+ < div >
127
+ < label htmlFor = "deploymentLink" className = { `block text-lg font-medium ${ mode === 'dark' ? 'text-gray-300' : 'text-gray-700' } ` } >
128
+ Deployment Link (Optional)
129
+ </ label >
130
+ < input
131
+ type = "url"
132
+ id = "deploymentLink"
133
+ name = "deploymentLink"
134
+ value = { formData . deploymentLink }
135
+ onChange = { handleChange }
136
+ className = { `w-full mt-2 p-3 border rounded-md focus:ring-2 focus:ring-blue-500 focus:outline-none ${ mode === 'dark' ? 'bg-gray-700 text-white border-gray-600' : 'bg-white text-gray-900 border-gray-300' } ` }
137
+ placeholder = "Enter your project live demo link"
138
+ />
139
+ </ div >
140
+
141
+
142
+
143
+ { /* Submit Button */ }
9
144
< div className = "text-center" >
10
- < div className = "body" >
11
- < h5 className = "text-xl font-bold text-blue-500 mb-8" > { props . title } < strong > 👇</ strong > </ h5 >
12
- < AddProject showAlert = { props . showAlert } />
13
- </ div >
145
+ < button
146
+ type = "submit"
147
+ className = { `w-full py-3 rounded-md text-lg font-semibold ${ mode === 'dark' ? 'bg-blue-700 hover:bg-blue-600' : 'bg-blue-600 hover:bg-blue-700' } text-white focus:outline-none focus:ring-2 focus:ring-blue-400` }
148
+ >
149
+ Upload Project
150
+ </ button >
14
151
</ div >
15
- </ div >
152
+ </ form >
16
153
</ div >
17
- )
18
- }
154
+ ) ;
155
+ } ;
19
156
20
- // Props Vadilation
21
157
UploadProject . propTypes = {
22
- title : PropTypes . string ,
23
- desc : PropTypes . string ,
24
- showAlert : PropTypes . func ,
158
+
159
+ mode : PropTypes . string ,
160
+
25
161
} ;
26
162
27
- export default UploadProject
163
+ export default UploadProject ;
0 commit comments