Newer
Older
class TaskItem extends React.Component {
constructor(props) {
fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`, {
.then(result => {
if (!result.ok) {
throw Error(result.responseText);
} else {
return result.json();
}
})
.then(result => {
selectedFactionId: result.factions[0].factionId
}
onSaveSubmit = e => {
e.preventDefault();
this.props.onSave(this.props.task, this.state.selectedFactionId);
handleFactionChange = e => {
this.setState({
selectedFactionId: e.target.value
onTaskDelete = e => {
e.preventDefault();
if (
window.confirm(
`Are you sure you want to delete task "${this.props.task.taskName}"`
)
) {
this.props.onDelete(this.props.task.taskId);
this.setState({
edit: false
});
}
let factionlistItems = this.state.factions.map(faction => (
<option key={faction.factionId} value={faction.factionId}>
{faction.factionName}
</option>
));
<label>{this.props.task.taskDescription}</label>
<br />
<label>
Faction:{" "}
{this.props.task.faction !== null
? this.props.task.faction.factionName
: "Every faction"}
</label>
<br />
{this.props.task.taskWinner !== null && (
<label>Winner: {this.props.task.taskWinner.factionName}</label>
{this.props.task.taskIsActive && this.props.role === "admin" && (
<button onClick={() => this.setState({ edit: !this.state.edit })}>
{this.state.edit ? "Cancel" : "Set Winner"}
</button>
<select
value={this.state.selectedFactionId}
onChange={e =>
this.setState({ selectedFactionId: e.target.value })
}
>
</select>
<button type="submit">Save</button>
</form>
{this.props.role === "admin" && (
<button
onClick={this.onTaskDelete}
style={{ backgroundColor: "red" }}
>
Delete
</button>
)}