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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import Dialog from 'react-native-dialog';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../../i18n/functions';
  6. import { _abstractMapStateToProps } from '../../functions';
  7. import { renderHTML } from '../functions.native';
  8. import AbstractDialog, { IProps as AbstractProps } from './AbstractDialog';
  9. interface IProps extends AbstractProps, WithTranslation {
  10. /**
  11. * Untranslated i18n key of the content to be displayed.
  12. *
  13. * NOTE: This dialog also adds support to Object type keys that will be
  14. * translated using the provided params. See i18n function
  15. * {@code translate(string, Object)} for more details.
  16. */
  17. contentKey: string | { key: string; params: Object; };
  18. }
  19. /**
  20. * Implements an alert dialog, to simply show an error or a message,
  21. * then disappear on dismiss.
  22. */
  23. class AlertDialog extends AbstractDialog<IProps> {
  24. /**
  25. * Implements React's {@link Component#render}.
  26. *
  27. * @inheritdoc
  28. */
  29. render() {
  30. const { contentKey, t } = this.props;
  31. const content
  32. = typeof contentKey === 'string'
  33. ? t(contentKey)
  34. : renderHTML(t(contentKey.key, contentKey.params));
  35. return (
  36. <Dialog.Container
  37. coverScreen = { false }
  38. visible = { true }>
  39. <Dialog.Description>
  40. { content }
  41. </Dialog.Description>
  42. <Dialog.Button
  43. label = { t('dialog.Ok') }
  44. onPress = { this._onSubmit } />
  45. </Dialog.Container>
  46. );
  47. }
  48. }
  49. export default translate(connect(_abstractMapStateToProps)(AlertDialog));