|
|
@@ -1,21 +1,25 @@
|
|
|
import React from 'react';
|
|
|
-import * as toastr from 'toastr';
|
|
|
+import PropTypes from 'prop-types';
|
|
|
+
|
|
|
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
+import { toastSuccess, toastError } from '../util/apiNotification';
|
|
|
|
|
|
import { withUnstatedContainers } from './UnstatedUtils';
|
|
|
|
|
|
import AppContainer from '../services/AppContainer';
|
|
|
|
|
|
const ShareLinkList = (props) => {
|
|
|
+ const { t, appContainer } = props;
|
|
|
|
|
|
- function deleteLinkHandler(shareLink) {
|
|
|
+ async function deleteLinkHandler(shareLinkId) {
|
|
|
try {
|
|
|
- // call api
|
|
|
- toastr.success(`Successfully deleted ${shareLink._id}`);
|
|
|
+ const res = await appContainer.apiv3Delete(`/share-links/${shareLinkId}`);
|
|
|
+ const { deletedShareLink } = res.data;
|
|
|
+ toastSuccess(t('remove_share_link_success', { shareLinkId: deletedShareLink._id }));
|
|
|
}
|
|
|
catch (err) {
|
|
|
- toastr.error(new Error(`Failed to delete ${shareLink._id}`));
|
|
|
+ toastError(err);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -48,7 +52,7 @@ const ShareLinkList = (props) => {
|
|
|
<td>{shareLink.expiration}</td>
|
|
|
<td>{shareLink.description}</td>
|
|
|
<td>
|
|
|
- <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink)}>
|
|
|
+ <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
|
|
|
<i className="icon-trash"></i>Delete
|
|
|
</button>
|
|
|
</td>
|
|
|
@@ -79,4 +83,9 @@ const ShareLinkList = (props) => {
|
|
|
|
|
|
const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
|
|
|
|
|
|
+ShareLinkList.propTypes = {
|
|
|
+ t: PropTypes.func.isRequired, // i18next
|
|
|
+ appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
+};
|
|
|
+
|
|
|
export default withTranslation()(ShareLinkListWrapper);
|