|
|
@@ -0,0 +1,64 @@
|
|
|
+import React, { useCallback } from 'react';
|
|
|
+
|
|
|
+import { useTranslation } from 'next-i18next';
|
|
|
+import Link from 'next/link';
|
|
|
+import {
|
|
|
+ Button, Modal, ModalHeader, ModalBody, ModalFooter,
|
|
|
+} from 'reactstrap';
|
|
|
+
|
|
|
+import { apiv3Delete } from '~/client/util/apiv3-client';
|
|
|
+import { toastSuccess, toastError } from '~/client/util/toastr';
|
|
|
+
|
|
|
+import { useSWRxAdminPlugins, usePluginDeleteModal } from '../../../stores/admin-plugins';
|
|
|
+
|
|
|
+export const PluginDeleteModal: React.FC = () => {
|
|
|
+
|
|
|
+ const { t } = useTranslation('admin');
|
|
|
+ const { mutate } = useSWRxAdminPlugins();
|
|
|
+ const { data: pluginDeleteModalData, close: closePluginDeleteModal } = usePluginDeleteModal();
|
|
|
+ const isOpen = pluginDeleteModalData?.isOpen;
|
|
|
+ const id = pluginDeleteModalData?.id;
|
|
|
+ const name = pluginDeleteModalData?.name;
|
|
|
+ const url = pluginDeleteModalData?.url;
|
|
|
+
|
|
|
+ const toggleHandler = useCallback(() => {
|
|
|
+ closePluginDeleteModal();
|
|
|
+ }, [closePluginDeleteModal]);
|
|
|
+
|
|
|
+ const onClickDeleteButtonHandler = useCallback(async() => {
|
|
|
+ const reqUrl = `/plugins/${id}/remove`;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res = await apiv3Delete(reqUrl);
|
|
|
+ const pluginName = res.data.pluginName;
|
|
|
+ closePluginDeleteModal();
|
|
|
+ toastSuccess(t('toaster.remove_plugin_success', { pluginName }));
|
|
|
+ mutate();
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ toastError(err);
|
|
|
+ }
|
|
|
+ }, [id, closePluginDeleteModal, t, mutate]);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal isOpen={isOpen} toggle={toggleHandler}>
|
|
|
+ <ModalHeader tag="h4" toggle={toggleHandler} className="bg-danger text-light" name={name}>
|
|
|
+ <span>
|
|
|
+ <i className="icon-fw icon-fire"></i>
|
|
|
+ {t('plugins.confirm')}
|
|
|
+ </span>
|
|
|
+ </ModalHeader>
|
|
|
+ <ModalBody>
|
|
|
+ <div className="card well mt-2 p-2" key={id}>
|
|
|
+ <Link href={`${url}`} legacyBehavior>{name}</Link>
|
|
|
+ </div>
|
|
|
+ </ModalBody>
|
|
|
+ <ModalFooter>
|
|
|
+ <Button color="danger" onClick={onClickDeleteButtonHandler}>
|
|
|
+ <i className="icon-fw icon-fire"></i>
|
|
|
+ {t('Delete')}
|
|
|
+ </Button>
|
|
|
+ </ModalFooter>
|
|
|
+ </Modal>
|
|
|
+ );
|
|
|
+};
|