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..d215a5a3
--- /dev/null
+++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/ConfirmationModal/ConfirmationModal.jsx
@@ -0,0 +1,38 @@
+import React from "react";
+import { Modal, Icon, Message } from "semantic-ui-react";
+
+export function ConfirmationModal({
+ header,
+ content,
+ trigger,
+ actions,
+ isOpen,
+ close,
+}) {
+ return (
+ <>
+ {trigger}
+
+ {header}
+ {content && (
+
+
+
+ {content}
+
+
+
+ )}
+ {actions}
+
+ >
+ );
+}
+
+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
index d87d33ac..09d01b14 100644
--- 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
@@ -1,76 +1,72 @@
import React from "react";
-import { Button, Modal, Icon, Message } from "semantic-ui-react";
+import { Button, Icon } 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 { isModalOpen, handleCloseModal, handleOpenModal } =
- useConfirmationModal();
+ 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={
+ <>
+
+
+ >
);
}
);
diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/PublishButton/PublishButton.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/PublishButton/PublishButton.jsx
index 3f89739b..8af82c85 100644
--- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/PublishButton/PublishButton.jsx
+++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/PublishButton/PublishButton.jsx
@@ -1,47 +1,44 @@
import React from "react";
-import { Button, Modal, Message, Icon } from "semantic-ui-react";
+import { Button } from "semantic-ui-react";
import { i18next } from "@translations/oarepo_ui/i18next";
-import { useConfirmationModal, useDepositApiClient } from "@js/oarepo_ui";
+import {
+ useConfirmationModal,
+ useDepositApiClient,
+ ConfirmationModal,
+} from "@js/oarepo_ui";
import PropTypes from "prop-types";
export const PublishButton = React.memo(({ modalMessage, modalHeader }) => {
- const { isModalOpen, handleCloseModal, handleOpenModal } =
- useConfirmationModal();
+ const {
+ isOpen: isModalOpen,
+ close: closeModal,
+ open: openModal,
+ } = useConfirmationModal();
const { isSubmitting, publish } = useDepositApiClient();
return (
-
-
-
- {modalHeader}
- {modalMessage && (
-
-
-
- {modalMessage}
-
-
-
- )}
-
-
+
+ }
+ actions={
+ <>
+
{i18next.t("Cancel")}
{
color="green"
onClick={() => {
publish();
- handleCloseModal();
+ closeModal();
}}
icon="upload"
labelPosition="left"
content={i18next.t("Publish")}
type="submit"
/>
-
-
-
+ >
+ }
+ />
);
});
diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js
index 422dd567..1f0e0c28 100644
--- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js
+++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js
@@ -13,4 +13,5 @@ export * from "./DeleteButton";
export * from "./PreviewButton";
export * from "./PublishButton";
export * from "./SaveButton";
-export * from "./ValidateButton";
\ No newline at end of file
+export * from "./ValidateButton";
+export * from "./ConfirmationModal";
diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js
index 11f6b530..9ad32a6b 100644
--- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js
+++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js
@@ -62,12 +62,12 @@ export const useVocabularyOptions = (vocabularyType) => {
};
export const useConfirmationModal = () => {
- const [isModalOpen, setIsModalOopen] = React.useState(false);
+ const [isOpen, setIsOpen] = React.useState(false);
- const handleCloseModal = () => setIsModalOopen(false);
- const handleOpenModal = () => setIsModalOopen(true);
+ const close = React.useCallback(() => setIsOpen(false));
+ const open = React.useCallback(() => setIsOpen(true));
- return { isModalOpen, handleCloseModal, handleOpenModal };
+ return { isOpen, close, open };
};
export const useFormFieldValue = ({
@@ -166,7 +166,7 @@ export const useDepositApiClient = (
? new baseApiClient(createUrl, recordSerializer)
: new OARepoDepositApiClient(createUrl, recordSerializer);
- async function save(saveWithoutDisplayingValidationErrors = false) {
+ async function save (saveWithoutDisplayingValidationErrors = false) {
let response;
setSubmitting(true);
@@ -231,7 +231,7 @@ export const useDepositApiClient = (
}
}
- async function publish() {
+ async function publish () {
// call save and if save returns false, exit
const saveResult = await save();
@@ -296,11 +296,11 @@ export const useDepositApiClient = (
}
}
- async function read(recordUrl) {
+ async function read (recordUrl) {
return await apiClient.readDraft({ self: recordUrl });
}
- async function _delete(redirectUrl) {
+ async function _delete (redirectUrl) {
if (!redirectUrl)
throw new Error(
"You must provide url where to be redirected after deleting a draft"
@@ -358,10 +358,10 @@ export const useDepositFileApiClient = (baseApiClient) => {
? new baseApiClient()
: new OARepoDepositFileApiClient();
- async function read(draft) {
+ async function read (draft) {
return await apiClient.readDraftFiles(draft);
}
- async function _delete(file) {
+ async function _delete (file) {
setValues(
_omit(values, [
"errors",
diff --git a/oarepo_ui/theme/assets/semantic-ui/translations/oarepo_ui/messages/cs/LC_MESSAGES/translations.json b/oarepo_ui/theme/assets/semantic-ui/translations/oarepo_ui/messages/cs/LC_MESSAGES/translations.json
index fa64a373..14d5a2c2 100644
--- a/oarepo_ui/theme/assets/semantic-ui/translations/oarepo_ui/messages/cs/LC_MESSAGES/translations.json
+++ b/oarepo_ui/theme/assets/semantic-ui/translations/oarepo_ui/messages/cs/LC_MESSAGES/translations.json
@@ -70,5 +70,6 @@
"Validate form": "Zkontrolovat formulář",
"Delete": "Smazat",
"Are you sure you wish delete this draft?": "Jste si jistý, že chcete smazat tento koncept?",
- "If you delete the draft, the work you have done on it will be lost.": "Pokud koncept smažete, práce, kterou jste na něm vykonali, bude ztracena."
+ "If you delete the draft, the work you have done on it will be lost.": "Pokud koncept smažete, práce, kterou jste na něm vykonali, bude ztracena.",
+ "Cancel": "Zrušit"
}
\ No newline at end of file