@sigtes/ui 0.2.2 → 0.2.3

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/hooks.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),n=require("sonner"),d=require("react-hook-form"),m=require("./UserProvider-Sov75KqP.cjs");require("@tanstack/react-query");function p(t){if(typeof t!="object"||t===null)return!1;const e=t;return"name"in e&&typeof e.name=="number"&&"message"in e&&typeof e.message=="string"&&"action"in e&&typeof e.action=="string"&&"statusCode"in e&&typeof e.statusCode=="number"}function g(t,e){if(p(e)){n.toast.error(e.message);return}if(e===!0){n.toast.success(t.message);return}n.toast.error(t.errorMessage)}function b(t){t instanceof Error?n.toast.error("Falha na solicitação.",{description:`${t.name} | ${t.message}`}):n.toast.error("Erro desconhecido.")}const E={handleApiReponse:g,handleApiError:b};function h(t){const[e,s]=i.useState(!1),[o,r]=i.useState(!1),[c,a]=i.useState(t);function u(f){const l={create:()=>{s(!0),r(!1)},edit:()=>{s(!0),r(!0)}}[f];l()}return{open:u,setData:a,currentState:{data:c,isEditMode:o,isVisible:e,setIsVisible:s},controls:{onCreate:()=>u("create"),onUpdate:()=>u("edit"),setData:a}}}const y="/forbidden";function S(t,e,s=""){const{user:o,isLoading:r}=m.useUser();i.useEffect(()=>{e&&o.id===""&&!r&&e.push("/login"),e&&o.id!==""&&!r&&(o.features.includes(t)?e.push(s):e.push(y))},[e,o,r,t,s])}Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>d.useForm});exports.useAuthorization=S;exports.useErrors=E;exports.useFormState=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),r=require("sonner"),m=require("react-hook-form"),p=require("./UserProvider-Sov75KqP.cjs");require("@tanstack/react-query");function c(t){if(typeof t!="object"||t===null)return!1;const e=t;return"name"in e&&typeof e.name=="string"&&"message"in e&&typeof e.message=="string"&&"action"in e&&typeof e.action=="string"&&"statusCode"in e&&typeof e.statusCode=="number"}function g(t,e){if(c(e)){r.toast.error(e.message);return}if(e){r.toast.success(t.message);return}r.toast.error(t.errorMessage)}function b(t){c(t)?r.toast.error("Falha na solicitação.",{description:`${t.name} | ${t.message}`}):r.toast.error("Erro desconhecido.")}const E={handleApiReponse:g,handleApiError:b};function h(t){const[e,s]=i.useState(!1),[o,n]=i.useState(!1),[f,a]=i.useState(t);function u(l){const d={create:()=>{s(!0),n(!1)},edit:()=>{s(!0),n(!0)}}[l];d()}return{open:u,setData:a,currentState:{data:f,isEditMode:o,isVisible:e,setIsVisible:s},controls:{onCreate:()=>u("create"),onUpdate:()=>u("edit"),setData:a}}}const y="/forbidden";function S(t,e,s=""){const{user:o,isLoading:n}=p.useUser();i.useEffect(()=>{e&&o.id===""&&!n&&e.push("/login"),e&&o.id!==""&&!n&&(o.features.includes(t)?e.push(s):e.push(y))},[e,o,n,t,s])}Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>m.useForm});exports.useAuthorization=S;exports.useErrors=E;exports.useFormState=h;
package/dist/hooks.es.js CHANGED
@@ -1,67 +1,67 @@
1
- import { useState as c, useEffect as p } from "react";
2
- import { toast as r } from "sonner";
1
+ import { useState as c, useEffect as l } from "react";
2
+ import { toast as i } from "sonner";
3
3
  import { useForm as U } from "react-hook-form";
4
- import { u as l } from "./UserProvider-ultyW1kJ.js";
4
+ import { u as d } from "./UserProvider-ultyW1kJ.js";
5
5
  import "@tanstack/react-query";
6
- function d(s) {
6
+ function a(s) {
7
7
  if (typeof s != "object" || s === null)
8
8
  return !1;
9
9
  const e = s;
10
- return "name" in e && typeof e.name == "number" && "message" in e && typeof e.message == "string" && "action" in e && typeof e.action == "string" && "statusCode" in e && typeof e.statusCode == "number";
10
+ return "name" in e && typeof e.name == "string" && "message" in e && typeof e.message == "string" && "action" in e && typeof e.action == "string" && "statusCode" in e && typeof e.statusCode == "number";
11
11
  }
12
12
  function g(s, e) {
13
- if (d(e)) {
14
- r.error(e.message);
13
+ if (a(e)) {
14
+ i.error(e.message);
15
15
  return;
16
16
  }
17
- if (e === !0) {
18
- r.success(s.message);
17
+ if (e) {
18
+ i.success(s.message);
19
19
  return;
20
20
  }
21
- r.error(s.errorMessage);
21
+ i.error(s.errorMessage);
22
22
  }
23
23
  function E(s) {
24
- s instanceof Error ? r.error("Falha na solicitação.", {
24
+ a(s) ? i.error("Falha na solicitação.", {
25
25
  description: `${s.name} | ${s.message}`
26
- }) : r.error("Erro desconhecido.");
26
+ }) : i.error("Erro desconhecido.");
27
27
  }
28
28
  const A = {
29
29
  handleApiReponse: g,
30
30
  handleApiError: E
31
31
  };
32
32
  function D(s) {
33
- const [e, t] = c(!1), [n, o] = c(!1), [a, u] = c(s);
34
- function i(f) {
35
- const m = {
33
+ const [e, t] = c(!1), [n, o] = c(!1), [f, u] = c(s);
34
+ function r(m) {
35
+ const p = {
36
36
  create: () => {
37
37
  t(!0), o(!1);
38
38
  },
39
39
  edit: () => {
40
40
  t(!0), o(!0);
41
41
  }
42
- }[f];
43
- m();
42
+ }[m];
43
+ p();
44
44
  }
45
45
  return {
46
- open: i,
46
+ open: r,
47
47
  setData: u,
48
48
  currentState: {
49
- data: a,
49
+ data: f,
50
50
  isEditMode: n,
51
51
  isVisible: e,
52
52
  setIsVisible: t
53
53
  },
54
54
  controls: {
55
- onCreate: () => i("create"),
56
- onUpdate: () => i("edit"),
55
+ onCreate: () => r("create"),
56
+ onUpdate: () => r("edit"),
57
57
  setData: u
58
58
  }
59
59
  };
60
60
  }
61
61
  const h = "/forbidden";
62
62
  function M(s, e, t = "") {
63
- const { user: n, isLoading: o } = l();
64
- p(() => {
63
+ const { user: n, isLoading: o } = d();
64
+ l(() => {
65
65
  e && n.id === "" && !o && e.push("/login"), e && n.id !== "" && !o && (n.features.includes(s) ? e.push(t) : e.push(h));
66
66
  }, [e, n, o, s, t]);
67
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigtes/ui",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {