@@ -11,21 +11,21 @@ function CreateClub() {
1111 name : "" ,
1212 address : "" ,
1313 district : "" ,
14- image : null ,
15- schedule : JSON . stringify ( {
16- "monday-friday" : {
17- init : "8" ,
18- end : "22"
19- } ,
20- saturday : {
21- init : "8" ,
22- end : "22"
23- } ,
24- sunday : {
25- init : "8" ,
26- end : "22"
27- }
28- } )
14+ image : null
15+ } ) ;
16+ const [ schedule , setSchedule ] = React . useState ( {
17+ "monday-friday" : {
18+ init : 0 ,
19+ end : 0
20+ } ,
21+ saturday : {
22+ init : 0 ,
23+ end : 0
24+ } ,
25+ sunday : {
26+ init : 0 ,
27+ end : 0
28+ }
2929 } ) ;
3030 const [ error , setError ] = React . useState ( null ) ;
3131
@@ -37,6 +37,14 @@ function CreateClub() {
3737 }
3838 }
3939
40+ function handleChangeSchedule ( e ) {
41+ const [ day , time ] = e . target . name . split ( "." ) ;
42+ setSchedule ( {
43+ ...schedule ,
44+ [ day ] : { ...schedule [ day ] , [ time ] : e . target . value }
45+ } ) ;
46+ }
47+
4048 async function handleSubmit ( e ) {
4149 e . preventDefault ( ) ;
4250 const formData = new FormData ( ) ;
@@ -46,9 +54,15 @@ function CreateClub() {
4654 const { results } = await getCoords (
4755 `${ fields . address } , ${ fields . district } `
4856 ) ;
49- formData . append ( "latitude" , results [ 0 ] . geometry . lat ) ;
50- formData . append ( "longitude" , results [ 0 ] . geometry . lng ) ;
51-
57+ formData . append (
58+ "latitude" ,
59+ results . length ? results [ 0 ] . geometry . lat : null
60+ ) ;
61+ formData . append (
62+ "longitude" ,
63+ results . length ? results [ 0 ] . geometry . lng : null
64+ ) ;
65+ formData . append ( "schedule" , JSON . stringify ( schedule ) ) ;
5266 try {
5367 await postClub ( formData ) ;
5468 navigate ( "/owner" ) ;
@@ -119,14 +133,76 @@ function CreateClub() {
119133 />
120134 </ div >
121135 < div css = { { marginTop : "2em" } } >
122- < Label htmlFor = "schedule" > Schedule</ Label >
123- < Input
124- id = "schedule"
125- name = "schedule"
126- type = "text"
127- value = { fields . schedule }
128- onChange = { handleChange }
129- />
136+ < Label > Schedule</ Label >
137+
138+ < div css = { { display : "flex" , justifyContent : "space-between" } } >
139+ < Label htmlFor = "monday-friday.init" css = { { fontSize : "12px" } } >
140+ Monday - Friday
141+ </ Label >
142+ < div >
143+ < input
144+ id = "monday-friday.init"
145+ name = "monday-friday.init"
146+ type = "time"
147+ step = "3600"
148+ onChange = { handleChangeSchedule }
149+ />
150+ < input
151+ id = "monday-friday.end"
152+ name = "monday-friday.end"
153+ type = "time"
154+ step = "3600"
155+ onChange = { handleChangeSchedule }
156+ />
157+ </ div >
158+ </ div >
159+
160+ < div css = { { display : "flex" , justifyContent : "space-between" } } >
161+ < Label
162+ htmlFor = "schedule-saturdays-start"
163+ css = { { fontSize : "12px" } }
164+ >
165+ Saturday
166+ </ Label >
167+ < div >
168+ < input
169+ id = "saturday.init"
170+ name = "saturday.init"
171+ type = "time"
172+ step = "3600"
173+ onChange = { handleChangeSchedule }
174+ />
175+ < input
176+ id = "saturday.end"
177+ name = "saturday.end"
178+ type = "time"
179+ step = "3600"
180+ onChange = { handleChangeSchedule }
181+ />
182+ </ div >
183+ </ div >
184+
185+ < div css = { { display : "flex" , justifyContent : "space-between" } } >
186+ < Label htmlFor = "schedule-sundays-start" css = { { fontSize : "12px" } } >
187+ Sunday
188+ </ Label >
189+ < div >
190+ < input
191+ id = "sunday.init"
192+ name = "sunday.init"
193+ type = "time"
194+ step = "3600"
195+ onChange = { handleChangeSchedule }
196+ />
197+ < input
198+ id = "sunday.end"
199+ name = "sunday.end"
200+ type = "time"
201+ step = "3600"
202+ onChange = { handleChangeSchedule }
203+ />
204+ </ div >
205+ </ div >
130206 </ div >
131207 < div css = { { marginTop : "2em" } } >
132208 < Button > Create</ Button >
0 commit comments