@gustavo-valsechi/client 1.4.6 → 1.4.8

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.
@@ -44,6 +44,7 @@ var Types = __toESM(require("./types"));
44
44
  __reExport(form_exports, require("./types"), module.exports);
45
45
  function Form(props) {
46
46
  const formRef = props.formRef || (0, import_react.useRef)({});
47
+ const [submitting, setSubmitting] = (0, import_react.useState)(false);
47
48
  const setSchema = () => {
48
49
  const schema2 = {};
49
50
  import_lodash.default.forEach(props.inputs, (data) => {
@@ -92,14 +93,27 @@ function Form(props) {
92
93
  }
93
94
  );
94
95
  };
95
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_styles.Container, { ref: formRef, onSubmit: handleSubmit(props.onSubmit), children: [
96
+ const onSubmit = async (data) => {
97
+ if (!props.onSubmit) return;
98
+ setSubmitting(true);
99
+ await props.onSubmit(data);
100
+ setSubmitting(false);
101
+ };
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_styles.Container, { ref: formRef, onSubmit: handleSubmit(onSubmit), children: [
96
103
  import_lodash.default.map(
97
104
  props.inputs,
98
105
  (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Fragment, { children: component(data) }, index)
99
106
  ),
100
107
  import_lodash.default.isArray(props.buttons) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "form-buttons", children: import_lodash.default.map(
101
108
  props.buttons,
102
- (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Types.Button, { ...data }, index)
109
+ (data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
110
+ Types.Button,
111
+ {
112
+ ...data,
113
+ loading: data.type === "submit" ? submitting || !!data.loading : !!data.loading
114
+ },
115
+ index
116
+ )
103
117
  ) })
104
118
  ] });
105
119
  }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import React, { useEffect, useRef } from "react";
3
+ import React, { useEffect, useRef, useState } from "react";
4
4
  import { Container } from "./styles";
5
5
  import { z } from "zod";
6
6
  import { useForm } from "react-hook-form";
@@ -10,6 +10,7 @@ import * as Types from "./types";
10
10
  export * from "./types";
11
11
  function Form(props) {
12
12
  const formRef = props.formRef || useRef({});
13
+ const [submitting, setSubmitting] = useState(false);
13
14
  const setSchema = () => {
14
15
  const schema2 = {};
15
16
  _.forEach(props.inputs, (data) => {
@@ -58,14 +59,27 @@ function Form(props) {
58
59
  }
59
60
  );
60
61
  };
61
- return /* @__PURE__ */ jsxs(Container, { ref: formRef, onSubmit: handleSubmit(props.onSubmit), children: [
62
+ const onSubmit = async (data) => {
63
+ if (!props.onSubmit) return;
64
+ setSubmitting(true);
65
+ await props.onSubmit(data);
66
+ setSubmitting(false);
67
+ };
68
+ return /* @__PURE__ */ jsxs(Container, { ref: formRef, onSubmit: handleSubmit(onSubmit), children: [
62
69
  _.map(
63
70
  props.inputs,
64
71
  (data, index) => /* @__PURE__ */ jsx(React.Fragment, { children: component(data) }, index)
65
72
  ),
66
73
  _.isArray(props.buttons) && /* @__PURE__ */ jsx("div", { className: "form-buttons", children: _.map(
67
74
  props.buttons,
68
- (data, index) => /* @__PURE__ */ jsx(Types.Button, { ...data }, index)
75
+ (data, index) => /* @__PURE__ */ jsx(
76
+ Types.Button,
77
+ {
78
+ ...data,
79
+ loading: data.type === "submit" ? submitting || !!data.loading : !!data.loading
80
+ },
81
+ index
82
+ )
69
83
  ) })
70
84
  ] });
71
85
  }
@@ -40,11 +40,10 @@ var import_lodash = __toESM(require("lodash"));
40
40
  function Button(props) {
41
41
  const [loading, setLoading] = (0, import_react.useState)(false);
42
42
  const onClick = async (e) => {
43
- var _a, _b, _c, _d;
43
+ var _a, _b;
44
44
  if (!props.onClick) return;
45
45
  setLoading(true);
46
- console.log("props.onClick?.constructor?.name", (_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name);
47
- if (((_d = (_c = props.onClick) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name) === "AsyncFunction") {
46
+ if (((_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "AsyncFunction") {
48
47
  await props.onClick(e);
49
48
  } else {
50
49
  props.onClick(e);
@@ -60,7 +59,7 @@ function Button(props) {
60
59
  onClick: async (e) => await onClick(e),
61
60
  ...import_lodash.default.omit(props, ["loading", "type", "onClick"]),
62
61
  children: [
63
- !!props.loading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loading.Loading, {}),
62
+ (loading || !!props.loading) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loading.Loading, {}),
64
63
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: props.label })
65
64
  ]
66
65
  }
@@ -7,11 +7,10 @@ import _ from "lodash";
7
7
  function Button(props) {
8
8
  const [loading, setLoading] = useState(false);
9
9
  const onClick = async (e) => {
10
- var _a, _b, _c, _d;
10
+ var _a, _b;
11
11
  if (!props.onClick) return;
12
12
  setLoading(true);
13
- console.log("props.onClick?.constructor?.name", (_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name);
14
- if (((_d = (_c = props.onClick) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name) === "AsyncFunction") {
13
+ if (((_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "AsyncFunction") {
15
14
  await props.onClick(e);
16
15
  } else {
17
16
  props.onClick(e);
@@ -27,7 +26,7 @@ function Button(props) {
27
26
  onClick: async (e) => await onClick(e),
28
27
  ..._.omit(props, ["loading", "type", "onClick"]),
29
28
  children: [
30
- !!props.loading && /* @__PURE__ */ jsx(Loading, {}),
29
+ (loading || !!props.loading) && /* @__PURE__ */ jsx(Loading, {}),
31
30
  /* @__PURE__ */ jsx("span", { children: props.label })
32
31
  ]
33
32
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./components";
2
2
  export * from "./contexts";
3
+ export * from "./request";
@@ -17,8 +17,10 @@ var interfaces_exports = {};
17
17
  module.exports = __toCommonJS(interfaces_exports);
18
18
  __reExport(interfaces_exports, require("./components"), module.exports);
19
19
  __reExport(interfaces_exports, require("./contexts"), module.exports);
20
+ __reExport(interfaces_exports, require("./request"), module.exports);
20
21
  // Annotate the CommonJS export names for ESM import in node:
21
22
  0 && (module.exports = {
22
23
  ...require("./components"),
23
- ...require("./contexts")
24
+ ...require("./contexts"),
25
+ ...require("./request")
24
26
  });
@@ -1,2 +1,3 @@
1
1
  export * from "./components";
2
2
  export * from "./contexts";
3
+ export * from "./request";
@@ -0,0 +1,13 @@
1
+ export interface ICredentials {
2
+ limit: number;
3
+ offset: number;
4
+ order: {
5
+ [field: string]: "ASC" | "DESC";
6
+ };
7
+ filters: any;
8
+ }
9
+ export interface IPagination {
10
+ content: Array<any>;
11
+ total: number;
12
+ totalPage: number;
13
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var request_exports = {};
16
+ module.exports = __toCommonJS(request_exports);
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",