@ssplib/react-components 0.0.95 → 0.0.96

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.
@@ -36,6 +36,7 @@ function FetchAutoComplete({ name, url, title, customLoadingText, shouldRefetch
36
36
  const [loading, setLoading] = (0, react_1.useState)(true);
37
37
  const [list, setList] = (0, react_1.useState)([]);
38
38
  const [loadingText, setLoadingText] = (0, react_1.useState)('Carregando...');
39
+ const [dValue, setDValue] = (0, react_1.useState)(null);
39
40
  const { user } = (0, react_1.useContext)(auth_1.AuthContext);
40
41
  (0, react_1.useEffect)(() => {
41
42
  if (defaultValue) {
@@ -47,9 +48,16 @@ function FetchAutoComplete({ name, url, title, customLoadingText, shouldRefetch
47
48
  }).then((res) => {
48
49
  if (res.ok) {
49
50
  res.json().then((j) => {
50
- setList(j.body.data);
51
- setLoading(false);
52
- context === null || context === void 0 ? void 0 : context.formSetValue(name, j.body.data[defaultValue].id);
51
+ let value = j.body.data.filter((x) => x.id === defaultValue);
52
+ if (value.length > 0) {
53
+ setList(j.body.data);
54
+ setLoading(false);
55
+ context === null || context === void 0 ? void 0 : context.formSetValue(name, defaultValue);
56
+ setDValue(value[0]);
57
+ }
58
+ else {
59
+ setLoadingText('Erro ao carregar dados. Valor inválido');
60
+ }
53
61
  });
54
62
  }
55
63
  else {
@@ -81,7 +89,7 @@ function FetchAutoComplete({ name, url, title, customLoadingText, shouldRefetch
81
89
  }
82
90
  });
83
91
  }
84
- if (defaultValue && list.length <= 0)
92
+ if (defaultValue && list.length <= 0 && !dValue)
85
93
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
86
94
  react_1.default.createElement(material_1.TextField, { size: 'small', fullWidth: true, placeholder: loadingText, disabled: true })));
87
95
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
@@ -92,7 +100,7 @@ function FetchAutoComplete({ name, url, title, customLoadingText, shouldRefetch
92
100
  return 'Este campo é obrigatório';
93
101
  },
94
102
  }), { hidden: true })),
95
- react_1.default.createElement(material_1.Autocomplete, { loading: loading, loadingText: loadingText, options: list, defaultValue: defaultValue ? list[defaultValue] : undefined, isOptionEqualToValue: (op, value) => op.id === value.id, onChange: (e, v) => context === null || context === void 0 ? void 0 : context.formSetValue(name, v ? v.id : ''), renderInput: (params) => {
103
+ react_1.default.createElement(material_1.Autocomplete, { loading: loading, loadingText: loadingText, options: list, defaultValue: dValue, isOptionEqualToValue: (op, value) => op.id === value.id, onChange: (e, v) => context === null || context === void 0 ? void 0 : context.formSetValue(name, v ? v.id : ''), renderInput: (params) => {
96
104
  var _a;
97
105
  return (react_1.default.createElement(material_1.TextField, Object.assign({}, params, { size: 'small', fullWidth: true, placeholder: title, onFocus: onFocus, required: true, error: (0, lodash_get_1.default)(context === null || context === void 0 ? void 0 : context.errors, name) ? true : false, helperText: (_a = (0, lodash_get_1.default)(context === null || context === void 0 ? void 0 : context.errors, name)) === null || _a === void 0 ? void 0 : _a.message })));
98
106
  }, size: 'small', fullWidth: true })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.95",
3
+ "version": "0.0.96",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",