import React from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, TabContent, TabPane } from 'reactstrap';
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 (
{isPro &&
}
);
};
render() {
const { itemName: repoName } = this.props;
let title = gettext('{library_name} Office Suite');
title = title.replace('{library_name}', '' + Utils.HTMLescape(repoName) + '');
return (
{this.renderOfficeSuiteContent()}
);
}
}
OfficeSuiteDialog.propTypes = propTypes;
export default OfficeSuiteDialog;