import React from 'react'; import PropTypes from 'prop-types'; import { Button, Modal, ModalBody, ModalFooter, TabContent, TabPane } from 'reactstrap'; import SeahubModalHeader from '../common/seahub-modal-header'; import makeAnimated from 'react-select/animated'; import { userAPI } from '../../utils/user-api'; import { gettext, isPro } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import toaster from '../toast'; import { SeahubSelect } from '../common/select'; import '../../css/repo-office-suite-dialog.css'; const propTypes = { itemName: PropTypes.string.isRequired, toggleDialog: PropTypes.func.isRequired, submit: PropTypes.func.isRequired, repoID: PropTypes.string.isRequired, }; class OfficeSuiteDialog extends React.Component { constructor(props) { super(props); this.state = { selectedOption: null, errorMsg: [] }; this.options = []; } handleSelectChange = (option) => { this.setState({ selectedOption: option }); }; submit = () => { let suite_id = this.state.selectedOption.value; this.props.submit(suite_id); }; componentDidMount() { if (isPro) { userAPI.getOfficeSuite(this.props.repoID).then((res) => { this.updateOptions(res); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } } updateOptions = (officeSuites) => { officeSuites.data.suites_info.forEach(item => { let option = { value: item.id, label: item.name, is_selected: item.is_selected, }; this.options.push(option); }); let selectedOption = this.options.find(op => op.is_selected); this.setState({ selectedOption }); }; renderOfficeSuiteContent = () => { return (