@ssplib/react-components 0.0.41 → 0.0.43

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,7 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export declare function File({ title, name, md, fileURL, fileExt }: {
3
3
  title: string;
4
- id: number;
5
4
  fileURL: string;
6
5
  name: string;
7
6
  md?: number;
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
- export default function AutoComplete({ name, required, title, customPlaceholder, url, xs, sm, md, }: {
2
+ export default function AutoComplete({ name, required, title, customPlaceholder, url, xs, sm, md, dataPath, }: {
3
3
  url: string;
4
4
  name: string;
5
5
  title?: string;
6
+ dataPath?: string;
6
7
  customPlaceholder?: string;
7
8
  required?: boolean;
8
9
  xs?: number;
@@ -33,7 +33,7 @@ const react_1 = __importStar(require("react"));
33
33
  const react_query_1 = require("react-query");
34
34
  const auth_1 = require("../../../context/auth");
35
35
  const form_1 = require("../../../context/form");
36
- function AutoComplete({ name, required = false, title, customPlaceholder, url, xs = 12, sm, md, }) {
36
+ function AutoComplete({ name, required = false, title, customPlaceholder, url, xs = 12, sm, md, dataPath = '', }) {
37
37
  const context = (0, react_1.useContext)(form_1.FormContext);
38
38
  const { user } = (0, react_1.useContext)(auth_1.AuthContext);
39
39
  const [options, setOptions] = (0, react_1.useState)([]);
@@ -41,7 +41,14 @@ function AutoComplete({ name, required = false, title, customPlaceholder, url, x
41
41
  headers: {
42
42
  Authorization: `Bearer ${user ? user.token : ''}`,
43
43
  },
44
- }).then((x) => x.json().then((list) => setOptions(list.body.data))));
44
+ }).then((x) => x.json().then((list) => setOptions(getData(list)))));
45
+ // transformar isso em um component ou utils
46
+ const getData = (0, react_1.useCallback)((dt) => {
47
+ if (Array.isArray(dt))
48
+ return dt;
49
+ if (typeof dt === 'object')
50
+ return (0, lodash_get_1.default)(dt, dataPath);
51
+ }, []);
45
52
  const onSelect = (0, react_1.useCallback)((e, value) => {
46
53
  context === null || context === void 0 ? void 0 : context.formSetValue(name, value ? value.id : '');
47
54
  context === null || context === void 0 ? void 0 : context.formTrigger(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",