import React from 'react'; import ModalPortal from '../modal-portal'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import toaster from '../toast'; import UpdateWebdavPassword from '../dialog/update-webdav-password'; const { webdavPasswd } = window.app.pageOptions; class WebdavPassword extends React.Component { constructor(props) { super(props); this.state = { password: webdavPasswd, isPasswordVisible: false, isDialogOpen: false }; } togglePasswordVisible = () => { this.setState({ isPasswordVisible: !this.state.isPasswordVisible }); } updatePassword = (password) => { seafileAPI.updateWebdavSecret(password).then((res) => { this.toggleDialog(); this.setState({ password: password }); toaster.success(gettext('Success')); }).catch((error) => { let errorMsg = ''; if (error.response) { if (error.response.data && error.response.data['error_msg']) { errorMsg = error.response.data['error_msg']; } else { errorMsg = gettext('Error'); } } else { errorMsg = gettext('Please check the network.'); } this.toggleDialog(); toaster.danger(errorMsg); }); } toggleDialog = () => { this.setState({ isDialogOpen: !this.state.isDialogOpen }); } render() { const { password, isPasswordVisible } = this.state; return (

{gettext('WebDav Password')}

{password ? (
) : ( )}
{this.state.isDialogOpen && ( )}
); } } export default WebdavPassword;