import React from 'react'; import PropTypes from 'prop-types'; import { Button, Modal, ModalBody, ModalFooter, Alert } from 'reactstrap'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import FileChooser from '../file-chooser'; import { Utils } from '../../utils/utils'; import SeahubModalHeader from '@/components/common/seahub-modal-header'; const propTypes = { sharedToken: PropTypes.string.isRequired, filePath: PropTypes.string, toggleCancel: PropTypes.func.isRequired, handleSaveSharedFile: PropTypes.func.isRequired, }; class SaveSharedFileDialog extends React.Component { constructor(props) { super(props); this.state = { repo: null, selectedPath: '', errMessage: '', }; } onSaveSharedFile = () => { const { sharedToken, filePath } = this.props; seafileAPI.saveSharedFile(this.state.repo.repo_id, this.state.selectedPath, sharedToken, filePath).then((res) => { this.props.toggleCancel(); this.props.handleSaveSharedFile(); }).catch((error) => { let errMessage = Utils.getErrorMsg(error); this.setState({ errMessage: errMessage }); }); }; onDirentItemClick = (repo, selectedPath, dirent) => { if (dirent.type === 'dir') { this.setState({ repo: repo, selectedPath: selectedPath, }); } else { this.setState({ repo: null, selectedPath: '', }); } }; onRepoItemClick = (repo) => { this.setState({ repo: repo, selectedPath: '/', }); }; render() { return ( {gettext('Save to:')} {this.state.errMessage && {this.state.errMessage}} { this.state.selectedPath ? : } ); } } SaveSharedFileDialog.propTypes = propTypes; export default SaveSharedFileDialog;