-
-
Save blackjmxx/20b7c19207e0879c690c0f29e2b9314d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state = { | |
departure: undefined, | |
pickUpLocation: undefined, | |
pickUpDate: new Date(), | |
availableSeatCount: 0, | |
pricePerSeat: 0, | |
travels:[], | |
showCalendarModal: false, | |
isLoading:false | |
}; | |
handleForm = () => { | |
const { | |
destination, | |
pickUpLocation, | |
pickUpDate, | |
availableSeatCount, | |
} = this.state; | |
const travels = []; | |
this.setState({isLoading:true}) | |
let destinationP = fetch( | |
`http://localhost:2020/extended-api/accounts?asset=destination&contains=${destination}` | |
); | |
let pickUpLocationP = fetch( | |
`http://localhost:2020/extended-api/accounts?asset=pickUpLocation&contains=${pickUpLocation}` | |
); | |
let pickUpDateP = fetch( | |
`http://localhost:2020/extended-api/accounts?asset=pickUpDate&contains=${pickUpDate}` | |
); | |
var search = { | |
availableSeatCount, | |
pickUpDate, | |
pickUpLocation, | |
destination | |
}; | |
Promise.all([ | |
destinationP, | |
pickUpLocationP, | |
pickUpDateP, | |
]) | |
.then((values) => { | |
let promises = []; | |
values.forEach((value) => { | |
promises.push(value.json()); | |
}); | |
Promise.all(promises).then((values) => { | |
values.forEach((value) => { | |
console.log(value); | |
value.data.forEach((v) => travels.push({travelId:v.id, carId:v.carId,...v.asset})); | |
}); | |
const filter = {pickUpDate, pickUpLocation, destination} | |
let results = travels.filter(function(item) { | |
for (var key in filter) { | |
if (item[key] === undefined || item[key] !== filter[key]) | |
return false; | |
} | |
return true; | |
}); | |
this.setState({isLoading:false}) | |
let uniquResult = _.uniqBy(results, 'travelId'); | |
this.props.updateTravels({travels:uniquResult, search}) | |
this.props.history.push("/home/results"); | |
}); | |
}) | |
.catch((reason) => { | |
this.setState({isLoading:false}) | |
console.log(reason); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment