You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PollAnswer.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // @flow
  2. import React from 'react';
  3. import { Switch, Text, View } from 'react-native';
  4. import { Button } from 'react-native-paper';
  5. import { BUTTON_MODES } from '../../../chat/constants';
  6. import { isSubmitAnswerDisabled } from '../../functions';
  7. import AbstractPollAnswer from '../AbstractPollAnswer';
  8. import type { AbstractProps } from '../AbstractPollAnswer';
  9. import { chatStyles, dialogStyles } from './styles';
  10. const PollAnswer = (props: AbstractProps) => {
  11. const {
  12. checkBoxStates,
  13. poll,
  14. setCheckbox,
  15. skipAnswer,
  16. skipChangeVote,
  17. submitAnswer,
  18. t
  19. } = props;
  20. const { changingVote } = poll;
  21. return (
  22. <View>
  23. <View>
  24. <Text style = { dialogStyles.question } >{ poll.question }</Text>
  25. </View>
  26. <View style = { chatStyles.answerContent }>
  27. {poll.answers.map((answer, index) => (
  28. <View
  29. key = { index }
  30. style = { chatStyles.switchRow } >
  31. <Switch
  32. /* eslint-disable react/jsx-no-bind */
  33. onValueChange = { state => setCheckbox(index, state) }
  34. value = { checkBoxStates[index] } />
  35. <Text>{answer.name}</Text>
  36. </View>
  37. ))}
  38. </View>
  39. <View style = { chatStyles.buttonRow }>
  40. <Button
  41. color = '#3D3D3D'
  42. mode = { BUTTON_MODES.CONTAINED }
  43. onPress = { changingVote ? skipChangeVote : skipAnswer }
  44. style = { chatStyles.pollCreateButton } >
  45. {t('polls.answer.skip')}
  46. </Button>
  47. <Button
  48. color = '#17a0db'
  49. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  50. mode = { BUTTON_MODES.CONTAINED }
  51. onPress = { submitAnswer }
  52. style = { chatStyles.pollCreateButton } >
  53. {t('polls.answer.submit')}
  54. </Button>
  55. </View>
  56. </View>
  57. );
  58. };
  59. /*
  60. * We apply AbstractPollAnswer to fill in the AbstractProps common
  61. * to both the web and native implementations.
  62. */
  63. // eslint-disable-next-line new-cap
  64. export default AbstractPollAnswer(PollAnswer);