diff options
author | eug-vs <eug-vs@keemail.me> | 2020-07-03 17:49:57 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-07-03 17:49:57 +0300 |
commit | e4a641aca387370adf5bfbe06f3f9ea9ed22215d (patch) | |
tree | 3e7fb03bb8aa41f10c0cf5801be166ea953f7e1d /src | |
parent | d68052300c2f52dfd0396a64f16645d639b8a52b (diff) | |
download | which-ui-e4a641aca387370adf5bfbe06f3f9ea9ed22215d.tar.gz |
feat: notify unauthorized user trying to vote
Diffstat (limited to 'src')
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index 6cdd777..f5a5762 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -7,9 +7,11 @@ import { } from '@material-ui/core/'; import { Which, Poll } from 'which-types'; import { useSnackbar } from 'notistack'; + import PercentageBar from './PercentageBar'; import UserStrip from '../UserStrip/UserStrip'; import { post } from '../../requests'; +import { useAuth } from '../../hooks/useAuth'; interface PropTypes { initialPoll: Poll; @@ -58,10 +60,15 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll }) => { const classes = useStyles(); const { author, contents: { left, right }, vote } = poll; const { enqueueSnackbar } = useSnackbar(); + const { isAuthenticated } = useAuth(); const date: string = new Date(poll.createdAt).toLocaleString('default', DATE_FORMAT); const handleVote = (which: Which) => { - if (vote) { + if (!isAuthenticated()) { + enqueueSnackbar('Unauthorized users can not vote in polls', { + variant: 'error' + }); + } else if (vote) { enqueueSnackbar('You have already voted in this poll', { variant: 'error' }); |