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