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.

BaseSubmitDialog.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @flow
  2. import React from 'react';
  3. import { View, Text, TouchableOpacity } from 'react-native';
  4. import { StyleType } from '../../../styles';
  5. import BaseDialog, { type Props as BaseProps } from './BaseDialog';
  6. import {
  7. brandedDialog
  8. } from './styles';
  9. type Props = BaseProps & {
  10. /**
  11. * The color-schemed stylesheet of the feature.
  12. */
  13. _dialogStyles: StyleType,
  14. t: Function
  15. }
  16. /**
  17. * Abstract dialog to submit something. E.g. a confirmation or a form.
  18. */
  19. class BaseSubmitDialog<P: Props, S: *> extends BaseDialog<P, S> {
  20. /**
  21. * Returns the title key of the submit button.
  22. *
  23. * NOTE: Please do not change this, this should be consistent accross the
  24. * application. This method is here to be able to be overriden ONLY by the
  25. * {@code ConfirmDialog}.
  26. *
  27. * @returns {string}
  28. */
  29. _getSubmitButtonKey() {
  30. return this.props.okKey || 'dialog.Ok';
  31. }
  32. /**
  33. * Renders additional buttons, if any - may be overwritten by children.
  34. *
  35. * @returns {?ReactElement}
  36. */
  37. _renderAdditionalButtons() {
  38. return null;
  39. }
  40. /**
  41. * Implements {@code BaseDialog._renderContent}.
  42. *
  43. * @inheritdoc
  44. */
  45. _renderContent() {
  46. const { _dialogStyles, t } = this.props;
  47. const additionalButtons = this._renderAdditionalButtons();
  48. return (
  49. <View>
  50. <View style = { brandedDialog.mainWrapper }>
  51. { this._renderSubmittable() }
  52. </View>
  53. <View style = { brandedDialog.buttonWrapper }>
  54. { additionalButtons }
  55. <TouchableOpacity
  56. disabled = { this.props.okDisabled }
  57. onPress = { this._onSubmit }
  58. style = { [
  59. _dialogStyles.button,
  60. additionalButtons
  61. ? null : brandedDialog.buttonFarLeft,
  62. brandedDialog.buttonFarRight
  63. ] }>
  64. <Text style = { _dialogStyles.buttonLabel }>
  65. { t(this._getSubmitButtonKey()) }
  66. </Text>
  67. </TouchableOpacity>
  68. </View>
  69. </View>
  70. );
  71. }
  72. _onCancel: () => void;
  73. _onSubmit: () => boolean;
  74. _renderHTML: string => Object | string
  75. /**
  76. * Renders the actual content of the dialog defining what is about to be
  77. * submitted. E.g. a simple confirmation (text, properly wrapped) or a
  78. * complex form.
  79. *
  80. * @returns {Object}
  81. */
  82. _renderSubmittable: () => Object
  83. }
  84. export default BaseSubmitDialog;