Skip to content
Snippets Groups Projects
Commit 79114c98 authored by Joni Laukka's avatar Joni Laukka
Browse files

Confirmations to notification form, game state buttons and edit game leaving

parent faaef841
No related branches found
No related tags found
3 merge requests!46Development to testing,!41Notifications + small updates,!39Notification view
...@@ -30,7 +30,8 @@ export default class EditGameForm extends React.Component { ...@@ -30,7 +30,8 @@ export default class EditGameForm extends React.Component {
objectivePoints: [], objectivePoints: [],
capture_time: 300, capture_time: 300,
confirmation_time: 60, confirmation_time: 60,
displayColorPicker: false displayColorPicker: false,
saved: false
}; };
this.handleMapDrag = this.handleMapDrag.bind(this); this.handleMapDrag = this.handleMapDrag.bind(this);
...@@ -185,7 +186,12 @@ export default class EditGameForm extends React.Component { ...@@ -185,7 +186,12 @@ export default class EditGameForm extends React.Component {
// show/hide this form // show/hide this form
handleView = e => { handleView = e => {
this.props.toggleView(this.props.view); if (
this.state.saved ||
window.confirm("Are you sure you want to leave without saving?")
) {
this.props.toggleView(this.props.view);
}
}; };
// remove view with ESC // remove view with ESC
...@@ -248,6 +254,7 @@ export default class EditGameForm extends React.Component { ...@@ -248,6 +254,7 @@ export default class EditGameForm extends React.Component {
} }
let token = sessionStorage.getItem("token"); let token = sessionStorage.getItem("token");
let error = false;
// Send Game info to the server // Send Game info to the server
fetch(`${process.env.REACT_APP_API_URL}/game/edit/${this.props.gameId}`, { fetch(`${process.env.REACT_APP_API_URL}/game/edit/${this.props.gameId}`, {
...@@ -261,15 +268,23 @@ export default class EditGameForm extends React.Component { ...@@ -261,15 +268,23 @@ export default class EditGameForm extends React.Component {
}) })
.then(res => { .then(res => {
if (!res.ok) { if (!res.ok) {
throw Error(res.statusMessage); error = true;
} else {
return res.json();
} }
return res.json();
}) })
.then(result => { .then(result => {
alert(result.message); alert(result.message);
this.props.onEditSave(); if (!error) {
this.handleView(); this.setState(
{
saved: true
},
() => {
this.handleView();
this.props.onEditSave();
}
);
}
}) })
.catch(error => console.log("Error: ", error)); .catch(error => console.log("Error: ", error));
}; };
......
...@@ -6,39 +6,42 @@ export default class GameStateButtons extends React.Component { ...@@ -6,39 +6,42 @@ export default class GameStateButtons extends React.Component {
}; };
setGameState(state) { setGameState(state) {
console.log(state); if (
let token = sessionStorage.getItem("token"); window.confirm(`Are you sure you want to change game state to ${state}?`)
let error = false; ) {
fetch( let token = sessionStorage.getItem("token");
`${process.env.REACT_APP_API_URL}/game/edit-state/${this.props.gameId}`, let error = false;
{ fetch(
method: "PUT", `${process.env.REACT_APP_API_URL}/game/edit-state/${this.props.gameId}`,
headers: { {
Authorization: "Bearer " + token, method: "PUT",
Accept: "application/json", headers: {
"Content-Type": "application/json" Authorization: "Bearer " + token,
}, Accept: "application/json",
body: JSON.stringify({ "Content-Type": "application/json"
id: this.props.gameId, },
state: state body: JSON.stringify({
}) id: this.props.gameId,
} state: state
) })
.then(res => {
if (!res.ok) {
error = true;
}
return res.json();
})
.then(res => {
if (error) {
console.log(res);
} else {
alert(`Game state changed to ${state}`);
this.setState({ gameState: state });
} }
}) )
.catch(error => console.log(error)); .then(res => {
if (!res.ok) {
error = true;
}
return res.json();
})
.then(res => {
if (error) {
console.log(res);
} else {
alert(`Game state changed to ${state}`);
this.setState({ gameState: state });
}
})
.catch(error => console.log(error));
}
} }
render() { render() {
......
...@@ -30,12 +30,15 @@ export default class NotificationView extends React.Component { ...@@ -30,12 +30,15 @@ export default class NotificationView extends React.Component {
if (this.state.notificationInput === "") { if (this.state.notificationInput === "") {
alert("notification message can't be empty"); alert("notification message can't be empty");
} else { } else if (
window.confirm("Are you sure you want to send the notification")
) {
this.props.socket.emit("game-info", { this.props.socket.emit("game-info", {
type: this.state.notificationTypeInput, type: this.state.notificationTypeInput,
message: this.state.notificationInput, message: this.state.notificationInput,
game: this.props.gameId game: this.props.gameId
}); });
alert("Notification sent");
this.getNotifications(this.props.gameId); this.getNotifications(this.props.gameId);
this.setState({ notificationInput: "" }); this.setState({ notificationInput: "" });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment