Skip to content

Commit

Permalink
request changes as I had
Browse files Browse the repository at this point in the history
  • Loading branch information
Balsam-Faysal committed Aug 16, 2018
1 parent d3a8066 commit b1f4de5
Showing 1 changed file with 38 additions and 60 deletions.
98 changes: 38 additions & 60 deletions client/src/pages/customer-pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Home extends Component {
};

closeModal = () => {
const { textInputValuepPhone } = this.state;
const { textInputValuepPhone, textInputValueFlightNo } = this.state;
if (textInputValuepPhone !== "") {
const data = JSON.stringify({
textInputValuepPhone
Expand All @@ -56,6 +56,9 @@ class Home extends Component {
.then(response => response.json(data))
.then(data => {
if (data.isAvailable) {
if (textInputValueFlightNo !== "") {
this.goToFlight();
}
this.setState({ modalIsOpen: false });
} else {
this.invalidFlightNoAlert("Invalied Phone no.!");
Expand Down Expand Up @@ -110,6 +113,39 @@ class Home extends Component {
});
}

goToFlight = () => {
const { textInputValueFlightNo } = this.state;
const data = JSON.stringify({
textInputValueFlightNo
});
fetch("/api/v1/check_flight", {
credentials: "same-origin",
headers: {
"content-type": "application/json"
},
method: "POST",
body: data
})
.then(response => response.json(data))
.then(data => {
sessionStorage.setItem("flight_no", data.flight_no);
if (data.isAvailable) {
this.setState({
isAvailable: true
});
data.isAvailable && (window.location = "/flightinfo");
} else {
this.setState({
isAvailable: false
});
this.invalidFlightNoAlert("Invalied Flight no.!");
}
})
.catch(err => {
console.log("There has been an error ", err);
});
};

handleCheck = e => {
e.preventDefault();
const {
Expand All @@ -120,35 +156,7 @@ class Home extends Component {

if (checkboxValue === false) {
if (textInputValueFlightNo !== "") {
const data = JSON.stringify({
textInputValueFlightNo
});
fetch("/api/v1/check_flight", {
credentials: "same-origin",
headers: {
"content-type": "application/json"
},
method: "POST",
body: data
})
.then(response => response.json(data))
.then(data => {
sessionStorage.setItem("flight_no", data.flight_no);
if (data.isAvailable) {
this.setState({
isAvailable: true
});
data.isAvailable && (window.location = "/flightinfo");
} else {
this.setState({
isAvailable: false
});
this.invalidFlightNoAlert("Invalied Flight no.!");
}
})
.catch(err => {
console.log("There has been an error ", err);
});
this.goToFlight();
} else {
this.invalidFlightNoAlert("Invalied Flight no.!");
}
Expand All @@ -171,35 +179,6 @@ class Home extends Component {
.then(data => {
if (data.isAvailable) {
if (textInputValueFlightNo !== "") {
const data = JSON.stringify({
textInputValueFlightNo
});
fetch("/api/v1/check_flight", {
credentials: "same-origin",
headers: {
"content-type": "application/json"
},
method: "POST",
body: data
})
.then(response => response.json(data))
.then(data => {
sessionStorage.setItem("flight_no", data.flight_no);
if (data.isAvailable) {
this.setState({
isAvailable: true
});
data.isAvailable && (window.location = "/flightinfo");
} else {
this.setState({
isAvailable: false
});
this.invalidFlightNoAlert("Invalied Flight no.!");
}
})
.catch(err => {
console.log("There has been an error ", err);
});
} else {
this.invalidFlightNoAlert("Invalied Flight no.!");
}
Expand All @@ -223,7 +202,6 @@ class Home extends Component {
labelText="Your flight date"
placeholder="Day DD/MM/Year"
type="date"
onChange={this.handledateInputChange}
/>
<Input
labelClassName="customer-label-style"
Expand Down

0 comments on commit b1f4de5

Please sign in to comment.