UNPKG

@kiwicom/smart-faq

Version:

85 lines (72 loc) 2.39 kB
// @flow import * as React from 'react'; import Text from '@kiwicom/nitro/lib/components/Text'; import Translate from '@kiwicom/nitro/lib/components/Translate'; import Stack from '@kiwicom/orbit-components/lib/Stack'; import ButtonLink from '@kiwicom/orbit-components/lib/ButtonLink'; import { ThumbUp, ThumbDown } from '@kiwicom/orbit-components/lib/icons'; import LogContext from '@kiwicom/nitro/lib/services/log/context'; import type { Context as LogContextType } from '@kiwicom/nitro/lib/services/log/context'; import type { VoteType } from '../../../SmartFAQ/mutations/__generated__/VoteArticleMutation.graphql'; import screenList from './screenList'; import voteArticle from '../../../SmartFAQ/mutations/VoteArticle'; import { events } from '../../../const/events'; type Props = {| articleId: number, changeScreen: (nextScreen: $Values<typeof screenList>) => void, |}; const voteType = { UP: 'up', DOWN: 'down', }; class ScreenVoting extends React.Component<Props> { context: LogContextType; static contextType = LogContext; handleVoteUp = () => { this.handleVote(voteType.UP); }; handleVoteDown = () => { this.handleVote(voteType.DOWN); }; handleVote = (vote: VoteType) => { const { articleId, changeScreen } = this.props; const { log } = this.context; const screen = vote === voteType.UP ? screenList.THANK_YOU : screenList.FEEDBACK; voteArticle({ articleId, vote }) .then(() => { changeScreen(screen); }) .catch(error => { log(events.FAQ_VOTE_ERROR, { error }); changeScreen(screenList.ERROR); }); if (vote === voteType.UP) { log(events.FAQ_VOTE_UP, {}); } else { log(events.FAQ_VOTE_DOWN, {}); } }; render() { return ( <Stack flex align="center"> <Text t="smartfaq.article_feedback.voting.title" /> <ButtonLink onClick={this.handleVoteUp} iconLeft={<ThumbUp size="medium" />} dataTest="thumbUp" > <Translate t="smartfaq.article_feedback.voting.yes" /> </ButtonLink> <ButtonLink onClick={this.handleVoteDown} iconLeft={<ThumbDown size="medium" />} dataTest="thumbDown" > <Translate t="smartfaq.article_feedback.voting.no" /> </ButtonLink> </Stack> ); } } export default ScreenVoting;