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

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