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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. submitAnswer,
  17. t
  18. } = props;
  19. return (
  20. <View>
  21. <View>
  22. <Text style = { dialogStyles.question } >{ poll.question }</Text>
  23. </View>
  24. <View style = { chatStyles.answerContent }>
  25. {poll.answers.map((answer, index) => (
  26. <View
  27. key = { index }
  28. style = { chatStyles.switchRow } >
  29. <Switch
  30. /* eslint-disable react/jsx-no-bind */
  31. onValueChange = { state => setCheckbox(index, state) }
  32. value = { checkBoxStates[index] } />
  33. <Text>{answer.name}</Text>
  34. </View>
  35. ))}
  36. </View>
  37. <View style = { chatStyles.buttonRow }>
  38. <Button
  39. color = '#3D3D3D'
  40. mode = { BUTTON_MODES.CONTAINED }
  41. onPress = { skipAnswer }
  42. style = { chatStyles.pollCreateButton } >
  43. {t('polls.answer.skip')}
  44. </Button>
  45. <Button
  46. color = '#17a0db'
  47. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  48. mode = { BUTTON_MODES.CONTAINED }
  49. onPress = { submitAnswer }
  50. style = { chatStyles.pollCreateButton } >
  51. {t('polls.answer.submit')}
  52. </Button>
  53. </View>
  54. </View>
  55. );
  56. };
  57. /*
  58. * We apply AbstractPollAnswer to fill in the AbstractProps common
  59. * to both the web and native implementations.
  60. */
  61. // eslint-disable-next-line new-cap
  62. export default AbstractPollAnswer(PollAnswer);