Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #312 from dotkom/feat/302-admin-issue-conclusion-w…
Browse files Browse the repository at this point in the history
…hen-voting-finished

Feature #302 - Display conclusion of issue to admins before users
  • Loading branch information
sklirg authored Feb 21, 2018
2 parents d483ce9 + 392b5e3 commit c62bd60
Show file tree
Hide file tree
Showing 11 changed files with 895 additions and 200 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Admin/AdminPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Link, Route, Switch } from 'react-router-dom';
import * as OfflinePluginRuntime from 'offline-plugin/runtime';
import { IS_MANAGER } from 'common/auth/permissions';
import { endGAM, toggleRegistration } from 'features/meeting/actionCreators';
import AdminHome from './Home';
import { AdminHomeContainer } from './Home';
import { IssueFormContainer } from './IssueForm';
import Users from './Users';
import Button from '../Button';
Expand Down Expand Up @@ -119,7 +119,7 @@ class AdminPanel extends React.Component {
<Switch>
<Route exact path={`${match.path}/question`} component={IssueFormContainer} />
<Route exact path={`${match.path}/users`} component={Users} />
<Route exact path={match.path} component={AdminHome} />
<Route exact path={match.path} component={AdminHomeContainer} />
<Route component={NotFound} />
</Switch>
</main>
Expand Down
28 changes: 27 additions & 1 deletion client/src/components/Admin/Home.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import DocumentTitle from 'react-document-title';
import { VOTING_FINISHED } from 'common/actionTypes/issues';
import Issue from '../App/Issue';
import { IssueContainer } from './Issue';
import Alternatives from './Alternatives';
import ConcludedIssue from '../ConcludedIssue';
import LatestConcludedIssue from '../LatestConcludedIssue';
import { ConcludedIssueListContainer } from '../ConcludedIssueList';
import UserSettings from '../UserSettings';
import IssueStatus from '../IssueStatus';
import { getIssue } from '../../features/issue/selectors';
import css from '../../css/Home.css';


const AdminHome = () => (
const AdminHome = ({ issue }) => (
<DocumentTitle title="Generalforsamling adminpanel">
<div>
<div className={css.components}>
Expand All @@ -19,6 +25,11 @@ const AdminHome = () => (
</div>
<IssueStatus />
</div>
{(issue && issue.status === VOTING_FINISHED) && <div className={css.latestIssueRemoveMargin}>
<ConcludedIssue
{...issue}
/>
</div>}
<div className={css.components}>
<div className={css.latestIssue}>
<LatestConcludedIssue />
Expand All @@ -30,4 +41,19 @@ const AdminHome = () => (
</DocumentTitle>
);

AdminHome.defaultProps = {
issue: Issue.defaultProps,
};

AdminHome.propTypes = {
issue: PropTypes.shape(Issue.propTypes),
};

const mapStateToProps = state => ({
issue: getIssue(state),
});

export default AdminHome;
export const AdminHomeContainer = connect(
mapStateToProps,
)(AdminHome);
10 changes: 6 additions & 4 deletions client/src/components/ConcludedIssue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import IconText from '../IconText';
import Card from '../Card';
import css from './ConcludedIssue.css';

const ConcludedIssue = ({ winner, voteDemand, text, alternatives, votes, qualifiedVoters }) => {
const ConcludedIssue = ({
winner, voteDemand, text, alternatives, concludedVotes, qualifiedVoters,
}) => {
const majority = winner !== null;
return (<Card
classes={css.concludedIssue}
Expand All @@ -33,7 +35,7 @@ const ConcludedIssue = ({ winner, voteDemand, text, alternatives, votes, qualifi
&& alternative.id === winner,
})}
>
{alternative.text}{ Object.keys(votes).length > 0 && `: ${votes[alternative.id]}` }
{alternative.text}{ Object.keys(concludedVotes).length > 0 && `: ${concludedVotes[alternative.id]}` }
</li>
))}
</ul>
Expand All @@ -42,7 +44,7 @@ const ConcludedIssue = ({ winner, voteDemand, text, alternatives, votes, qualifi

ConcludedIssue.defaultProps = {
alternatives: [],
votes: {},
concludedVotes: {},
voteDemand: RESOLUTION_TYPES.regular.voteDemand,
text: 'Denne saken har ingen tittel.',
winner: null,
Expand All @@ -57,7 +59,7 @@ ConcludedIssue.propTypes = {
text: PropTypes.string.isRequired,
})).isRequired,
qualifiedVoters: PropTypes.number.isRequired,
votes: PropTypes.objectOf(PropTypes.number),
concludedVotes: PropTypes.objectOf(PropTypes.number),
winner: PropTypes.string,
};

Expand Down
4 changes: 4 additions & 0 deletions client/src/css/Home.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
.latestIssue > * {
margin: 0;
}

.latestIssueRemoveMargin {
margin: 0 -0.5rem;
}
5 changes: 3 additions & 2 deletions client/src/features/issue/reducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CLOSE_ISSUE, OPEN_ISSUE, SEND_VOTE, DELETED_ISSUE } from 'common/actionTypes/issues';
import { RECEIVE_VOTE, USER_VOTE, DISABLE_VOTING, ENABLE_VOTING } from 'common/actionTypes/voting';

const issue = (state = { votes: {} }, action, currentIssue) => {
const issue = (state = { votes: {}, concludedVotes: {} }, action, currentIssue) => {
switch (action.type) {
case CLOSE_ISSUE:
case OPEN_ISSUE: {
Expand All @@ -22,9 +22,10 @@ const issue = (state = { votes: {} }, action, currentIssue) => {
countingBlankVotes: action.data.countingBlankVotes,
showOnlyWinner: action.data.showOnlyWinner,
status: action.data.status,
votes: action.data.votes || {},
votes: action.data.votes || state.votes,
winner: action.data.winner,
userVote: state.userVote || null,
concludedVotes: action.data.concludedVotes || {},
};
}
case USER_VOTE: {
Expand Down
Loading

0 comments on commit c62bd60

Please sign in to comment.