snt-voting/app/components/flow/LearnAboutBallots.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-10-16 16:20:54 -04:00
import {Link} from "react-router-dom";
import Button from '@material-ui/core/Button';
2018-10-18 16:10:48 -04:00
import React, {Component, Fragment} from 'react';
2018-10-16 16:20:54 -04:00
import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
import DialogTitle from '@material-ui/core/DialogTitle';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
class LearnAboutBallots extends Component {
state = {
open: false,
dialogTitle: '',
dialogText: ''
2018-10-16 16:20:54 -04:00
};
handleClickOpen = (dialogTitle, dialogText) => {
2018-10-16 16:20:54 -04:00
this.setState({
open: true,
dialogTitle,
dialogText
2018-10-16 16:20:54 -04:00
});
};
handleClose = value => {
this.setState({ open: false });
};
render(){
const {polls, idPoll} = this.props;
if(!polls || !polls.length) return null;
2018-10-29 02:51:25 -04:00
const poll = polls[polls.length - 1];
const title = poll.content.title;
const ballots = poll.content.ballots;
2018-10-18 16:10:48 -04:00
return (<Fragment>
<div className="section">
<Typography variant="headline">{title}</Typography>
2018-10-16 16:20:54 -04:00
<BallotDialog
title={this.state.dialogTitle}
text={this.state.dialogText}
2018-10-16 16:20:54 -04:00
open={this.state.open}
onClose={this.handleClose}
/>
{
ballots.map((item, i) => {
return <Card key={i} className="card">
2018-10-18 16:10:48 -04:00
<CardContent className="ballotData">
<Typography gutterBottom component="h2">{item.title}</Typography>
<Typography component="p">{item.subtitle}</Typography>
</CardContent>
2018-10-18 16:10:48 -04:00
<CardActions className="actionArea">
<Button size="small" color="primary" onClick={() => this.handleClickOpen(item.title, item.content)}>Learn more</Button>
</CardActions>
</Card>
})
}
2018-10-16 16:20:54 -04:00
</div>
2018-10-18 16:10:48 -04:00
<div className="buttonNav">
<Link to={"/votingHelp/" + idPoll}><Button className="nextAction">How voting works</Button></Link>
2018-10-18 16:10:48 -04:00
</div>
</Fragment>
2018-10-16 16:20:54 -04:00
);
}
}
class BallotDialog extends Component {
handleClose = () => {
this.props.onClose(this.props.selectedValue);
};
handleListItemClick = value => {
this.props.onClose(value);
};
render() {
const { onClose, title, text, polls, ...other } = this.props;
2018-10-16 16:20:54 -04:00
return (
<Dialog onClose={this.handleClose} aria-labelledby="simple-dialog-title" {...other}>
<DialogTitle>{title}</DialogTitle>
2018-10-16 16:20:54 -04:00
<DialogContent>
<Typography variant="body1" component="div">{text}</Typography>
2018-10-16 16:20:54 -04:00
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary" autoFocus>Ok</Button>
</DialogActions>
</Dialog>
);
}
}
export default LearnAboutBallots;