import React, { Component } from 'react'; import { withModalMounter } from '/imports/ui/components/modal/service'; import Modal from '/imports/ui/components/modal/simple/component'; import Button from '/imports/ui/components/button/component'; import { defineMessages, injectIntl } from 'react-intl'; import { isUrlValid } from '../service'; import { styles } from './styles'; const intlMessages = defineMessages({ start: { id: 'app.externalVideo.start', description: 'Share external video', }, urlError: { id: 'app.externalVideo.urlError', description: 'Not a video URL error', }, input: { id: 'app.externalVideo.input', description: 'Video URL', }, urlInput: { id: 'app.externalVideo.urlInput', description: 'URL input field placeholder', }, title: { id: 'app.externalVideo.title', description: 'Modal title', }, close: { id: 'app.externalVideo.close', description: 'Close', }, note: { id: 'app.externalVideo.noteLabel', description: 'provides hint about Shared External videos', }, }); class ExternalVideoModal extends Component { constructor(props) { super(props); const { videoUrl } = props; this.state = { url: videoUrl, sharing: videoUrl, }; this.startWatchingHandler = this.startWatchingHandler.bind(this); this.updateVideoUrlHandler = this.updateVideoUrlHandler.bind(this); this.renderUrlError = this.renderUrlError.bind(this); this.updateVideoUrlHandler = this.updateVideoUrlHandler.bind(this); } startWatchingHandler() { const { startWatching, closeModal, toggleLayout, isSwapped, } = this.props; const { url } = this.state; startWatching(url.trim()); if (isSwapped) toggleLayout(); closeModal(); } updateVideoUrlHandler(ev) { this.setState({ url: ev.target.value }); } renderUrlError() { const { intl } = this.props; const { url } = this.state; const valid = (!url || url.length <= 3) || isUrlValid(url); return ( !valid ? (
{intl.formatMessage(intlMessages.urlError)}
) : null ); } render() { const { intl, videoUrl, closeModal } = this.props; const { url, sharing } = this.state; const startDisabled = !isUrlValid(url); return (

{intl.formatMessage(intlMessages.title)}

{intl.formatMessage(intlMessages.note)}
{this.renderUrlError()}
); } } export default injectIntl(withModalMounter(ExternalVideoModal));