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

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