@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.
@@ -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 giveaways
5
- * based on the properties provided in the formResponseData object.
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 giveaway
10
- * @param {"success" | "danger"} [formResponseData.type] - Type of giveaway to be displayed
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
- * // Basic usage example
15
- * const formResponseData = {
15
+ * // Complete usage with success notification
16
+ * const responseData = {
16
17
  * closeModal: true,
17
- * message: "Operation successfully completed!",
18
+ * message: "Operation completed successfully!",
18
19
  * type: "success"
19
20
  * };
20
21
  *
21
- * useAutomation(formResponseData);
22
+ * useAutomation(responseData);
22
23
  * ```
23
24
  *
24
25
  * @example
25
26
  * ```tsx
26
- * // Use with only modal closing
27
- * const formResponseData = {
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
- * // Use with only error message display
37
- * const formResponseData = {
33
+ * // Display error notification
34
+ * useAutomation({
38
35
  * message: "Error processing request",
39
- * type: "danger" // "success" | "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":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,iBAAS,aAAa,CAAC,gBAAgB,EAAE,GAAG,QAa3C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
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 giveaways
8
- * based on the properties provided in the formResponseData object.
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 giveaway
13
- * @param {"success" | "danger"} [formResponseData.type] - Type of giveaway to be displayed
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
- * // Basic usage example
18
- * const formResponseData = {
20
+ * // Complete usage with success notification
21
+ * const responseData = {
19
22
  * closeModal: true,
20
- * message: "Operation successfully completed!",
23
+ * message: "Operation completed successfully!",
21
24
  * type: "success"
22
25
  * };
23
26
  *
24
- * useAutomation(formResponseData);
27
+ * useAutomation(responseData);
25
28
  * ```
26
29
  *
27
30
  * @example
28
31
  * ```tsx
29
- * // Use with only modal closing
30
- * const formResponseData = {
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
- * // Use with only error message display
40
- * const formResponseData = {
38
+ * // Display error notification
39
+ * useAutomation({
41
40
  * message: "Error processing request",
42
- * type: "danger" // "success" | "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 && type === "success")
58
- showToast({ message, type: "success" });
59
- if (message && type === "danger")
60
- showToast({ message, type: "danger" });
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,3 @@
1
+ declare const badResponses: string[];
2
+ export { badResponses };
3
+ //# sourceMappingURL=badResponses.d.ts.map
@@ -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,12 @@
1
+ const badResponses = [
2
+ "BadGateway",
3
+ "BadRequest",
4
+ "Conflict",
5
+ "Forbidden",
6
+ "NotFound",
7
+ "NotImplemented",
8
+ "ServerError",
9
+ "Unauthorized",
10
+ "UnprocessableEntity",
11
+ ];
12
+ export { badResponses };
@@ -0,0 +1,3 @@
1
+ declare const successResponses: string[];
2
+ export { successResponses };
3
+ //# sourceMappingURL=successResponses.d.ts.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ const successResponses = ["Created", "Found", "Success", "Updated"];
2
+ export { successResponses };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "3.0.1-beta.91",
3
+ "version": "3.0.1-beta.92",
4
4
  "main": "./dist/bundle.js",
5
5
  "module": "./dist/bundle.js",
6
6
  "types": "./dist/index.d.ts",