From e4a641aca387370adf5bfbe06f3f9ea9ed22215d Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 3 Jul 2020 17:49:57 +0300 Subject: feat: notify unauthorized user trying to vote --- src/components/PollCard/PollCard.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/components/PollCard') 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 = ({ 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' }); -- cgit v1.2.3