2019-02-13 04:02:55 +00:00
import React from 'react' ;
import PropTypes from 'prop-types' ;
2023-09-13 00:40:50 +00:00
import { Modal , ModalHeader , ModalBody } from 'reactstrap' ;
2019-02-13 04:02:55 +00:00
import { gettext , contactEmail } from '../../utils/constants' ;
import { seafileAPI } from '../../utils/seafile-api' ;
const propTypes = {
repoID : PropTypes . string . isRequired ,
toggleDialog : PropTypes . func . isRequired ,
} ;
class ResetEncryptedRepoPasswordDialog extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
errMessage : '' ,
showLoading : true ,
showSuccess : false ,
showError : false ,
} ;
}
componentDidMount ( ) {
seafileAPI . resetAndSendEncryptedRepoPassword ( this . props . repoID ) . then ( ( res ) => {
2024-07-18 03:58:42 +00:00
this . setState ( { showLoading : false } ) ;
this . setState ( { showSuccess : true } ) ;
2019-02-13 04:02:55 +00:00
} ) . catch ( ( error ) => {
if ( error . response ) {
this . setState ( {
errMessage : error . response . data . error _msg
} ) ;
2024-07-18 03:58:42 +00:00
this . setState ( { showLoading : false } ) ;
this . setState ( { showError : true } ) ;
2019-02-13 04:02:55 +00:00
}
} ) ;
}
render ( ) {
let user _email = '<strong>' + contactEmail + '</strong>' ;
let message = gettext ( 'New password has been sent to your email {mail}. Please check your mailbox. If you don’ t receive the password, please check if your email address is properly configured.' ) . replace ( '{mail}' , user _email ) ;
return (
2023-11-30 05:58:06 +00:00
< Modal isOpen = { true } toggle = { this . props . toggleDialog } >
2019-02-13 04:02:55 +00:00
< ModalHeader toggle = { this . props . toggleDialog } >
{ gettext ( 'Reset library password' ) }
< / M o d a l H e a d e r >
< ModalBody >
2020-11-02 05:56:35 +00:00
{ this . state . showLoading && (
< span > { gettext ( 'Sending new password...' ) } < / s p a n >
) }
{ this . state . showSuccess && (
2024-07-18 03:58:42 +00:00
< div dangerouslySetInnerHTML = { { _ _html : message } } / >
2020-11-02 05:56:35 +00:00
) }
{ this . state . showError && (
< span className = "err-message" > { this . state . errMessage } < / s p a n >
) }
2019-02-13 04:02:55 +00:00
< / M o d a l B o d y >
< / M o d a l >
) ;
}
}
ResetEncryptedRepoPasswordDialog . propTypes = propTypes ;
export default ResetEncryptedRepoPasswordDialog ;