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.5KB

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