Skip to content

Instantly share code, notes, and snippets.

View aghh1504's full-sized avatar

Agata aghh1504

  • Festicket
  • London
View GitHub Profile
state = {
msg: '',
showMsg: false,
isModalOpen: false,
from: this.props.flight.from,
to: this.props.flight.to,
noBooking: this.props.flight.noBooking,
};
<button onClick={() => update(flight.noBooking)} > Edit </button>
<Flights
flights={this.state.flights}
onDeleteFlight={this.onDeleteFlight}
update={this.update}
showMsg={this.state.showMsg}
msg={this.state.msg}
/>
update = noBooking => {
const flight = this.state.flights.find(flight => flight.noBooking === noBooking)
this.setState({ editModal: !this.state.editModal, flight: flight });
};
onSubmit = e => {
this.onEditFlight(e);
this.setState(() => ({ isModalOpen: !this.state.isModalOpen }));
};
<form onSubmit={this.onSubmit}>
<input type="text" name="from" value={from} onChange={this.onChange}/>
<input type="text" name="to" value={to} onChange={this.onChange}/>
<input type="text" name="noBooking" value={noBooking} onChange={this.onChange}/>
<button type="submit">Submit</button>
</form>
openEditModale = noBooking => {
const flight = this.state.flights.find(flight => flight.noBooking === noBooking)
this.setState({ editModal: !this.state.editModal, flight: flight });
};
app.post('/flights/editFlight/', function(req, res) {
const newItem = req.body.flights;
savedItems = [newItem, ...savedItems];
updateItems(res);
if (newItem) {
res.send(savedItems);
}
});
onEditFlight = e => {
e.preventDefault();
const { from, to, noBooking } = e.target;
const flights = {
from: from.value,
to: to.value,
noBooking: noBooking.value,
};
const updateItems = res => {
fs.writeFile(reqPath, JSON.stringify(savedItems), 'utf8', function(err) {
if (err) {
console.log(err);
}
});
};
app.post('/flights/remove', function(req, res) {
savedItems = savedItems.filter(item => item.noBooking !== req.body.noBooking);