@arkyn/components 3.0.1-beta.91 → 3.0.1-beta.92
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.
- package/dist/bundle.js +175 -164
- package/dist/bundle.umd.cjs +3 -3
- package/dist/hooks/useAutomation.d.ts +17 -22
- package/dist/hooks/useAutomation.d.ts.map +1 -1
- package/dist/hooks/useAutomation.js +30 -26
- package/dist/templates/badResponses.d.ts +3 -0
- package/dist/templates/badResponses.d.ts.map +1 -0
- package/dist/templates/badResponses.js +12 -0
- package/dist/templates/successResponses.d.ts +3 -0
- package/dist/templates/successResponses.d.ts.map +1 -0
- package/dist/templates/successResponses.js +2 -0
- package/package.json +1 -1
|
@@ -1,45 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hook for automating actions based on form data.
|
|
2
|
+
* Hook for automating actions based on form response data.
|
|
3
3
|
*
|
|
4
|
-
* This hook automates the closing of modals and the display of
|
|
5
|
-
* based on the properties provided in the
|
|
4
|
+
* This hook automates the closing of modals and the display of toast notifications
|
|
5
|
+
* based on the properties provided in the form response data object.
|
|
6
6
|
*
|
|
7
|
-
* @param {Object} formResponseData - Object containing form data for automation
|
|
7
|
+
* @param {Object} formResponseData - Object containing form response data for automation
|
|
8
8
|
* @param {boolean} [formResponseData.closeModal] - If true, closes all open modals
|
|
9
|
-
* @param {string} [formResponseData.message] - Message to be displayed in the
|
|
10
|
-
* @param {
|
|
9
|
+
* @param {string} [formResponseData.message] - Message to be displayed in the toast notification
|
|
10
|
+
* @param {string} [formResponseData.name] - Response name used to check against known error responses
|
|
11
|
+
* @param {"success" | "danger"} [formResponseData.type] - Type of toast notification to be displayed
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```tsx
|
|
14
|
-
* //
|
|
15
|
-
* const
|
|
15
|
+
* // Complete usage with success notification
|
|
16
|
+
* const responseData = {
|
|
16
17
|
* closeModal: true,
|
|
17
|
-
* message: "Operation successfully
|
|
18
|
+
* message: "Operation completed successfully!",
|
|
18
19
|
* type: "success"
|
|
19
20
|
* };
|
|
20
21
|
*
|
|
21
|
-
* useAutomation(
|
|
22
|
+
* useAutomation(responseData);
|
|
22
23
|
* ```
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* ```tsx
|
|
26
|
-
* //
|
|
27
|
-
*
|
|
28
|
-
* closeModal: true
|
|
29
|
-
* };
|
|
30
|
-
*
|
|
31
|
-
* useAutomation(formResponseData);
|
|
27
|
+
* // Close modal only
|
|
28
|
+
* useAutomation({ closeModal: true });
|
|
32
29
|
* ```
|
|
33
30
|
*
|
|
34
31
|
* @example
|
|
35
32
|
* ```tsx
|
|
36
|
-
* //
|
|
37
|
-
*
|
|
33
|
+
* // Display error notification
|
|
34
|
+
* useAutomation({
|
|
38
35
|
* message: "Error processing request",
|
|
39
|
-
* type: "danger"
|
|
40
|
-
* };
|
|
41
|
-
*
|
|
42
|
-
* useAutomation(formResponseData);
|
|
36
|
+
* type: "danger"
|
|
37
|
+
* });
|
|
43
38
|
* ```
|
|
44
39
|
*/
|
|
45
40
|
declare function useAutomation(formResponseData: any): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,iBAAS,aAAa,CAAC,gBAAgB,EAAE,GAAG,QAmB3C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,48 +1,45 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
import { useModal } from "./useModal";
|
|
3
3
|
import { useToast } from "./useToast";
|
|
4
|
+
import { badResponses } from "../templates/badResponses";
|
|
5
|
+
import { successResponses } from "../templates/successResponses";
|
|
4
6
|
/**
|
|
5
|
-
* Hook for automating actions based on form data.
|
|
7
|
+
* Hook for automating actions based on form response data.
|
|
6
8
|
*
|
|
7
|
-
* This hook automates the closing of modals and the display of
|
|
8
|
-
* based on the properties provided in the
|
|
9
|
+
* This hook automates the closing of modals and the display of toast notifications
|
|
10
|
+
* based on the properties provided in the form response data object.
|
|
9
11
|
*
|
|
10
|
-
* @param {Object} formResponseData - Object containing form data for automation
|
|
12
|
+
* @param {Object} formResponseData - Object containing form response data for automation
|
|
11
13
|
* @param {boolean} [formResponseData.closeModal] - If true, closes all open modals
|
|
12
|
-
* @param {string} [formResponseData.message] - Message to be displayed in the
|
|
13
|
-
* @param {
|
|
14
|
+
* @param {string} [formResponseData.message] - Message to be displayed in the toast notification
|
|
15
|
+
* @param {string} [formResponseData.name] - Response name used to check against known error responses
|
|
16
|
+
* @param {"success" | "danger"} [formResponseData.type] - Type of toast notification to be displayed
|
|
14
17
|
*
|
|
15
18
|
* @example
|
|
16
19
|
* ```tsx
|
|
17
|
-
* //
|
|
18
|
-
* const
|
|
20
|
+
* // Complete usage with success notification
|
|
21
|
+
* const responseData = {
|
|
19
22
|
* closeModal: true,
|
|
20
|
-
* message: "Operation successfully
|
|
23
|
+
* message: "Operation completed successfully!",
|
|
21
24
|
* type: "success"
|
|
22
25
|
* };
|
|
23
26
|
*
|
|
24
|
-
* useAutomation(
|
|
27
|
+
* useAutomation(responseData);
|
|
25
28
|
* ```
|
|
26
29
|
*
|
|
27
30
|
* @example
|
|
28
31
|
* ```tsx
|
|
29
|
-
* //
|
|
30
|
-
*
|
|
31
|
-
* closeModal: true
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
* useAutomation(formResponseData);
|
|
32
|
+
* // Close modal only
|
|
33
|
+
* useAutomation({ closeModal: true });
|
|
35
34
|
* ```
|
|
36
35
|
*
|
|
37
36
|
* @example
|
|
38
37
|
* ```tsx
|
|
39
|
-
* //
|
|
40
|
-
*
|
|
38
|
+
* // Display error notification
|
|
39
|
+
* useAutomation({
|
|
41
40
|
* message: "Error processing request",
|
|
42
|
-
* type: "danger"
|
|
43
|
-
* };
|
|
44
|
-
*
|
|
45
|
-
* useAutomation(formResponseData);
|
|
41
|
+
* type: "danger"
|
|
42
|
+
* });
|
|
46
43
|
* ```
|
|
47
44
|
*/
|
|
48
45
|
function useAutomation(formResponseData) {
|
|
@@ -50,14 +47,21 @@ function useAutomation(formResponseData) {
|
|
|
50
47
|
const { showToast } = useToast();
|
|
51
48
|
const closeModal = formResponseData?.closeModal;
|
|
52
49
|
const message = formResponseData?.message;
|
|
50
|
+
const name = formResponseData?.name;
|
|
53
51
|
const type = formResponseData?.type;
|
|
54
52
|
useEffect(() => {
|
|
55
53
|
if (closeModal)
|
|
56
54
|
closeAll();
|
|
57
|
-
if (message
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
if (message) {
|
|
56
|
+
if (type === "success")
|
|
57
|
+
showToast({ message, type: "success" });
|
|
58
|
+
if (type === "danger")
|
|
59
|
+
showToast({ message, type: "danger" });
|
|
60
|
+
if (badResponses.includes(name))
|
|
61
|
+
showToast({ message, type: "danger" });
|
|
62
|
+
if (successResponses.includes(name))
|
|
63
|
+
showToast({ message, type: "success" });
|
|
64
|
+
}
|
|
61
65
|
}, [formResponseData]);
|
|
62
66
|
}
|
|
63
67
|
export { useAutomation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badResponses.d.ts","sourceRoot":"","sources":["../../src/templates/badResponses.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY,UAUjB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successResponses.d.ts","sourceRoot":"","sources":["../../src/templates/successResponses.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,UAA6C,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|