2019-06-27 06:08:10 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Button, Form, FormGroup, Label } from 'reactstrap';
|
|
|
|
import { seafileAPI } from '../utils/seafile-api';
|
|
|
|
import { gettext } from '../utils/constants';
|
2019-07-16 02:01:09 +00:00
|
|
|
import { Utils } from '../utils/utils';
|
2019-06-27 06:08:10 +00:00
|
|
|
import toaster from './toast';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
token: PropTypes.string.isRequired,
|
|
|
|
linkType: PropTypes.string.isRequired,
|
|
|
|
toggleSendLink: PropTypes.func.isRequired,
|
|
|
|
closeShareDialog: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
class SendLink extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
emails: '',
|
|
|
|
msg: '',
|
|
|
|
errorMsg: '',
|
|
|
|
btnDisabled: false,
|
|
|
|
sending: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEmailsInputChange = (e) => {
|
|
|
|
this.setState({
|
|
|
|
emails: e.target.value
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-06-27 06:08:10 +00:00
|
|
|
|
|
|
|
handleMsgInputChange = (e) => {
|
|
|
|
this.setState({
|
|
|
|
msg: e.target.value
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-06-27 06:08:10 +00:00
|
|
|
|
|
|
|
sendLink = () => {
|
|
|
|
const { emails, msg } = this.state;
|
|
|
|
if (!emails.trim()) {
|
|
|
|
this.setState({
|
|
|
|
errorMsg: gettext('Please input at least an email.')
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2020-11-02 05:56:35 +00:00
|
|
|
|
2019-06-27 06:08:10 +00:00
|
|
|
this.setState({
|
|
|
|
btnDisabled: true,
|
|
|
|
sending: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const { token, linkType } = this.props;
|
|
|
|
const request = linkType == 'uploadLink' ?
|
|
|
|
seafileAPI.sendUploadLink(token, emails.trim(), msg.trim()) :
|
|
|
|
seafileAPI.sendShareLink(token, emails.trim(), msg.trim());
|
|
|
|
request.then((res) => {
|
|
|
|
this.props.closeShareDialog();
|
|
|
|
const { success, failed } = res.data;
|
|
|
|
if (success.length) {
|
|
|
|
const feedbackMsg = gettext('Successfully sent to {placeholder}')
|
|
|
|
.replace('{placeholder}', success.join(', '));
|
|
|
|
toaster.success(feedbackMsg);
|
|
|
|
}
|
|
|
|
if (failed.length) {
|
2023-09-13 00:40:50 +00:00
|
|
|
failed.forEach((item) => {
|
2019-06-27 06:08:10 +00:00
|
|
|
const feedbackMsg = gettext('Failed to send to {email_placeholder}: {errorMsg_placeholder}')
|
|
|
|
.replace('{email_placeholder}', item.email)
|
|
|
|
.replace('{errorMsg_placeholder}', item.error_msg);
|
|
|
|
toaster.warning(feedbackMsg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch((error) => {
|
2019-07-16 02:01:09 +00:00
|
|
|
let errorMsg = Utils.getErrorMsg(error);
|
2019-06-27 06:08:10 +00:00
|
|
|
this.setState({
|
|
|
|
btnDisabled: false,
|
|
|
|
sending: false,
|
|
|
|
errorMsg: errorMsg
|
|
|
|
});
|
2020-11-02 05:56:35 +00:00
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-06-27 06:08:10 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { emails, msg, errorMsg, btnDisabled, sending } = this.state;
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
<FormGroup>
|
|
|
|
<Label htmlFor="emails" className="text-secondary font-weight-normal">{gettext('Send to:')}</Label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="emails"
|
|
|
|
className="form-control w-75"
|
|
|
|
value={emails}
|
|
|
|
onChange={this.handleEmailsInputChange}
|
|
|
|
placeholder={gettext('Emails, separated by \',\'')}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Label htmlFor="msg" className="text-secondary font-weight-normal">{gettext('Message (optional):')}</Label>
|
|
|
|
<textarea
|
|
|
|
className="form-control w-75"
|
|
|
|
id="msg"
|
|
|
|
value={msg}
|
|
|
|
onChange={this.handleMsgInputChange}
|
2024-07-18 03:58:42 +00:00
|
|
|
>
|
|
|
|
</textarea>
|
2019-06-27 06:08:10 +00:00
|
|
|
</FormGroup>
|
|
|
|
{errorMsg && <p className="error">{errorMsg}</p>}
|
|
|
|
<Button color="primary" onClick={this.sendLink} disabled={btnDisabled} className="mr-2">{gettext('Send')}</Button>
|
|
|
|
<Button color="secondary" onClick={this.props.toggleSendLink}>{gettext('Cancel')}</Button>
|
|
|
|
{sending && <p className="mt-2">{gettext('Sending...')}</p>}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendLink.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default SendLink;
|