Browse Source

feat: add signup-to-enable-voting view

develop
Apostolos Fanakis 4 years ago
parent
commit
150806c39d
Signed by: Apostolof GPG Key ID: 8600B4C4163B3269
  1. 21
      packages/concordia-app/src/components/PollView/PollGuestView/index.jsx
  2. 23
      packages/concordia-app/src/components/PollView/index.jsx

21
packages/concordia-app/src/components/PollView/PollGuestView/index.jsx

@ -0,0 +1,21 @@
import React from 'react';
import { Container, Header, Icon } from 'semantic-ui-react';
import { Link } from 'react-router-dom';
const PollGuestView = () => (
<Container id="topic-poll-guest-view-container" textAlign="center">
<Header as="h3" icon textAlign="center">
<Icon name="signup" />
<Header.Content>
Only registered users are able to vote in polls.
<Header.Subheader>
You can register in the&nbsp;
<Link to="/auth/register">signup</Link>
&nbsp;page.
</Header.Subheader>
</Header.Content>
</Header>
</Container>
);
export default PollGuestView;

23
packages/concordia-app/src/components/PollView/index.jsx

@ -16,6 +16,7 @@ import { FETCH_USER_DATABASE } from '../../redux/actions/peerDbReplicationAction
import { generatePollHash, generateHash } from '../../utils/hashUtils'; import { generatePollHash, generateHash } from '../../utils/hashUtils';
import { POLL_OPTIONS, POLL_QUESTION } from '../../constants/orbit/PollsDatabaseKeys'; import { POLL_OPTIONS, POLL_QUESTION } from '../../constants/orbit/PollsDatabaseKeys';
import PollDataInvalid from './PollDataInvalid'; import PollDataInvalid from './PollDataInvalid';
import PollGuestView from './PollGuestView';
const { contracts: { [VOTING_CONTRACT]: { methods: { getPoll: { cacheCall: getPollChainData } } } } } = drizzle; const { contracts: { [VOTING_CONTRACT]: { methods: { getPoll: { cacheCall: getPollChainData } } } } } = drizzle;
const { orbit } = breeze; const { orbit } = breeze;
@ -92,8 +93,6 @@ const PollView = (props) => {
} }
}, [pollHash, polls, topicId]); }, [pollHash, polls, topicId]);
// TODO: add a "Signup to enable voting" view
const userHasVoted = useMemo(() => hasSignedUp && voters const userHasVoted = useMemo(() => hasSignedUp && voters
.some((optionVoters) => optionVoters.includes(userAddress)), .some((optionVoters) => optionVoters.includes(userAddress)),
[hasSignedUp, userAddress, voters]); [hasSignedUp, userAddress, voters]);
@ -107,18 +106,24 @@ const PollView = (props) => {
return ''; return '';
}, [pollOptions, userAddress, userHasVoted, voters]); }, [pollOptions, userAddress, userHasVoted, voters]);
const pollVoteTab = useMemo(() => ( const pollVoteTab = useMemo(() => {
!loading if (!hasSignedUp) {
? ( return <PollGuestView />;
}
if (loading) {
return null;
}
return (
<PollVote <PollVote
pollOptions={pollOptions} pollOptions={pollOptions}
enableVoteChanges={pollChangeVoteEnabled} enableVoteChanges={pollChangeVoteEnabled}
hasUserVoted={userHasVoted} hasUserVoted={userHasVoted}
userVoteHash={userVoteHash} userVoteHash={userVoteHash}
/> />
) );
: <div /> }, [hasSignedUp, loading, pollChangeVoteEnabled, pollOptions, userHasVoted, userVoteHash]);
), [loading, pollChangeVoteEnabled, pollOptions, userHasVoted, userVoteHash]);
const pollGraphTab = useMemo(() => ( const pollGraphTab = useMemo(() => (
!loading !loading
@ -130,7 +135,7 @@ const PollView = (props) => {
userVoteHash={userVoteHash} userVoteHash={userVoteHash}
/> />
) )
: <div /> : null
), [loading, pollOptions, userHasVoted, userVoteHash, voteCounts]); ), [loading, pollOptions, userHasVoted, userVoteHash, voteCounts]);
const panes = useMemo(() => { const panes = useMemo(() => {

Loading…
Cancel
Save