1
1
import React from 'react' ;
2
2
import { NavLink } from "react-router-dom" ;
3
3
import moment from 'moment' ;
4
+ import { Redirect } from 'react-router-dom' ;
4
5
5
6
class SearchForm extends React . Component {
6
7
@@ -125,15 +126,30 @@ class SearchForm extends React.Component {
125
126
126
127
this . slideToggle = this . slideToggle ;
127
128
this . $el . slideToggle ( 'fast' , this . handleClick ) ;
128
-
129
+
129
130
}
130
131
131
132
componentWillUnmount ( ) {
132
133
this . $el . off ( 'change' , this . handleChange ) ;
133
134
this . $el . off ( 'click' , this . handleClick ) ;
134
135
}
135
136
137
+ constructor ( ) {
138
+ super ( ) ;
139
+ this . state = {
140
+ fireRedirect : false
141
+ }
142
+ }
143
+
144
+ submitForm = ( e ) => {
145
+ e . preventDefault ( )
146
+ this . setState ( { fireRedirect : true } )
147
+ }
148
+
136
149
render ( ) {
150
+
151
+ const { fireRedirect } = this . state ;
152
+
137
153
return (
138
154
< section className = "train-section" >
139
155
< div id = "search-form" className = "container pb-1" >
@@ -183,7 +199,12 @@ class SearchForm extends React.Component {
183
199
< div className = "tab-pane fade" id = "flight" role = "tabpanel" aria-labelledby = "flight-tab" >
184
200
< div className = "bg-light" >
185
201
< h2 className = "text-4 mb-3" > Book Domestic and International Flights</ h2 >
186
- < form id = "bookingFlight" method = "post" >
202
+ < form
203
+ id = "bookingFlight"
204
+ method = "post"
205
+ onSubmit = { this . submitForm }
206
+ >
207
+ { fireRedirect && ( < Redirect to = { '/available' } /> ) }
187
208
< div className = "mb-3" >
188
209
< div className = "custom-control custom-radio custom-control-inline" >
189
210
< input id = "oneway" name = "flight-trip" className = "custom-control-input" defaultChecked required type = "radio" />
@@ -325,7 +346,12 @@ class SearchForm extends React.Component {
325
346
< div className = "tab-pane fade" id = "hotel" role = "tabpanel" aria-labelledby = "hotel-tab" >
326
347
< div className = "bg-light" >
327
348
< h2 className = "text-4 mb-3" > Book Domestic and International Hotels</ h2 >
328
- < form id = "bookingHotels" method = "post" >
349
+ < form
350
+ id = "bookingHotels"
351
+ method = "post"
352
+ onSubmit = { this . submitForm }
353
+ >
354
+ { fireRedirect && ( < Redirect to = { '/available' } /> ) }
329
355
< div className = "form-row" >
330
356
< div className = "col-md-12 col-lg-6 form-group" >
331
357
< input type = "text" className = "form-control" id = "hotelsFrom" placeholder = "Enter City/Hotel" />
@@ -401,7 +427,7 @@ class SearchForm extends React.Component {
401
427
</ div >
402
428
</ div >
403
429
< div className = "col-md-6 col-lg-6 form-group" >
404
- < button className = "btn btn-search btn-block" type = "submit" > < i className = "fas fa-search" onClick = { ( '/available' ) } /> Search</ button >
430
+ < button className = "btn btn-search btn-block" type = "submit" > < i className = "fas fa-search" /> Search</ button >
405
431
</ div >
406
432
</ div >
407
433
</ form >
@@ -412,7 +438,12 @@ class SearchForm extends React.Component {
412
438
< div className = "tab-pane fade show active" id = "train" role = "tabpanel" aria-labelledby = "train-tab" >
413
439
< div className = "bg-light" >
414
440
< h2 className = "text-4 mb-3" > Book Train Tickets</ h2 >
415
- < form id = "bookingTrain" method = "post" >
441
+ < form
442
+ id = "bookingTrain"
443
+ method = "post"
444
+ onSubmit = { this . submitForm }
445
+ >
446
+ { fireRedirect && ( < Redirect to = { '/available' } /> ) }
416
447
< div className = "mb-3" >
417
448
< div className = "custom-control custom-radio custom-control-inline" >
418
449
< input id = "train-oneway" name = "train-trip" className = "custom-control-input" defaultChecked required type = "radio" />
@@ -425,19 +456,19 @@ class SearchForm extends React.Component {
425
456
</ div >
426
457
< div className = "form-row" >
427
458
< div className = "col-md-6 col-lg-3 form-group" >
428
- < input type = "text" className = "form-control" id = "trainFrom" required placeholder = "From" />
459
+ < input type = "text" className = "form-control" id = "trainFrom" placeholder = "From" />
429
460
< span className = "icon-inside" > < i className = "fas fa-map-marker-alt" /> </ span >
430
461
</ div >
431
462
< div className = "col-md-6 col-lg-3 form-group" >
432
- < input type = "text" className = "form-control" id = "trainTo" required placeholder = "To" />
463
+ < input type = "text" className = "form-control" id = "trainTo" placeholder = "To" />
433
464
< span className = "icon-inside" > < i className = "fas fa-map-marker-alt" /> </ span >
434
465
</ div >
435
466
< div className = "col-md-6 col-lg-3 form-group" >
436
- < input id = "trainsDepart" type = "text" className = "form-control" required placeholder = "Depart Date" />
467
+ < input id = "trainsDepart" type = "text" className = "form-control" placeholder = "Depart Date" />
437
468
< span className = "icon-inside" > < i className = "far fa-calendar-alt" /> </ span >
438
469
</ div >
439
470
< div className = "col-md-6 col-lg-3 form-group" >
440
- < input id = "trainsReturn" type = "text" className = "form-control" required placeholder = "Return Date" />
471
+ < input id = "trainsReturn" type = "text" className = "form-control" placeholder = "Return Date" />
441
472
< span className = "icon-inside" > < i className = "far fa-calendar-alt" /> </ span >
442
473
</ div >
443
474
< div className = "col-md-6 col-lg-6 travellers-class form-group" >
@@ -449,7 +480,7 @@ class SearchForm extends React.Component {
449
480
name = "train-travellers-class"
450
481
placeholder = "Travellers, Class"
451
482
readOnly = ""
452
- required = ""
483
+
453
484
/>
454
485
< span className = "icon-inside" > < i className = "fas fa-caret-down" /> </ span >
455
486
< div className = "travellers-dropdown" >
0 commit comments