@sigtes/ui 0.1.0 → 0.2.0

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,19 +1,18 @@
1
1
  type OpenMode = "create" | "edit";
2
- export interface FormStateProps<T> {
3
- dataToUpdate: Partial<T>;
4
- initialData: Partial<T>;
2
+ export interface FormStateProps<TKeys, TData> {
3
+ data: TKeys & Partial<TData>;
5
4
  isVisible: boolean;
6
5
  isEditMode: boolean;
7
6
  setIsVisible: (value: boolean) => void;
8
7
  }
9
- export declare function useFormState<T>(initialData?: Partial<T>): {
8
+ export declare function useFormState<TKeys, TData>(initialData: TKeys & Partial<TData>): {
10
9
  open: (mode: OpenMode) => void;
11
- setDataToUpdate: import('react').Dispatch<import('react').SetStateAction<Partial<T>>>;
12
- currentState: FormStateProps<T>;
10
+ setData: import('react').Dispatch<import('react').SetStateAction<TKeys & Partial<TData>>>;
11
+ currentState: FormStateProps<TKeys, TData>;
13
12
  controls: {
14
13
  onCreate: () => void;
15
14
  onUpdate: () => void;
16
- setDataToUpdate: import('react').Dispatch<import('react').SetStateAction<Partial<T>>>;
15
+ setData: import('react').Dispatch<import('react').SetStateAction<TKeys & Partial<TData>>>;
17
16
  };
18
17
  };
19
18
  export {};
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"),l=require("react-hook-form"),m=require("./UserProvider-Sov75KqP.cjs");require("@tanstack/react-query");function p(e,s){s instanceof Object?"statusCode"in s||s===!0?n.toast.error(e.errorMessage):n.toast.success(e.message):s===!0?n.toast.success(e.message):n.toast.error(e.errorMessage)}function g(e){e instanceof Error?n.toast.error("Falha na solicitação.",{description:`${e.name} | ${e.message}`}):n.toast.error("Erro desconhecido.")}const E={handleApiReponse:p,handleApiError:g};function h(e){const[s,t]=i.useState(!1),[o,r]=i.useState(!1),[c,u]=i.useState(e||{});function a(d){const f={create:()=>{t(!0),r(!1)},edit:()=>{t(!0),r(!0)}}[d];f()}return{open:a,setDataToUpdate:u,currentState:{dataToUpdate:c,isEditMode:o,initialData:e||{},isVisible:s,setIsVisible:t},controls:{onCreate:()=>a("create"),onUpdate:()=>a("edit"),setDataToUpdate:u}}}const S="/forbidden";function b(e,s,t=""){const{user:o,isLoading:r}=m.useUser();i.useEffect(()=>{s&&o.id===""&&!r&&s.push("/login"),s&&o.id!==""&&!r&&(o.features.includes(e)?s.push(t):s.push(S))},[s,o,r,e,t])}Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>l.useForm});exports.useAuthorization=b;exports.useErrors=E;exports.useFormState=h;
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 g(e,s){s instanceof Object?"statusCode"in s||s===!0?n.toast.error(e.errorMessage):n.toast.success(e.message):s===!0?n.toast.success(e.message):n.toast.error(e.errorMessage)}function E(e){e instanceof Error?n.toast.error("Falha na solicitação.",{description:`${e.name} | ${e.message}`}):n.toast.error("Erro desconhecido.")}const h={handleApiReponse:g,handleApiError:E};function p(e){const[s,t]=i.useState(!1),[r,o]=i.useState(!1),[a,c]=i.useState(e);function u(f){const l={create:()=>{t(!0),o(!1)},edit:()=>{t(!0),o(!0)}}[f];l()}return{open:u,setData:c,currentState:{data:a,isEditMode:r,isVisible:s,setIsVisible:t},controls:{onCreate:()=>u("create"),onUpdate:()=>u("edit"),setData:c}}}const S="/forbidden";function b(e,s,t=""){const{user:r,isLoading:o}=m.useUser();i.useEffect(()=>{s&&r.id===""&&!o&&s.push("/login"),s&&r.id!==""&&!o&&(r.features.includes(e)?s.push(t):s.push(S))},[s,r,o,e,t])}Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>d.useForm});exports.useAuthorization=b;exports.useErrors=h;exports.useFormState=p;
package/dist/hooks.es.js CHANGED
@@ -1,9 +1,9 @@
1
- import { useState as c, useEffect as l } from "react";
1
+ import { useState as c, useEffect as d } from "react";
2
2
  import { toast as r } from "sonner";
3
3
  import { useForm as x } from "react-hook-form";
4
- import { u as p } from "./UserProvider-ultyW1kJ.js";
4
+ import { u as m } from "./UserProvider-ultyW1kJ.js";
5
5
  import "@tanstack/react-query";
6
- function m(e, s) {
6
+ function p(e, s) {
7
7
  s instanceof Object ? "statusCode" in s || s === !0 ? r.error(e.errorMessage) : r.success(e.message) : s === !0 ? r.success(e.message) : r.error(e.errorMessage);
8
8
  }
9
9
  function E(e) {
@@ -11,16 +11,14 @@ function E(e) {
11
11
  description: `${e.name} | ${e.message}`
12
12
  }) : r.error("Erro desconhecido.");
13
13
  }
14
- const A = {
15
- handleApiReponse: m,
14
+ const D = {
15
+ handleApiReponse: p,
16
16
  handleApiError: E
17
17
  };
18
- function D(e) {
19
- const [s, t] = c(!1), [o, n] = c(!1), [u, a] = c(
20
- e || {}
21
- );
18
+ function I(e) {
19
+ const [s, t] = c(!1), [o, n] = c(!1), [u, a] = c(e);
22
20
  function i(f) {
23
- const d = {
21
+ const l = {
24
22
  create: () => {
25
23
  t(!0), n(!1);
26
24
  },
@@ -28,35 +26,34 @@ function D(e) {
28
26
  t(!0), n(!0);
29
27
  }
30
28
  }[f];
31
- d();
29
+ l();
32
30
  }
33
31
  return {
34
32
  open: i,
35
- setDataToUpdate: a,
33
+ setData: a,
36
34
  currentState: {
37
- dataToUpdate: u,
35
+ data: u,
38
36
  isEditMode: o,
39
- initialData: e || {},
40
37
  isVisible: s,
41
38
  setIsVisible: t
42
39
  },
43
40
  controls: {
44
41
  onCreate: () => i("create"),
45
42
  onUpdate: () => i("edit"),
46
- setDataToUpdate: a
43
+ setData: a
47
44
  }
48
45
  };
49
46
  }
50
47
  const h = "/forbidden";
51
- function I(e, s, t = "") {
52
- const { user: o, isLoading: n } = p();
53
- l(() => {
48
+ function O(e, s, t = "") {
49
+ const { user: o, isLoading: n } = m();
50
+ d(() => {
54
51
  s && o.id === "" && !n && s.push("/login"), s && o.id !== "" && !n && (o.features.includes(e) ? s.push(t) : s.push(h));
55
52
  }, [s, o, n, e, t]);
56
53
  }
57
54
  export {
58
- I as useAuthorization,
59
- A as useErrors,
55
+ O as useAuthorization,
56
+ D as useErrors,
60
57
  x as useForm,
61
- D as useFormState
58
+ I as useFormState
62
59
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Button, buttonVariants } from './components/button';
2
- export { Table, TableBody, TableCell, TableCaption, TableFooter, TableHead, TableHeader, TableRow, DataTable, DraggableRow, DragHandle, type DataFormProps, type DataTableProps, } from './components/table';
2
+ export { Table, TableBody, TableCell, TableCaption, TableFooter, TableHead, TableHeader, TableRow, DataTable, DraggableRow, DragHandle, type DataTableProps, } from './components/table';
3
3
  export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, DefaultDropdownMenuTrigger, } from './components/dropdown-menu';
4
4
  export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, } from './components/select';
5
5
  export { Input } from './components/input';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigtes/ui",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {