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.

ConfirmDialog.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../../i18n';
  6. import { StyleType } from '../../../styles';
  7. import { _abstractMapStateToProps } from '../../functions';
  8. import { type Props as BaseProps } from './BaseDialog';
  9. import BaseSubmitDialog from './BaseSubmitDialog';
  10. import { brandedDialog } from './styles';
  11. type Props = BaseProps & {
  12. /**
  13. * The color-schemed stylesheet of the feature.
  14. */
  15. _dialogStyles: StyleType,
  16. /**
  17. * Untranslated i18n key of the content to be displayed.
  18. *
  19. * NOTE: This dialog also adds support to Object type keys that will be
  20. * translated using the provided params. See i18n function
  21. * {@code translate(string, Object)} for more details.
  22. */
  23. contentKey: string | { key: string, params: Object},
  24. t: Function
  25. }
  26. /**
  27. * Implements a confirm dialog component.
  28. */
  29. class ConfirmDialog extends BaseSubmitDialog<Props, *> {
  30. /**
  31. * Returns the title key of the submit button.
  32. *
  33. * @returns {string}
  34. */
  35. _getSubmitButtonKey() {
  36. return this.props.okKey || 'dialog.confirmYes';
  37. }
  38. _onCancel: () => void;
  39. /**
  40. * Renders the 'No' button.
  41. *
  42. * NOTE: The {@code ConfirmDialog} is the only dialog right now that
  43. * renders 2 buttons, mainly for clarity.
  44. *
  45. * @inheritdoc
  46. */
  47. _renderAdditionalButtons() {
  48. const { _dialogStyles, cancelKey, t } = this.props;
  49. return (
  50. <TouchableOpacity
  51. onPress = { this._onCancel }
  52. style = { [
  53. _dialogStyles.button,
  54. brandedDialog.buttonFarLeft,
  55. _dialogStyles.buttonSeparator
  56. ] }>
  57. <Text style = { _dialogStyles.buttonLabel }>
  58. { t(cancelKey || 'dialog.confirmNo') }
  59. </Text>
  60. </TouchableOpacity>
  61. );
  62. }
  63. /**
  64. * Implements {@code BaseSubmitDialog._renderSubmittable}.
  65. *
  66. * @inheritdoc
  67. */
  68. _renderSubmittable() {
  69. if (this.props.children) {
  70. return this.props.children;
  71. }
  72. const { _dialogStyles, contentKey, t } = this.props;
  73. const content
  74. = typeof contentKey === 'string'
  75. ? t(contentKey)
  76. : this._renderHTML(t(contentKey.key, contentKey.params));
  77. return (
  78. <Text style = { _dialogStyles.text }>
  79. { content }
  80. </Text>
  81. );
  82. }
  83. _renderHTML: string => Object | string
  84. }
  85. export default translate(connect(_abstractMapStateToProps)(ConfirmDialog));