import React from 'react'; import ModalPortal from '../modal-portal'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; 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 = Utils.getErrorMsg(error); this.toggleDialog(); toaster.danger(errorMsg); }); } toggleDialog = () => { this.setState({ isDialogOpen: !this.state.isDialogOpen }); } onIconKeyDown = (e) => { if (e.key == 'Enter' || e.key == 'Space') { e.target.click(); } } render() { const { password, isPasswordVisible } = this.state; return (

{gettext('WebDav Password')}

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