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
This commit is part of merge request !41. Comments created here will be created in the context of that merge request.
......@@ -30,7 +30,8 @@ export default class EditGameForm extends React.Component {
objectivePoints: [],
capture_time: 300,
confirmation_time: 60,
displayColorPicker: false
displayColorPicker: false,
saved: false
};
this.handleMapDrag = this.handleMapDrag.bind(this);
......@@ -185,7 +186,12 @@ export default class EditGameForm extends React.Component {
// show/hide this form
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
......@@ -248,6 +254,7 @@ export default class EditGameForm extends React.Component {
}
let token = sessionStorage.getItem("token");
let error = false;
// Send Game info to the server
fetch(`${process.env.REACT_APP_API_URL}/game/edit/${this.props.gameId}`, {
......@@ -261,15 +268,23 @@ export default class EditGameForm extends React.Component {
})
.then(res => {
if (!res.ok) {
throw Error(res.statusMessage);
} else {
return res.json();
error = true;
}
return res.json();
})
.then(result => {
alert(result.message);
this.props.onEditSave();
this.handleView();
if (!error) {
this.setState(
{
saved: true
},
() => {
this.handleView();
this.props.onEditSave();
}
);
}
})
.catch(error => console.log("Error: ", error));
};
......
......@@ -6,39 +6,42 @@ export default class GameStateButtons extends React.Component {
};
setGameState(state) {
console.log(state);
let token = sessionStorage.getItem("token");
let error = false;
fetch(
`${process.env.REACT_APP_API_URL}/game/edit-state/${this.props.gameId}`,
{
method: "PUT",
headers: {
Authorization: "Bearer " + token,
Accept: "application/json",
"Content-Type": "application/json"
},
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 });
if (
window.confirm(`Are you sure you want to change game state to ${state}?`)
) {
let token = sessionStorage.getItem("token");
let error = false;
fetch(
`${process.env.REACT_APP_API_URL}/game/edit-state/${this.props.gameId}`,
{
method: "PUT",
headers: {
Authorization: "Bearer " + token,
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
id: this.props.gameId,
state: 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() {
......
......@@ -30,12 +30,15 @@ export default class NotificationView extends React.Component {
if (this.state.notificationInput === "") {
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", {
type: this.state.notificationTypeInput,
message: this.state.notificationInput,
game: this.props.gameId
});
alert("Notification sent");
this.getNotifications(this.props.gameId);
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