@ssplib/react-components 0.0.106 → 0.0.108

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.
@@ -115,11 +115,13 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
115
115
  };
116
116
  (0, react_1.useEffect)(() => {
117
117
  const dt = new DataTransfer();
118
- files.forEach((x) => {
118
+ files
119
+ .filter((x) => !filesError.includes(x.id))
120
+ .forEach((x) => {
119
121
  dt.items.add(x.file);
120
122
  });
121
123
  context === null || context === void 0 ? void 0 : context.formSetValue(name, dt.files);
122
- }, [files, context, name]);
124
+ }, [files, context, filesError, name]);
123
125
  (0, react_1.useEffect)(() => {
124
126
  return () => {
125
127
  context.setFilesUid((files) => files.filter((x) => x.CO_TIPO_ARQUIVO !== parseInt(tipoArquivo)));
@@ -130,12 +132,14 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
130
132
  react_1.default.createElement(material_1.Box, { sx: { backgroundColor: '#e2eafc', padding: 1, borderRadius: 1, marginTop: 1 } },
131
133
  react_1.default.createElement("input", Object.assign({ id: name, type: 'file', multiple: multiple }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
132
134
  validate: (v, f) => {
135
+ console.log('dsadsadas 1');
133
136
  if (v.length <= 0 && required)
134
137
  return 'O campo de arquivo é obrigatório';
135
138
  },
136
139
  }), { onChange: onFile, accept: '.pdf', style: { display: 'none' } })),
137
140
  react_1.default.createElement("input", Object.assign({ id: name + 'foto', type: 'file', capture: 'environment', multiple: multiple }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
138
141
  validate: (v, f) => {
142
+ console.log('dsadsadas 2');
139
143
  if (v.length <= 0 && required)
140
144
  return 'O campo de arquivo é obrigatório';
141
145
  },
@@ -155,7 +159,6 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
155
159
  files.length,
156
160
  " arquivo",
157
161
  files.length > 1 && 's'),
158
- (0, lodash_get_1.default)(context === null || context === void 0 ? void 0 : context.errors, name) && (react_1.default.createElement(material_1.Typography, { variant: 'caption', sx: { color: '#e53935' } }, "* O campo de arquivo \u00E9 obrigat\u00F3rio")),
159
162
  files.length > 0 && (react_1.default.createElement(material_1.TableContainer, { component: material_1.Paper },
160
163
  react_1.default.createElement(system_1.Stack, { direction: 'column' }, files.map((x) => (react_1.default.createElement(system_1.Stack, { key: x.name, direction: 'row', justifyContent: 'space-between', padding: 0.5 },
161
164
  react_1.default.createElement(material_1.Box, null,
@@ -163,6 +166,7 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
163
166
  filesLoaded.includes(x.id) ? (react_1.default.createElement(Done_1.default, { sx: { fill: '#06d6a0' } })) : filesError.includes(x.id) ? (react_1.default.createElement(Clear_1.default, { sx: { fill: 'red' } })) : (react_1.default.createElement(material_1.CircularProgress, { size: 22, sx: { color: 'black' } })),
164
167
  react_1.default.createElement(PictureAsPdf_1.default, { color: 'error' }),
165
168
  react_1.default.createElement(material_1.Typography, { fontWeight: 600 }, x.name))),
166
- react_1.default.createElement(material_1.Box, null, (filesLoaded.includes(x.id) || filesError.includes(x.id)) && (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', sx: { textTransform: 'none', backgroundColor: '#d1495b', '&:hover': { backgroundColor: '#c1121f' } }, onClick: (e) => deleteFile(e, x.id), startIcon: react_1.default.createElement(Delete_1.default, null) }, "Remover"))))))))))));
169
+ react_1.default.createElement(material_1.Box, null, (filesLoaded.includes(x.id) || filesError.includes(x.id)) && (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', sx: { textTransform: 'none', backgroundColor: '#d1495b', '&:hover': { backgroundColor: '#c1121f' } }, onClick: (e) => deleteFile(e, x.id), startIcon: react_1.default.createElement(Delete_1.default, null) }, "Remover"))))))))),
170
+ (0, lodash_get_1.default)(context === null || context === void 0 ? void 0 : context.errors, name) && (react_1.default.createElement(material_1.Typography, { variant: 'caption', color: '#e53935', fontWeight: 600, fontSize: 14, paddingTop: 2 }, "* O campo de arquivo \u00E9 obrigat\u00F3rio")))));
167
171
  }
168
172
  exports.default = FileUpload;
@@ -47,18 +47,30 @@ function Table({ columns, fetchFunc, emptyMsg = {
47
47
  const { user, userLoaded } = (0, react_1.useContext)(auth_1.AuthContext);
48
48
  (0, react_1.useEffect)(() => {
49
49
  if (userLoaded || isPublic)
50
- fetchFunc().then((res) => res.json().then((j) => {
51
- if (j.statusCode === 204)
52
- setData({ body: { data: [] } });
53
- else if (j.statusCode === 403)
50
+ fetchFunc()
51
+ .then((res) => {
52
+ if (!res.ok)
54
53
  setError({
55
- status: j.statusCode,
54
+ status: 500,
56
55
  });
57
- else
58
- setData(j);
59
- console.log(j.statusCode);
60
- setIsLoading(false);
61
- }));
56
+ return res.json().then((j) => {
57
+ if (j.statusCode === 204)
58
+ setData({ body: { data: [] } });
59
+ else if (j.statusCode === 403)
60
+ setError({
61
+ status: j.statusCode,
62
+ });
63
+ else
64
+ setData(j);
65
+ console.log(j.statusCode);
66
+ setIsLoading(false);
67
+ });
68
+ })
69
+ .catch((err) => {
70
+ setError({
71
+ status: 500,
72
+ });
73
+ });
62
74
  }, [userLoaded]);
63
75
  const [list, setList] = (0, react_1.useState)([]);
64
76
  //numero de items pra ser mostrado
@@ -206,12 +218,10 @@ function Table({ columns, fetchFunc, emptyMsg = {
206
218
  });
207
219
  const csvData = header + values.join('\n');
208
220
  // download
209
- const a = document.createElement('a');
210
- a.href = 'data:text/csv;charset=utf-8,' + csvData;
211
- a.download = `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`;
212
- document.body.appendChild(a);
213
- a.click();
214
- document.body.removeChild(a);
221
+ var link = window.document.createElement('a');
222
+ link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
223
+ link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
224
+ link.click();
215
225
  }, [list]);
216
226
  const downloadCSVAll = (0, react_1.useCallback)((e) => {
217
227
  e.preventDefault();
@@ -236,12 +246,10 @@ function Table({ columns, fetchFunc, emptyMsg = {
236
246
  .join('\n');
237
247
  const csvData = header + values;
238
248
  // download
239
- const a = document.createElement('a');
240
- a.href = 'data:text/csv;charset=utf-8,' + csvData;
241
- a.download = `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`;
242
- document.body.appendChild(a);
243
- a.click();
244
- document.body.removeChild(a);
249
+ var link = window.document.createElement('a');
250
+ link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
251
+ link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
252
+ link.click();
245
253
  }, [list]);
246
254
  const getStatusMsg = (0, react_1.useCallback)((cod) => {
247
255
  switch (cod) {
@@ -276,7 +284,9 @@ function Table({ columns, fetchFunc, emptyMsg = {
276
284
  }, [data]);
277
285
  if (error)
278
286
  return (react_1.default.createElement(material_1.Box, { bgcolor: '#E2E8F0', padding: 2, marginX: 2 },
279
- react_1.default.createElement(Typography_1.default, { fontSize: 24, textAlign: 'center', fontFamily: 'Inter' }, error.status === 403 && 'Acesso negado')));
287
+ react_1.default.createElement(Typography_1.default, { fontSize: 24, textAlign: 'center', fontFamily: 'Inter' },
288
+ error.status === 403 && 'Acesso negado',
289
+ error.status === 500 && (react_1.default.createElement(material_1.Box, { fontWeight: 500, textAlign: 'center' }, "Lamentavelmente, ocorreu um imprevisto em nosso servidor. Pedimos a sua compreens\u00E3o e solicitamos que aguarde por um momento enquanto verificamos a situa\u00E7\u00E3o.")))));
280
290
  if (isLoading)
281
291
  return (react_1.default.createElement(material_1.Stack, { sx: { height: '100%', width: '100%' }, justifyContent: 'center', alignItems: 'center' },
282
292
  react_1.default.createElement(Typography_1.default, { fontWeight: 600, fontSize: 20, paddingBottom: 2, marginTop: 14 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.106",
3
+ "version": "0.0.108",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",