diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/ConfirmationModal.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/ConfirmationModal.jsx new file mode 100644 index 00000000..784acc1f --- /dev/null +++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/ConfirmationModal.jsx @@ -0,0 +1,48 @@ +import React from "react"; +import { Modal, Icon, Message } from "semantic-ui-react"; +import PropTypes from "prop-types"; + +export function ConfirmationModal({ + header, + content, + trigger, + actions, + isOpen, + close, +}) { + return ( + <> + {trigger} + + {header} + {content && ( + + +

+ {content} +

+
+
+ )} + {actions} +
+ + ); +} + +ConfirmationModal.propTypes = { + header: PropTypes.string, + content: PropTypes.string, + trigger: PropTypes.element, + actions: PropTypes.node, + isOpen: PropTypes.bool, + close: PropTypes.func, +}; + +export default ConfirmationModal; diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/index.js b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/index.js new file mode 100644 index 00000000..ccb94b1e --- /dev/null +++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/index.js @@ -0,0 +1,2 @@ +export * from './ConfirmationModal'; +export { default } from './ConfirmationModal'; diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/DeleteButton/DeleteButton.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/DeleteButton/DeleteButton.jsx new file mode 100644 index 00000000..8f345779 --- /dev/null +++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/DeleteButton/DeleteButton.jsx @@ -0,0 +1,87 @@ +import React from "react"; +import { Button } from "semantic-ui-react"; +import { i18next } from "@translations/i18next"; +import { + useConfirmationModal, + useFormConfig, + useDepositApiClient, + ConfirmationModal, +} from "@js/oarepo_ui"; +import PropTypes from "prop-types"; + +export const DeleteButton = React.memo( + ({ modalMessage, modalHeader, redirectUrl }) => { + const { + isOpen: isModalOpen, + close: closeModal, + open: openModal, + } = useConfirmationModal(); + const { + formConfig: { permissions }, + } = useFormConfig(); + const { values, isSubmitting, _delete, isDeleting } = useDepositApiClient(); + + return ( + <> + {values.id && permissions?.can_delete_draft && ( + + } + actions={ + <> + + +