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.

SharedVideoDialog.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // @flow
  2. import { FieldTextStateless } from '@atlaskit/field-text';
  3. import React from 'react';
  4. import { Dialog } from '../../../base/dialog';
  5. import { translate } from '../../../base/i18n';
  6. import { getFieldValue } from '../../../base/react';
  7. import { connect } from '../../../base/redux';
  8. import AbstractSharedVideoDialog from '../AbstractSharedVideoDialog';
  9. /**
  10. * Component that renders the video share dialog.
  11. *
  12. * @returns {React$Element<any>}
  13. */
  14. class SharedVideoDialog extends AbstractSharedVideoDialog<*> {
  15. /**
  16. * Instantiates a new component.
  17. *
  18. * @inheritdoc
  19. */
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. value: '',
  24. okDisabled: true,
  25. error: false
  26. };
  27. this._onChange = this._onChange.bind(this);
  28. this._onSubmitValue = this._onSubmitValue.bind(this);
  29. }
  30. _onChange: Object => void;
  31. /**
  32. * Callback for the onChange event of the field.
  33. *
  34. * @param {Object} evt - The static event.
  35. * @returns {void}
  36. */
  37. _onChange(evt: Object) {
  38. const linkValue = getFieldValue(evt);
  39. this.setState({
  40. value: linkValue,
  41. okDisabled: !linkValue
  42. });
  43. }
  44. _onSubmitValue: () => boolean;
  45. /**
  46. * Callback to be invoked when the value of the link input is submitted.
  47. *
  48. * @returns {boolean}
  49. */
  50. _onSubmitValue() {
  51. const result = super._onSetVideoLink(this.state.value);
  52. if (!result) {
  53. this.setState({
  54. error: true
  55. });
  56. }
  57. return result;
  58. }
  59. /**
  60. * Implements React's {@link Component#render()}.
  61. *
  62. * @inheritdoc
  63. */
  64. render() {
  65. const { t } = this.props;
  66. const { error } = this.state;
  67. return (
  68. <Dialog
  69. hideCancelButton = { false }
  70. okDisabled = { this.state.okDisabled }
  71. okKey = { t('dialog.Share') }
  72. onSubmit = { this._onSubmitValue }
  73. titleKey = { t('dialog.shareVideoTitle') }
  74. width = { 'small' }>
  75. <FieldTextStateless
  76. autoFocus = { true }
  77. className = 'input-control'
  78. compact = { false }
  79. isInvalid = { error }
  80. label = { t('dialog.videoLink') }
  81. name = 'sharedVideoUrl'
  82. onChange = { this._onChange }
  83. placeholder = { t('dialog.sharedVideoLinkPlaceholder') }
  84. shouldFitContainer = { true }
  85. type = 'text'
  86. value = { this.state.value } />
  87. { error && <span className = 'shared-video-dialog-error'>{ t('dialog.sharedVideoDialogError') }</span> }
  88. </Dialog>
  89. );
  90. }
  91. _onChange: Object => void;
  92. }
  93. export default translate(connect()(SharedVideoDialog));