foris 6.6.2-beta.0a839bf3 → 6.6.2-beta.13ca7454

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
2
+ * Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
3
3
  *
4
4
  * This is free software, licensed under the GNU General Public License v3.
5
5
  * See /LICENSE for more information.
@@ -9,7 +9,7 @@ import React, { useState, useEffect } from "react";
9
9
 
10
10
  import PropTypes from "prop-types";
11
11
 
12
- import { useAPIPost } from "../../api/hooks";
12
+ import { useAPIPost, useAPIPut } from "../../api/hooks";
13
13
  import { API_STATE } from "../../api/utils";
14
14
  import Button from "../../bootstrap/Button";
15
15
  import {
@@ -23,6 +23,8 @@ import { useAlert } from "../../context/alertContext/AlertContext";
23
23
  ActionButtonWithModal.propTypes = {
24
24
  /** Component that triggers the action. */
25
25
  actionTrigger: PropTypes.elementType.isRequired,
26
+ /** Method to use for the action. */
27
+ actionMethod: PropTypes.string,
26
28
  /** URL to send the action to. */
27
29
  actionUrl: PropTypes.string.isRequired,
28
30
  /** Title of the modal. */
@@ -41,6 +43,7 @@ ActionButtonWithModal.propTypes = {
41
43
 
42
44
  function ActionButtonWithModal({
43
45
  actionTrigger: ActionTriggerComponent,
46
+ actionMethod = "POST",
44
47
  actionUrl,
45
48
  modalTitle,
46
49
  modalMessage,
@@ -51,24 +54,43 @@ function ActionButtonWithModal({
51
54
  }) {
52
55
  const [triggered, setTriggered] = useState(false);
53
56
  const [modalShown, setModalShown] = useState(false);
54
- const [triggerActionStatus, triggerAction] = useAPIPost(actionUrl);
57
+ const [triggerPostActionStatus, triggerPostAction] = useAPIPost(actionUrl);
58
+ const [triggerPutActionStatus, triggerPutAction] = useAPIPut(actionUrl);
55
59
 
56
60
  const [setAlert] = useAlert();
57
61
  useEffect(() => {
58
- if (triggerActionStatus.state === API_STATE.SUCCESS) {
62
+ if (
63
+ triggerPostActionStatus.state === API_STATE.SUCCESS ||
64
+ triggerPutActionStatus.state === API_STATE.SUCCESS
65
+ ) {
59
66
  setAlert(
60
67
  successMessage || _("Action successful."),
61
68
  API_STATE.SUCCESS
62
69
  );
70
+ setTriggered(false);
63
71
  }
64
- if (triggerActionStatus.state === API_STATE.ERROR) {
72
+ if (
73
+ triggerPostActionStatus.state === API_STATE.ERROR ||
74
+ triggerPutActionStatus.state === API_STATE.ERROR
75
+ ) {
65
76
  setAlert(errorMessage || _("Action failed."));
77
+ setTriggered(false);
66
78
  }
67
- }, [triggerActionStatus, setAlert, successMessage, errorMessage]);
79
+ }, [
80
+ triggerPostActionStatus,
81
+ triggerPutActionStatus,
82
+ setAlert,
83
+ successMessage,
84
+ errorMessage,
85
+ ]);
68
86
 
69
87
  const actionHandler = () => {
70
88
  setTriggered(true);
71
- triggerAction();
89
+ if (actionMethod === "POST") {
90
+ triggerPostAction();
91
+ } else {
92
+ triggerPutAction();
93
+ }
72
94
  setModalShown(false);
73
95
  };
74
96
 
package/foris-6.6.2.tgz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foris",
3
- "version": "6.6.2-beta.0a839bf3",
3
+ "version": "6.6.2-beta.13ca7454",
4
4
  "description": "Foris JS library is a set of components and utils for reForis application and plugins.",
5
5
  "author": "CZ.NIC, z.s.p.o.",
6
6
  "repository": {