import React from 'react'; import '../css/SharePopup.scss'; import PropTypes from 'prop-types'; import ErrorMessage from './ErrorMessage'; import Utils from '../classes/Utils'; import ClipboardInput from './ClipboardInput'; import QRCode from 'qrcode.react'; import update from 'immutability-helper'; import $ from 'jquery'; import PluginsAPI from '../classes/plugins/API'; import { _ } from '../classes/gettext'; class SharePopup extends React.Component{ static propTypes = { task: PropTypes.object.isRequired, linksTarget: PropTypes.oneOf(['map', '3d']).isRequired, placement: PropTypes.string, taskChanged: PropTypes.func, queryParams: PropTypes.object }; static defaultProps = { placement: 'top', taskChanged: () => {} }; constructor(props){ super(props); this.state = { task: props.task, togglingShare: false, error: "", showQR: false, linkControls: [], // coming from plugins, relShareLink: this.getRelShareLink() }; this.handleEnableSharing = this.handleEnableSharing.bind(this); } getRelShareLink = () => { let url = `/public/task/${this.props.task.id}/${this.props.linksTarget}/`; if (this.props.queryParams){ url += Utils.toSearchQuery(this.props.queryParams); } return url; } componentDidMount(){ if (!this.state.task.public){ this.handleEnableSharing(); } PluginsAPI.SharePopup.triggerAddLinkControl({ sharePopup: this }, (ctrl) => { if (!ctrl) return; this.setState(update(this.state, { linkControls: {$push: [ctrl]} })); }); } handleEnableSharing(e){ const { task } = this.state; this.setState({togglingShare: true}); return $.ajax({ url: `/api/projects/${task.project}/tasks/${task.id}/`, contentType: 'application/json', data: JSON.stringify({ public: !this.state.task.public }), dataType: 'json', type: 'PATCH' }) .done((task) => { this.setState({task}); this.props.taskChanged(task); }) .fail(() => this.setState({error: _("An error occurred. Check your connection and permissions.")})) .always(() => { this.setState({togglingShare: false}); }); } toggleQRCode = () => { this.setState({showQR: !this.state.showQR}); } render(){ const shareLink = Utils.absoluteUrl(this.getRelShareLink()); const iframeUrl = Utils.absoluteUrl(`public/task/${this.state.task.id}/iframe/${this.props.linksTarget}/${Utils.toSearchQuery(this.props.queryParams)}`); const iframeCode = ``; return (
{ e.stopPropagation(); }} className={"sharePopup " + this.props.placement}>

{_("Share This Task")}

{this.state.linkControls.map((Ctrl, i) => )}
); } } export default SharePopup;