@arkyn/components 3.0.10 → 3.0.11

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.
@@ -2,46 +2,45 @@ import { badResponses as e } from "../templates/badResponses.js";
2
2
  import { successResponses as t } from "../templates/successResponses.js";
3
3
  import { useModal as n } from "./useModal.js";
4
4
  import { useToast as r } from "./useToast.js";
5
- import { useCallback as i, useEffect as a } from "react";
6
- import { scroller as o } from "react-scroll";
5
+ import { useEffect as i } from "react";
6
+ import { scroller as a } from "react-scroll";
7
7
  //#region src/hooks/useAutomation.ts
8
- function s(s) {
9
- let { closeAll: c } = n(), { showToast: l } = r(), u = s?.closeModal, d = s?.message, f = s?.name, p = s?.cause?.data?.scrollTo, m = s?.cause?.fieldErrors ? Object.values(s?.cause?.fieldErrors)[0] : null, h = i(() => {
10
- if (!(!d && !m)) {
11
- if (t.includes(f)) return l({
12
- message: d,
13
- type: "success"
14
- });
15
- if (e.includes(f)) {
16
- if (m) return l({
17
- message: m,
18
- type: "danger"
8
+ function o(o) {
9
+ let { closeAll: s } = n(), { showToast: c } = r();
10
+ i(() => {
11
+ let n = o?.closeModal, r = o?.message, i = o?.name, l = o?.cause?.data?.scrollTo, u = o?.cause?.fieldErrors ? Object.values(o?.cause?.fieldErrors)[0] : null;
12
+ if (n && s(), l && a.scrollTo(l, {
13
+ smooth: !0,
14
+ offset: 20
15
+ }), !(!r && !u)) {
16
+ if (t.includes(i)) {
17
+ c({
18
+ message: r,
19
+ type: "success"
19
20
  });
20
- if (d !== "Unprocessable entity") return l({
21
- message: d,
21
+ return;
22
+ }
23
+ if (e.includes(i)) {
24
+ if (u) {
25
+ c({
26
+ message: u,
27
+ type: "danger"
28
+ });
29
+ return;
30
+ }
31
+ r !== "Unprocessable entity" && c({
32
+ message: r,
22
33
  type: "danger"
23
34
  });
24
35
  }
25
36
  }
26
37
  }, [
27
- d,
28
- m,
29
- f,
30
- l
31
- ]);
32
- a(() => {
33
- u && c(), p && o.scrollTo(p, {
34
- smooth: !0,
35
- offset: 20
36
- }), h();
37
- }, [
38
- u,
39
- p,
40
- h,
38
+ o,
39
+ s,
41
40
  c
42
41
  ]);
43
42
  }
44
43
  //#endregion
45
- export { s as useAutomation };
44
+ export { o as useAutomation };
46
45
 
47
46
  //# sourceMappingURL=useAutomation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAutomation.js","names":[],"sources":["../../../src/hooks/useAutomation.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\nimport { scroller } from \"react-scroll\";\nimport { badResponses } from \"../templates/badResponses\";\nimport { successResponses } from \"../templates/successResponses\";\nimport { useModal } from \"./useModal\";\nimport { useToast } from \"./useToast\";\n\n/**\n * useAutomation, runs UI side-effects (close modals, scroll, toast) in response to a server action payload.\n *\n * Pass the raw response from a form submission. On every change the hook:\n * 1. Closes all open modals if `closeModal` is `true`.\n * 2. Smooth-scrolls to a named element if `cause.data.scrollTo` is set.\n * 3. Shows a toast based on `name` (matched against `successResponses`/`badResponses`) and `message`.\n * When `cause.fieldErrors` is present, the first field error takes priority in the toast.\n * The message `\"Unprocessable entity\"` is intentionally suppressed.\n *\n * @param formResponseData - Raw server response payload.\n * @param formResponseData.closeModal - Closes all open modals when `true`.\n * @param formResponseData.name - Response identifier matched against success/bad response lists.\n * @param formResponseData.message - Text shown in the toast notification.\n * @param formResponseData.cause.data.scrollTo - Element name to scroll to via `react-scroll`.\n * @param formResponseData.cause.fieldErrors - Field-level errors; the first value is shown in the toast.\n *\n * @example\n * ```tsx\n * // After a successful create action\n * useAutomation({ closeModal: true, name: \"created\", message: \"Saved successfully\" });\n * ```\n *\n * @example\n * ```tsx\n * // Validation error with field-level feedback and scroll\n * useAutomation({\n * name: \"validation_error\",\n * message: \"Invalid payload\",\n * cause: {\n * data: { scrollTo: \"email\" },\n * fieldErrors: { email: \"E-mail is required\" },\n * },\n * });\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nfunction useAutomation(formResponseData: any) {\n\tconst { closeAll } = useModal();\n\tconst { showToast } = useToast();\n\n\tconst closeModal = formResponseData?.closeModal;\n\tconst message = formResponseData?.message;\n\tconst name = formResponseData?.name;\n\tconst scrollTo = formResponseData?.cause?.data?.scrollTo;\n\tconst firstErrorField = formResponseData?.cause?.fieldErrors\n\t\t? (Object.values(formResponseData?.cause?.fieldErrors)[0] as string)\n\t\t: null;\n\n\tconst fireToast = useCallback(() => {\n\t\tif (!message && !firstErrorField) return;\n\n\t\tif (successResponses.includes(name))\n\t\t\treturn showToast({ message, type: \"success\" });\n\n\t\tif (!badResponses.includes(name)) return;\n\t\tif (firstErrorField)\n\t\t\treturn showToast({ message: firstErrorField, type: \"danger\" });\n\n\t\tif (message === \"Unprocessable entity\") return;\n\t\treturn showToast({ message, type: \"danger\" });\n\t}, [message, firstErrorField, name, showToast]);\n\n\tuseEffect(() => {\n\t\tif (closeModal) closeAll();\n\t\tif (scrollTo) scroller.scrollTo(scrollTo, { smooth: true, offset: 20 });\n\t\tfireToast();\n\t}, [closeModal, scrollTo, fireToast, closeAll]);\n}\n\nexport { useAutomation };\n"],"mappings":";;;;;;;AA6CA,SAAS,EAAc,GAAuB;CAC7C,IAAM,EAAE,gBAAa,EAAS,GACxB,EAAE,iBAAc,EAAS,GAEzB,IAAa,GAAkB,YAC/B,IAAU,GAAkB,SAC5B,IAAO,GAAkB,MACzB,IAAW,GAAkB,OAAO,MAAM,UAC1C,IAAkB,GAAkB,OAAO,cAC7C,OAAO,OAAO,GAAkB,OAAO,WAAW,CAAC,CAAC,KACrD,MAEG,IAAY,QAAkB;EAC/B,OAAC,KAAW,CAAC,IAEjB;OAAI,EAAiB,SAAS,CAAI,GACjC,OAAO,EAAU;IAAE;IAAS,MAAM;GAAU,CAAC;GAEzC,MAAa,SAAS,CAAI,GAC/B;QAAI,GACH,OAAO,EAAU;KAAE,SAAS;KAAiB,MAAM;IAAS,CAAC;IAE1D,UAAY,wBAChB,OAAO,EAAU;KAAE;KAAS,MAAM;IAAS,CAAC;GAHkB;EAJhB;CAQ/C,GAAG;EAAC;EAAS;EAAiB;EAAM;CAAS,CAAC;CAE9C,QAAgB;EAGf,AAFI,KAAY,EAAS,GACrB,KAAU,EAAS,SAAS,GAAU;GAAE,QAAQ;GAAM,QAAQ;EAAG,CAAC,GACtE,EAAU;CACX,GAAG;EAAC;EAAY;EAAU;EAAW;CAAQ,CAAC;AAC/C"}
1
+ {"version":3,"file":"useAutomation.js","names":[],"sources":["../../../src/hooks/useAutomation.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { scroller } from \"react-scroll\";\nimport { badResponses } from \"../templates/badResponses\";\nimport { successResponses } from \"../templates/successResponses\";\nimport { useModal } from \"./useModal\";\nimport { useToast } from \"./useToast\";\n\n/**\n * useAutomation, runs UI side-effects (close modals, scroll, toast) in response to a server action payload.\n *\n * Pass the raw response from a form submission. On every change the hook:\n * 1. Closes all open modals if `closeModal` is `true`.\n * 2. Smooth-scrolls to a named element if `cause.data.scrollTo` is set.\n * 3. Shows a toast based on `name` (matched against `successResponses`/`badResponses`) and `message`.\n * When `cause.fieldErrors` is present, the first field error takes priority in the toast.\n * The message `\"Unprocessable entity\"` is intentionally suppressed.\n *\n * @param formResponseData - Raw server response payload.\n * @param formResponseData.closeModal - Closes all open modals when `true`.\n * @param formResponseData.name - Response identifier matched against success/bad response lists.\n * @param formResponseData.message - Text shown in the toast notification.\n * @param formResponseData.cause.data.scrollTo - Element name to scroll to via `react-scroll`.\n * @param formResponseData.cause.fieldErrors - Field-level errors; the first value is shown in the toast.\n *\n * @example\n * ```tsx\n * // After a successful create action\n * useAutomation({ closeModal: true, name: \"created\", message: \"Saved successfully\" });\n * ```\n *\n * @example\n * ```tsx\n * // Validation error with field-level feedback and scroll\n * useAutomation({\n * name: \"validation_error\",\n * message: \"Invalid payload\",\n * cause: {\n * data: { scrollTo: \"email\" },\n * fieldErrors: { email: \"E-mail is required\" },\n * },\n * });\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nfunction useAutomation(formResponseData: any) {\n\tconst { closeAll } = useModal();\n\tconst { showToast } = useToast();\n\n\tuseEffect(() => {\n\t\tconst closeModal = formResponseData?.closeModal;\n\t\tconst message = formResponseData?.message;\n\t\tconst name = formResponseData?.name;\n\t\tconst scrollTo = formResponseData?.cause?.data?.scrollTo;\n\t\tconst firstErrorField = formResponseData?.cause?.fieldErrors\n\t\t\t? (Object.values(formResponseData?.cause?.fieldErrors)[0] as string)\n\t\t\t: null;\n\n\t\tif (closeModal) closeAll();\n\t\tif (scrollTo) scroller.scrollTo(scrollTo, { smooth: true, offset: 20 });\n\n\t\tif (!message && !firstErrorField) return;\n\n\t\tif (successResponses.includes(name)) {\n\t\t\tshowToast({ message, type: \"success\" });\n\t\t\treturn;\n\t\t}\n\n\t\tif (!badResponses.includes(name)) return;\n\t\tif (firstErrorField) {\n\t\t\tshowToast({ message: firstErrorField, type: \"danger\" });\n\t\t\treturn;\n\t\t}\n\n\t\tif (message === \"Unprocessable entity\") return;\n\t\tshowToast({ message, type: \"danger\" });\n\t}, [formResponseData, closeAll, showToast]);\n}\n\nexport { useAutomation };\n"],"mappings":";;;;;;;AA6CA,SAAS,EAAc,GAAuB;CAC7C,IAAM,EAAE,gBAAa,EAAS,GACxB,EAAE,iBAAc,EAAS;CAE/B,QAAgB;EACf,IAAM,IAAa,GAAkB,YAC/B,IAAU,GAAkB,SAC5B,IAAO,GAAkB,MACzB,IAAW,GAAkB,OAAO,MAAM,UAC1C,IAAkB,GAAkB,OAAO,cAC7C,OAAO,OAAO,GAAkB,OAAO,WAAW,CAAC,CAAC,KACrD;EAEH,IAAI,KAAY,EAAS,GACrB,KAAU,EAAS,SAAS,GAAU;GAAE,QAAQ;GAAM,QAAQ;EAAG,CAAC,GAElE,GAAC,KAAW,CAAC,IAEjB;OAAI,EAAiB,SAAS,CAAI,GAAG;IACpC,EAAU;KAAE;KAAS,MAAM;IAAU,CAAC;IACtC;GACD;GAEK,MAAa,SAAS,CAAI,GAC/B;QAAI,GAAiB;KACpB,EAAU;MAAE,SAAS;MAAiB,MAAM;KAAS,CAAC;KACtD;IACD;IAEI,MAAY,0BAChB,EAAU;KAAE;KAAS,MAAM;IAAS,CAAC;GAHrC;EANA;CAUD,GAAG;EAAC;EAAkB;EAAU;CAAS,CAAC;AAC3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",