Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import React, { useState } from "react";
import errorAlert from "../Helpers/errorAlert";
import isEmpty from 'validator/lib/isEmpty';
const CreateEventForm = () => {
const [errorMsg, setErrorMsg] = useState('')
const [eventData, setEventData] = useState({
eventTitle: "",
organiser: "",
venueName: "",
venueAddress: "",
eventGenre: "",
startDate: "",
endDate: "",
startTime: "",
endTime: "",
ticketPrice: "",
ticketQty: "",
eventImage: null,
eventDescription: "",
});
// Destructuring form data
const {
eventTitle,
organiser,
venueName,
venueAddress,
eventGenre,
startDate,
endDate,
startTime,
endTime,
ticketPrice,
ticketQty,
eventImage,
eventDescription,
} = eventData;
const handleEventImage = (event) => {
console.log(event.target.files[0])
setEventData({
...eventData,
[event.target.name]: event.target.files[0],
})
}
const handleEventChange = (event) => {
setEventData({
...eventData,
[event.target.name]: event.target.value
})
}
const handleEventSubmit = (event) => {
event.preventDefault()
if (eventImage === null) {
setErrorMsg("Image is required")
}
}
return (
<form onSubmit={handleEventSubmit}>
{JSON.stringify(eventData)}
{JSON.stringify(errorMsg)}
<div className="mt-16 mx-20">
<div className="px-2">
<div className="flex -mx-2">
<div className="w-1/2 px-4 ">
<div className="space-y-6">
<h1 className=" text-black font-montserrat font-extrabold text-3xl">
Create event
</h1>
{errorMsg && errorAlert(errorMsg)}
<input
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="eventTitle"
value={eventTitle}
type="text"
placeholder="Event title"
onChange={handleEventChange}
></input>
<input
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="organiser"
value={organiser}
type="text"
placeholder="organiser"
onChange={handleEventChange}
></input>
<input
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="venueName"
value={venueName}
type="text"
placeholder="Venue name"
onChange={handleEventChange}
></input>
<input
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="venueAddress"
value={venueAddress}
type="text"
placeholder="Venue address"
onChange={handleEventChange}
></input>
<select
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="eventGenre"
type="text"
placeholder="Event Genre"
onChange={handleEventChange}
>
<option value="" disabled="disabled">
Pick a genre
</option>
<option value="Hip-hop">Hip-hop</option>
<option value="Rap">Rap</option>
<option value="Rock">Rock</option>
<option value="Grime">Grime</option>
<option value="Pop">Pop</option>
<option value="Electronic">Electronic</option>
<option value="House">House</option>
<option value="Reggae">Reggae</option>
<option value="Indie">Indie</option>
<option value="Dance<">Dance</option>
</select>
<div className="flex space-x-2">
<input
className="font-montserrat font-medium rounded-full w-1/2 py-4 px-7 shadow-lg"
name="startDate"
value={startDate}
type="text"
placeholder="Start date"
onChange={handleEventChange}
></input>
<input
className="font-montserrat font-medium rounded-full w-1/2 py-4 px-7 shadow-lg"
name="endDate"
value={endDate}
type="text"
placeholder="End date"
onChange={handleEventChange}
></input>
</div>
<div className="flex space-x-2">
<input
className="font-montserrat font-medium rounded-full w-1/2 py-4 px-7 shadow-lg"
name="startTime"
value={startTime}
type="text"
placeholder="Start time"
onChange={handleEventChange}
></input>
<input
className="font-montserrat font-medium rounded-full w-1/2 py-4 px-7 shadow-lg"
name="endTime"
value={endTime}
type="text"
placeholder="End time"
onChange={handleEventChange}
></input>
</div>
<input
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="ticketPrice"
value={ticketPrice}
type="text"
placeholder="Ticket price"
onChange={handleEventChange}
></input>
<input
className="font-montserrat font-medium rounded-full w-full py-4 px-7 shadow-lg"
name="ticketQty"
value={ticketQty}
type="number"
min="1"
placeholder="Quantity of tickets"
onChange={handleEventChange}
></input>
</div>
</div>
<div className="w-1/2 px-4">
<div>
<div className="flex justify-center mt-16 ">
<div className="w-full rounded-lg shadow-xl bg-gray-50 ">
<div className="m-6 ">
<div className="flex items-center justify-center w-full ">
<label className="flex flex-col w-full h-32 border-4 border-blue-200 border-dashed hover:bg-gray-100 hover:border-gray-300">
<div className="flex flex-col items-center justify-center pt-7">
<p className="pt-1 font-montserrat font-medium text-sm tracking-wider text-gray-400 group-hover:text-gray-600">
Attach a file
</p>
</div>
<input
type="file"
name="eventImage"
className="custom-file-input opacity-0"
onChange={handleEventImage}
/>
</label>
</div>
</div>
<div className="flex justify-center p-2">
<button className="w-full px-4 py-3 font-montserrat font-medium text-white bg-purple-500 rounded shadow-xl">
Upload event image
</button>
</div>
</div>
</div>
</div>
<div className="py-6">
<textarea
name="eventDescription"
value={eventDescription}
placeholder="Event description"
onChange={handleEventChange}
className="w-full h-48 px-3 py-4 font-montserrat font-medium text-base border rounded-lg focus:shadow-outline"
></textarea>
</div>
<button
className="p-5 px-24 w-full bg-purple-500 hover:bg-purple-400 text-white rounded font-montserrat font-bold"
type="submit"
>
Create event
</button>
</div>
</div>
</div>
</div>
</form>
);
};
export default CreateEventForm;