Skip to content

Commit

Permalink
Ordini a domicilio ultimati, con bottoni
Browse files Browse the repository at this point in the history
  • Loading branch information
ikros98 committed Jan 6, 2020
1 parent 9122e8b commit fd51384
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import OrdersHistory from "./Components/OrdersHistory";
import Order from "./Components/Order";
import Reservation from "./Components/Reservation";
import RestaurantHome from "./Components/RestaurantHome";
// import RestOrder from "./Components/RestOrder";
import RestOrder from "./Components/RestOrder";


class App extends React.Component {
Expand Down Expand Up @@ -50,9 +50,9 @@ class App extends React.Component {
<Route path="/Order">
<Order />
</Route>
{/* <Route path="/RestOrder">
<Route path="/RestOrder">
<RestOrder />
</Route> */}
</Route>
<Route path="/Reservation">
<Reservation />
</Route>
Expand Down
60 changes: 46 additions & 14 deletions src/Components/RestOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import MenuEntryOrder from "./MenuEntryOrder";
class RestOrder extends React.Component {
constructor(props) {
super(props);
console.debug("Order", "constructor");
console.debug("RestOrder", "constructor");
this.provider = new DataProvider();
this.state = {
id: "id",
Expand All @@ -37,7 +37,7 @@ class RestOrder extends React.Component {
}

componentDidMount() {
console.debug("Order", "componentDidMount");
console.debug("RestOrder", "componentDidMount");
this.provider.getRestBookedOrder().then(response => {
console.log(response);
this.setState({
Expand All @@ -58,6 +58,18 @@ class RestOrder extends React.Component {
});
}

handleOrder(stato, id) {
sessionStorage.setItem("id", id);
if (stato == "in elaborazione")
this.provider.doAcceptOrder();
else if(stato == "accettato dal ristorante")
this.provider.doShipOrder();
else if(stato == "in consegna")
this.provider.doCompleteOrder();
else
this.provider.doCancelOrder();
}

render() {
console.debug("Order", "render");
return (
Expand Down Expand Up @@ -97,19 +109,39 @@ class RestOrder extends React.Component {




{(this.state.stato == "in elaborazione") ? (
<View style={styles.buttonRow}>
<Button text={"Accetta ordine"}
onPress={() => this.handleOrder(this.state.stato, this.state.id)}/>
</View>
): ((this.state.stato == "accettato dal ristorante") ? (
<View style={styles.buttonRow}>
<Button text={"In consegna"}
onPress={() => this.handleOrder(this.state.stato, this.state.id)}
/>
</View>
): ((this.state.stato == "in consegna") ? (
<View style={styles.buttonRow}>
<Button text={"Completato"}
onPress={() => this.handleOrder(this.state.stato, this.state.id)}

/>
</View>
): (null)
))}

{((this.state.stato != "completato") && (this.state.stato != "cancellato")) ? (
<View style={styles.buttonRow}>
<Button text={"Cancella"}
onPress={() => this.handleOrder("cancellato", this.state.id)}
/>
</View>
): (null)
}



<View style={styles.buttonRow}>
<Button text={"In elaborazione"} />
</View>
<View style={styles.buttonRow}>
<Button text={"In consegna"} />
</View>
<View style={styles.buttonRow}>
<Button text={"Completato"} />
</View>
<View style={styles.buttonRow}>
<Button text={"Cancella"} />
</View>



Expand Down
104 changes: 104 additions & 0 deletions src/DataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,110 @@ class DataProvider {
});
}

doAcceptOrder() {
const data = {
token: this.token,
ordine: {
id: sessionStorage.getItem("id")
},
orario: ""
};

return new Promise((resolve, reject) => {
this.doPost("ristorante/ordini/accept", data)
.then(response => {
if (response != null) {
resolve(response);
window.location.href = "RestOrder";
} else {
reject("NoResult");
}
})
.catch(error => {
console.error(error);
reject("FailedToFetch");
});
});
}

doCancelOrder() {
const data = {
token: this.token,
ordine: {
id: sessionStorage.getItem("id")
}
};

return new Promise((resolve, reject) => {
this.doPost("ristorante/ordini/delete", data)
.then(response => {
if (response != null) {
resolve(response);
//window.location.href = "RestOrder";
console.log(response.value);
} else {
reject("NoResult");
}
})
.catch(error => {
console.error(error);
reject("FailedToFetch");
});
});
}

doShipOrder() {
const data = {
token: this.token,
ordine: {
id: sessionStorage.getItem("id")
},
orario: "2020-01-07T14:00:00"
};

return new Promise((resolve, reject) => {
this.doPost("ristorante/ordini/delivery", data)
.then(response => {
if (response != null) {
resolve(response);
window.location.href = "RestOrder";
} else {
reject("NoResult");
}
})
.catch(error => {
console.error(error);
reject("FailedToFetch");
});
});
}

doCompleteOrder() {
const data = {
token: this.token,
ordine: {
id: sessionStorage.getItem("id")
},
orario: "2020-01-07T14:00:00"
};

return new Promise((resolve, reject) => {
this.doPost("ristorante/ordini/complete", data)
.then(response => {
if (response != null) {
resolve(response);
window.location.href = "RestOrder";
} else {
reject("NoResult");
}
})
.catch(error => {
console.error(error);
reject("FailedToFetch");
});
});
}

getAllOrders() {
const data = {
value: this.token
Expand Down

0 comments on commit fd51384

Please sign in to comment.