@ssplib/react-components 0.0.248 → 0.0.249
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.
- package/package.json +2 -2
- package/src/components/detalhes/Category.js +7 -0
- package/src/components/detalhes/Field.js +35 -0
- package/src/components/detalhes/FieldLabel.js +21 -0
- package/src/components/detalhes/File.js +35 -0
- package/src/components/form/checkbox/CheckBox.js +12 -0
- package/{components → src/components}/form/checkbox/CheckBoxAdditional.js +11 -37
- package/src/components/form/checkbox/CheckBoxWarning.js +14 -0
- package/src/components/form/checkbox/RequiredCheckBoxValidator.js +56 -0
- package/src/components/form/date/DatePicker.js +71 -0
- package/src/components/form/date/TimePicker.js +53 -0
- package/src/components/form/file/DropFileUpload.js +207 -0
- package/src/components/form/file/FileUpload.js +171 -0
- package/src/components/form/input/ActiveInput.js +27 -0
- package/src/components/form/input/AutoComplete.js +40 -0
- package/src/components/form/input/FetchAutoComplete.js +103 -0
- package/src/components/form/input/FixedAutoComplete.js +46 -0
- package/{components → src/components}/form/input/Input.js +22 -52
- package/src/components/form/input/MaskInput.js +52 -0
- package/src/components/form/input/MultInput.js +38 -0
- package/src/components/form/input/OtherCheckBox.js +27 -0
- package/src/components/form/stepper/Stepper.js +105 -0
- package/src/components/form/stepper/StepperBlock.js +67 -0
- package/src/components/form/switch/Switch.js +27 -0
- package/src/components/form/switch/ToggleVisibility.js +33 -0
- package/{components → src/components}/form/table/Table.js +200 -230
- package/src/components/icons/icons.js +16 -0
- package/src/components/modal/Modal.js +75 -0
- package/src/components/navbar/NavBar.js +127 -0
- package/src/components/navbar/TabNavBar.js +135 -0
- package/src/components/providers/FormProvider.js +23 -0
- package/src/components/providers/KeycloakAuthProvider.js +69 -0
- package/{components → src/components}/providers/OAuthProvider.js +19 -49
- package/src/components/providers/SspComponentsProvider.js +11 -0
- package/{components → src/components}/utils/Bt.js +7 -13
- package/src/components/utils/CustomMenu.js +33 -0
- package/src/context/auth.js +2 -0
- package/{context → src/context}/form.d.ts +2 -3
- package/src/context/form.js +2 -0
- package/src/index.js +41 -0
- package/src/types/auth.js +1 -0
- package/{types → src/types}/form.js +4 -7
- package/components/detalhes/Category.js +0 -14
- package/components/detalhes/Field.js +0 -42
- package/components/detalhes/FieldLabel.js +0 -28
- package/components/detalhes/File.js +0 -62
- package/components/form/checkbox/CheckBox.js +0 -18
- package/components/form/checkbox/CheckBoxWarning.js +0 -43
- package/components/form/checkbox/RequiredCheckBoxValidator.js +0 -85
- package/components/form/date/DatePicker.js +0 -100
- package/components/form/date/TimePicker.js +0 -82
- package/components/form/file/DropFileUpload.js +0 -236
- package/components/form/file/FileUpload.js +0 -200
- package/components/form/input/ActiveInput.js +0 -33
- package/components/form/input/AutoComplete.js +0 -69
- package/components/form/input/FetchAutoComplete.js +0 -132
- package/components/form/input/FixedAutoComplete.js +0 -76
- package/components/form/input/MaskInput.js +0 -78
- package/components/form/input/MultInput.js +0 -67
- package/components/form/input/OtherCheckBox.js +0 -56
- package/components/form/stepper/Stepper.js +0 -135
- package/components/form/stepper/StepperBlock.js +0 -97
- package/components/form/switch/Switch.js +0 -54
- package/components/form/switch/ToggleVisibility.js +0 -61
- package/components/icons/icons.js +0 -24
- package/components/modal/Modal.js +0 -105
- package/components/navbar/NavBar.js +0 -156
- package/components/navbar/TabNavBar.js +0 -164
- package/components/providers/FormProvider.js +0 -49
- package/components/providers/KeycloakAuthProvider.js +0 -98
- package/components/providers/SspComponentsProvider.js +0 -18
- package/components/utils/CustomMenu.js +0 -39
- package/context/auth.js +0 -5
- package/context/form.js +0 -5
- package/index.js +0 -80
- package/types/auth.js +0 -2
- /package/{components → src/components}/detalhes/Category.d.ts +0 -0
- /package/{components → src/components}/detalhes/Field.d.ts +0 -0
- /package/{components → src/components}/detalhes/FieldLabel.d.ts +0 -0
- /package/{components → src/components}/detalhes/File.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/CheckBox.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/CheckBoxAdditional.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/CheckBoxWarning.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/RequiredCheckBoxValidator.d.ts +0 -0
- /package/{components → src/components}/form/date/DatePicker.d.ts +0 -0
- /package/{components → src/components}/form/date/TimePicker.d.ts +0 -0
- /package/{components → src/components}/form/file/DropFileUpload.d.ts +0 -0
- /package/{components → src/components}/form/file/FileUpload.d.ts +0 -0
- /package/{components → src/components}/form/input/ActiveInput.d.ts +0 -0
- /package/{components → src/components}/form/input/AutoComplete.d.ts +0 -0
- /package/{components → src/components}/form/input/FetchAutoComplete.d.ts +0 -0
- /package/{components → src/components}/form/input/FixedAutoComplete.d.ts +0 -0
- /package/{components → src/components}/form/input/Input.d.ts +0 -0
- /package/{components → src/components}/form/input/MaskInput.d.ts +0 -0
- /package/{components → src/components}/form/input/MultInput.d.ts +0 -0
- /package/{components → src/components}/form/input/OtherCheckBox.d.ts +0 -0
- /package/{components → src/components}/form/stepper/Stepper.d.ts +0 -0
- /package/{components → src/components}/form/stepper/StepperBlock.d.ts +0 -0
- /package/{components → src/components}/form/switch/Switch.d.ts +0 -0
- /package/{components → src/components}/form/switch/ToggleVisibility.d.ts +0 -0
- /package/{components → src/components}/form/table/Table.d.ts +0 -0
- /package/{components → src/components}/icons/icons.d.ts +0 -0
- /package/{components → src/components}/modal/Modal.d.ts +0 -0
- /package/{components → src/components}/navbar/NavBar.d.ts +0 -0
- /package/{components → src/components}/navbar/TabNavBar.d.ts +0 -0
- /package/{components → src/components}/providers/FormProvider.d.ts +0 -0
- /package/{components → src/components}/providers/KeycloakAuthProvider.d.ts +0 -0
- /package/{components → src/components}/providers/OAuthProvider.d.ts +0 -0
- /package/{components → src/components}/providers/SspComponentsProvider.d.ts +0 -0
- /package/{components → src/components}/utils/Bt.d.ts +0 -0
- /package/{components → src/components}/utils/CustomMenu.d.ts +0 -0
- /package/{context → src/context}/auth.d.ts +0 -0
- /package/{index.d.ts → src/index.d.ts} +0 -0
- /package/{types → src/types}/auth.d.ts +0 -0
- /package/{types → src/types}/form.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssplib/react-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.249",
|
|
4
4
|
"description": "SSP React Components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Pedro Henrique <sr.hudrick@gmail.com>",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"lodash.hasin": "^4.5.2",
|
|
18
18
|
"react-google-recaptcha": "^2.1.0",
|
|
19
19
|
"jszip": "^3.10.1",
|
|
20
|
-
"keycloak-js": "^
|
|
20
|
+
"keycloak-js": "^26.0.5",
|
|
21
21
|
"react-toastify": "^10.0.4",
|
|
22
22
|
"axios": "^1.6.7",
|
|
23
23
|
"react-dropzone": "^14.2.3"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Grid, Typography, Box } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export function Category({ title }) {
|
|
4
|
+
return (React.createElement(Grid, { paddingY: 1, item: true, marginTop: 1, marginBottom: 3, xs: 12 },
|
|
5
|
+
React.createElement(Typography, { textTransform: 'uppercase', fontWeight: 600 }, title),
|
|
6
|
+
React.createElement(Box, { sx: { backgroundColor: '#94A3B8', height: 6, borderRadius: 1 } })));
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Box, Grid, Stack, Typography } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export function Field({ name, title, tag, xs = 12, md, lg }) {
|
|
4
|
+
let color = tag && tag === 'Distrital'
|
|
5
|
+
? '#BFDBFE'
|
|
6
|
+
: tag === 'Estadual'
|
|
7
|
+
? '#BBF7D0'
|
|
8
|
+
: tag === 'Federal'
|
|
9
|
+
? '#FEF08A'
|
|
10
|
+
: tag === 'Internacional'
|
|
11
|
+
? '#FED7AA'
|
|
12
|
+
: tag === 'Não'
|
|
13
|
+
? '#FECACA'
|
|
14
|
+
: tag === 'Sim'
|
|
15
|
+
? '#BBF7D0'
|
|
16
|
+
: '#BBF7D0';
|
|
17
|
+
return (React.createElement(Grid, Object.assign({ paddingBottom: 3, item: true }, { xs, md, lg }, { paddingRight: 2 }),
|
|
18
|
+
React.createElement(Stack, { spacing: 1 },
|
|
19
|
+
React.createElement(Stack, { spacing: 1, direction: 'row' },
|
|
20
|
+
React.createElement(Typography, { sx: {
|
|
21
|
+
backgroundColor: '#E2E8F0',
|
|
22
|
+
maxWidth: 'max-content',
|
|
23
|
+
paddingX: 1,
|
|
24
|
+
borderRadius: 2,
|
|
25
|
+
color: '#1E293B',
|
|
26
|
+
}, fontWeight: 600 }, title),
|
|
27
|
+
tag && (React.createElement(Typography, { sx: {
|
|
28
|
+
backgroundColor: color,
|
|
29
|
+
maxWidth: 'max-content',
|
|
30
|
+
paddingX: 1,
|
|
31
|
+
borderRadius: 2,
|
|
32
|
+
color: '#1E293B',
|
|
33
|
+
}, fontWeight: 600 }, tag))),
|
|
34
|
+
name && React.createElement(Box, null, String(name) === 'false' ? 'Não' : String(name) === 'true' ? 'Sim' : String(name) === '' ? '' : !name ? 'Não informado' : String(name)))));
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Grid, Stack, Typography } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export function FieldLabel({ title, xs = 12, tag, md, lg, paddingBottom = 3 }) {
|
|
4
|
+
let color = tag && tag === 'Não' ? '#FECACA' : tag === 'Sim' ? '#BBF7D0' : '#E2E8F0';
|
|
5
|
+
return (React.createElement(Grid, Object.assign({ paddingBottom: paddingBottom, item: true }, { xs, md, lg }, { paddingRight: 2 }),
|
|
6
|
+
React.createElement(Stack, { spacing: 1, direction: 'row' },
|
|
7
|
+
React.createElement(Typography, { sx: {
|
|
8
|
+
backgroundColor: '#E2E8F0',
|
|
9
|
+
maxWidth: 'max-content',
|
|
10
|
+
paddingX: 1,
|
|
11
|
+
borderRadius: 2,
|
|
12
|
+
color: '#1E293B',
|
|
13
|
+
}, fontWeight: 600, fontSize: 16 }, title),
|
|
14
|
+
tag && (React.createElement(Typography, { sx: {
|
|
15
|
+
backgroundColor: color,
|
|
16
|
+
maxWidth: 'max-content',
|
|
17
|
+
paddingX: 1,
|
|
18
|
+
borderRadius: 2,
|
|
19
|
+
color: '#1E293B',
|
|
20
|
+
}, fontWeight: 600 }, tag)))));
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Button, Grid, Stack, Typography } from '@mui/material';
|
|
2
|
+
import { FileDownload } from '@mui/icons-material';
|
|
3
|
+
import React, { useContext } from 'react';
|
|
4
|
+
import { AuthContext } from '../../context/auth';
|
|
5
|
+
export function File({ title, name, md, fileURL, fileExt = 'pdf' }) {
|
|
6
|
+
const { user } = useContext(AuthContext);
|
|
7
|
+
return (React.createElement(Grid, Object.assign({ paddingBottom: 3, paddingRight: 3 }, { md }),
|
|
8
|
+
React.createElement(Stack, { spacing: 1, sx: {
|
|
9
|
+
backgroundColor: '#F8FAFC',
|
|
10
|
+
paddingY: 1,
|
|
11
|
+
paddingX: 3,
|
|
12
|
+
borderRadius: 2,
|
|
13
|
+
border: 1,
|
|
14
|
+
borderColor: '#CBD5E1',
|
|
15
|
+
} },
|
|
16
|
+
React.createElement(Typography, { fontWeight: 600, sx: { textAlign: 'center' } }, title),
|
|
17
|
+
React.createElement(Stack, { direction: 'row', spacing: 2, alignItems: 'center' },
|
|
18
|
+
React.createElement(FileDownload, { sx: { fill: 'red' } }),
|
|
19
|
+
React.createElement(Typography, null, name)),
|
|
20
|
+
React.createElement(Stack, { alignItems: 'center' },
|
|
21
|
+
React.createElement(Button, { variant: 'outlined', color: 'error', size: 'small', endIcon: React.createElement(FileDownload, null), onClick: () => fetch(fileURL, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Bearer ${user === null || user === void 0 ? void 0 : user.token}`,
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
.then((res) => res.blob())
|
|
28
|
+
.then((blob) => {
|
|
29
|
+
var file = window.URL.createObjectURL(blob);
|
|
30
|
+
const a = document.createElement('a');
|
|
31
|
+
a.href = file;
|
|
32
|
+
a.download = name.split('.')[0] + `.${fileExt}`;
|
|
33
|
+
a.click();
|
|
34
|
+
}) }, "Baixar")))));
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Checkbox, FormControlLabel, Grid } from '@mui/material';
|
|
2
|
+
import { useCallback, useContext } from 'react';
|
|
3
|
+
import { FormContext } from '../../../context/form';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export default function CheckBox({ name, title, defaultValue = false, xs = 12, sm, md, onChange, }) {
|
|
6
|
+
const context = useContext(FormContext);
|
|
7
|
+
const onClick = useCallback((e) => {
|
|
8
|
+
context === null || context === void 0 ? void 0 : context.formSetValue(name, !(context === null || context === void 0 ? void 0 : context.formGetValues(name)));
|
|
9
|
+
}, [context, name]);
|
|
10
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
11
|
+
React.createElement(FormControlLabel, Object.assign({ control: React.createElement(Checkbox, { size: 'small', defaultChecked: defaultValue }), label: title }, context === null || context === void 0 ? void 0 : context.formRegister(name), { onChange: onChange, onClick: onClick }))));
|
|
12
|
+
}
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
2
|
var t = {};
|
|
27
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -33,10 +9,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
33
9
|
}
|
|
34
10
|
return t;
|
|
35
11
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const material_1 = require("@mui/material");
|
|
12
|
+
import React, { useContext, useState } from 'react';
|
|
13
|
+
import { FormContext } from '../../../context/form';
|
|
14
|
+
import { Grid } from '@mui/material';
|
|
40
15
|
function getChildrenNames(children) {
|
|
41
16
|
let arr = [];
|
|
42
17
|
children.forEach((x) => {
|
|
@@ -54,12 +29,12 @@ function getChildrenNames(children) {
|
|
|
54
29
|
});
|
|
55
30
|
return arr;
|
|
56
31
|
}
|
|
57
|
-
function RequiredCheckBoxAdditional(_a) {
|
|
32
|
+
export default function RequiredCheckBoxAdditional(_a) {
|
|
58
33
|
var { customText = 'Selecione pelo menos 1 opção' } = _a, props = __rest(_a, ["customText"]);
|
|
59
|
-
const [firstTime, setFirstTime] =
|
|
60
|
-
const [showAfterFirst, setAfterFirst] =
|
|
61
|
-
const context =
|
|
62
|
-
const children =
|
|
34
|
+
const [firstTime, setFirstTime] = useState(false);
|
|
35
|
+
const [showAfterFirst, setAfterFirst] = useState(true);
|
|
36
|
+
const context = useContext(FormContext);
|
|
37
|
+
const children = React.cloneElement(props.children, {
|
|
63
38
|
onChange: () => {
|
|
64
39
|
if (firstTime) {
|
|
65
40
|
const name = children.props.name;
|
|
@@ -69,8 +44,8 @@ function RequiredCheckBoxAdditional(_a) {
|
|
|
69
44
|
}
|
|
70
45
|
},
|
|
71
46
|
});
|
|
72
|
-
return (
|
|
73
|
-
|
|
47
|
+
return (React.createElement(Grid, { container: true, sx: { padding: 1, borderRadius: 2 } },
|
|
48
|
+
React.createElement("input", Object.assign({ type: 'text' }, context.formRegister(props.name, {
|
|
74
49
|
validate: (v, f) => {
|
|
75
50
|
if (firstTime && showAfterFirst)
|
|
76
51
|
return true;
|
|
@@ -90,6 +65,5 @@ function RequiredCheckBoxAdditional(_a) {
|
|
|
90
65
|
},
|
|
91
66
|
}), { hidden: true })),
|
|
92
67
|
children,
|
|
93
|
-
|
|
68
|
+
React.createElement(Grid, { item: true, xs: 12 }, firstTime && showAfterFirst && props.content)));
|
|
94
69
|
}
|
|
95
|
-
exports.default = RequiredCheckBoxAdditional;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Card, Checkbox, FormControlLabel, Grid } from '@mui/material';
|
|
2
|
+
import Typography from '@mui/material/Typography';
|
|
3
|
+
import React, { useContext } from 'react';
|
|
4
|
+
import { FormContext } from '../../../context/form';
|
|
5
|
+
export default function CheckBoxWarning({ name, title, customWarning, defaultValue = false, xs = 12, sm, md, }) {
|
|
6
|
+
const context = useContext(FormContext);
|
|
7
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
8
|
+
React.createElement(FormControlLabel, { control: React.createElement(Checkbox, Object.assign({ size: 'small' }, context.formRegister(name), { defaultChecked: defaultValue })), label: title }),
|
|
9
|
+
context.formWatch(name) && (React.createElement(Card, { sx: { bgcolor: '#FFFBF5', color: '#F59E0B', padding: 1, paddingLeft: 2 } }, customWarning ? (customWarning) : (React.createElement(Typography, null,
|
|
10
|
+
React.createElement("b", null, "Aten\u00E7\u00E3o"),
|
|
11
|
+
" ",
|
|
12
|
+
React.createElement("i", null, title),
|
|
13
|
+
" possui regras espec\u00EDficas."))))));
|
|
14
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React, { useContext } from 'react';
|
|
13
|
+
import { FormContext } from '../../../context/form';
|
|
14
|
+
import { Grid, Typography } from '@mui/material';
|
|
15
|
+
import get from 'lodash.get';
|
|
16
|
+
function getChildrenNames(children) {
|
|
17
|
+
let arr = [];
|
|
18
|
+
children.forEach((x) => {
|
|
19
|
+
if (!x.props)
|
|
20
|
+
return;
|
|
21
|
+
if (x.props.children) {
|
|
22
|
+
const childrenArr = getChildrenNames(Array.isArray(x.props.children) ? x.props.children : [x.props.children]);
|
|
23
|
+
arr = arr.concat(childrenArr);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (x.props.name) {
|
|
27
|
+
arr.push(x.props.name);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return arr;
|
|
32
|
+
}
|
|
33
|
+
export default function RequiredCheckBoxGroup(_a) {
|
|
34
|
+
var _b;
|
|
35
|
+
var { customText = 'Selecione pelo menos 1 opção' } = _a, props = __rest(_a, ["customText"]);
|
|
36
|
+
const context = useContext(FormContext);
|
|
37
|
+
return (React.createElement(Grid, { container: true, sx: { border: get(context.errors, props.name) ? '2px solid #a51c30' : '', padding: 1, borderRadius: 2 } },
|
|
38
|
+
React.createElement("input", Object.assign({ key: 1, type: 'text' }, context.formRegister(props.name, {
|
|
39
|
+
validate: (v, i) => {
|
|
40
|
+
const names = getChildrenNames(Array.isArray(props.children) ? props.children : [props.children]);
|
|
41
|
+
let canContinue = false;
|
|
42
|
+
names.forEach((x, i) => {
|
|
43
|
+
const nameValue = context.formGetValues(x);
|
|
44
|
+
if (nameValue) {
|
|
45
|
+
canContinue = true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (!canContinue)
|
|
49
|
+
return customText;
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
}), { hidden: true })),
|
|
53
|
+
props.children,
|
|
54
|
+
React.createElement(Grid, { item: true, xs: 12 },
|
|
55
|
+
React.createElement(Typography, { sx: { color: '#a51c30', fontSize: 16, paddingLeft: 1 } }, (_b = get(context.errors, props.name)) === null || _b === void 0 ? void 0 : _b.message))));
|
|
56
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { Grid, InputLabel, TextField, Typography } from '@mui/material';
|
|
13
|
+
import { LocalizationProvider } from '@mui/x-date-pickers';
|
|
14
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
15
|
+
import { DatePicker as MUIDatePicker } from '@mui/x-date-pickers';
|
|
16
|
+
import dayjs from 'dayjs';
|
|
17
|
+
import 'dayjs/locale/pt-br';
|
|
18
|
+
import get from 'lodash.get';
|
|
19
|
+
import hasIn from 'lodash.hasin';
|
|
20
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
21
|
+
import { FormContext } from '../../../context/form';
|
|
22
|
+
export default function DatePicker(_a) {
|
|
23
|
+
var _b;
|
|
24
|
+
var { name, required = false, title, xs = 12, sm, md, minDt, defaultValue = '', maxDt } = _a, props = __rest(_a, ["name", "required", "title", "xs", "sm", "md", "minDt", "defaultValue", "maxDt"]);
|
|
25
|
+
const context = useContext(FormContext);
|
|
26
|
+
const [value, setValue] = useState(defaultValue ? dayjs(defaultValue, 'DD/MM/YYYY') : null);
|
|
27
|
+
const handleChange = (newValue) => {
|
|
28
|
+
setValue(newValue);
|
|
29
|
+
};
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
context.formSetValue(name, value ? value.format('DD/MM/YYYY') : value);
|
|
32
|
+
}, [value]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
return () => {
|
|
35
|
+
context.formUnregister(name);
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
return (React.createElement(React.Fragment, null,
|
|
39
|
+
React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
40
|
+
title && React.createElement(InputLabel, { required: required }, title),
|
|
41
|
+
React.createElement(LocalizationProvider, { adapterLocale: 'pt-br', dateAdapter: AdapterDayjs },
|
|
42
|
+
React.createElement(MUIDatePicker, { minDate: dayjs(minDt, 'DD/MM/YYYY'), maxDate: dayjs(maxDt, 'DD/MM/YYYY'), format: 'DD/MM/YYYY', value: value, onChange: handleChange, disableHighlightToday: true, sx: {
|
|
43
|
+
outline: get(context.errors, name) ? '1px solid #a51c30' : '',
|
|
44
|
+
backgroundColor: 'white',
|
|
45
|
+
width: '100%',
|
|
46
|
+
div: {
|
|
47
|
+
input: {
|
|
48
|
+
paddingX: 2,
|
|
49
|
+
paddingY: 1.05,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}, inputRef: (params) => (React.createElement(TextField, Object.assign({ size: 'small' }, params, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
53
|
+
validate: (v, f) => {
|
|
54
|
+
if (!hasIn(f, name)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (!v)
|
|
58
|
+
v = '';
|
|
59
|
+
if (v.length <= 0 && required)
|
|
60
|
+
return 'Este campo é obrigatório';
|
|
61
|
+
if (v.length < 10 && required)
|
|
62
|
+
return 'A data precisa seguir o padrão DD/MM/AAAA';
|
|
63
|
+
if (minDt && !(dayjs(minDt, 'DD/MM/YYYY').isSame(dayjs(v, 'DD/MM/YYYY')) || dayjs(minDt, 'DD/MM/YYYY').isBefore(dayjs(v, 'DD/MM/YYYY'))))
|
|
64
|
+
return `A data tem que ser depois de ${minDt} e antes de ${maxDt}`;
|
|
65
|
+
if (maxDt && !(dayjs(maxDt, 'DD/MM/YYYY').isSame(dayjs(v, 'DD/MM/YYYY')) || dayjs(maxDt, 'DD/MM/YYYY').isAfter(dayjs(v, 'DD/MM/YYYY'))))
|
|
66
|
+
return 'A data escolhida não é válida';
|
|
67
|
+
},
|
|
68
|
+
shouldUnregister: true,
|
|
69
|
+
}), { fullWidth: true }))) }),
|
|
70
|
+
React.createElement(Typography, { sx: { color: '#a51c30', fontSize: 14, paddingLeft: 1 } }, (_b = get(context.errors, name)) === null || _b === void 0 ? void 0 : _b.message)))));
|
|
71
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Grid, InputLabel, TextField, Typography } from '@mui/material';
|
|
2
|
+
import { LocalizationProvider, TimePicker as MUITimePicker } from '@mui/x-date-pickers';
|
|
3
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import get from 'lodash.get';
|
|
6
|
+
import 'dayjs/locale/pt-br';
|
|
7
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
8
|
+
import { FormContext } from '../../../context/form';
|
|
9
|
+
import hasIn from 'lodash.hasin';
|
|
10
|
+
export default function TimePicker({ name, required = false, title, defaultValue = '', xs = 12, sm, md, }) {
|
|
11
|
+
var _a;
|
|
12
|
+
const context = useContext(FormContext);
|
|
13
|
+
const [value, setValue] = useState(defaultValue ? dayjs(defaultValue, 'HH:mm') : null);
|
|
14
|
+
const handleChange = (newValue) => {
|
|
15
|
+
setValue(newValue);
|
|
16
|
+
};
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
context.formSetValue(name, value ? value.format('HH:mm') : value);
|
|
19
|
+
}, [value]);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
return () => {
|
|
22
|
+
context.formUnregister(name);
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
26
|
+
title && React.createElement(InputLabel, { required: required }, title),
|
|
27
|
+
React.createElement(LocalizationProvider, { adapterLocale: 'pt-br', dateAdapter: AdapterDayjs },
|
|
28
|
+
React.createElement(MUITimePicker, { value: value, ampm: false, onChange: handleChange, sx: {
|
|
29
|
+
outline: get(context.errors, name) ? '1px solid #a51c30' : '',
|
|
30
|
+
backgroundColor: 'white',
|
|
31
|
+
width: '100%',
|
|
32
|
+
div: {
|
|
33
|
+
input: {
|
|
34
|
+
paddingX: 2,
|
|
35
|
+
paddingY: 1.05,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}, inputRef: (params) => (React.createElement(TextField, Object.assign({ size: 'small' }, params, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
39
|
+
validate: (v, f) => {
|
|
40
|
+
if (!hasIn(f, name)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (!v)
|
|
44
|
+
v = '';
|
|
45
|
+
if (v.length <= 0 && required)
|
|
46
|
+
return 'Este campo é obrigatório';
|
|
47
|
+
if (v.length < 5 && required)
|
|
48
|
+
return 'A hora precisa seguir o padrão HH:MM';
|
|
49
|
+
},
|
|
50
|
+
shouldUnregister: true,
|
|
51
|
+
}), { fullWidth: true }))) }),
|
|
52
|
+
React.createElement(Typography, { sx: { color: '#a51c30', fontSize: 15, paddingLeft: 1 } }, (_a = get(context.errors, name)) === null || _a === void 0 ? void 0 : _a.message))));
|
|
53
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Box, Button, Grid, InputLabel, LinearProgress, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
2
|
+
import { Stack } from '@mui/system';
|
|
3
|
+
import get from 'lodash.get';
|
|
4
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
5
|
+
import { AuthContext } from '../../../context/auth';
|
|
6
|
+
import { FormContext } from '../../../context/form';
|
|
7
|
+
import { useDropzone } from 'react-dropzone';
|
|
8
|
+
import axios from 'axios';
|
|
9
|
+
import { PDFIcon, TrashIcon } from '../../icons/icons';
|
|
10
|
+
function bytesToMegabytes(bytes) {
|
|
11
|
+
const megabytes = bytes / (1024 * 1024);
|
|
12
|
+
return megabytes;
|
|
13
|
+
}
|
|
14
|
+
function bytesToKBorMB(bytes) {
|
|
15
|
+
const KB = 1024;
|
|
16
|
+
const MB = 1024 * KB;
|
|
17
|
+
if (bytes < MB) {
|
|
18
|
+
const KBValue = bytes / KB;
|
|
19
|
+
return `${KBValue.toFixed(1)}KB`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const MBValue = bytes / MB;
|
|
23
|
+
return `${MBValue.toFixed(1)}MB`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function LinearProgressWithLabel(props) {
|
|
27
|
+
return (React.createElement(Box, { sx: { display: 'flex', alignItems: 'center' } },
|
|
28
|
+
React.createElement(Box, { sx: { width: '100%', mr: 1 } },
|
|
29
|
+
React.createElement(LinearProgress, Object.assign({ variant: 'determinate' }, props))),
|
|
30
|
+
React.createElement(Box, { sx: { minWidth: 3 } },
|
|
31
|
+
React.createElement(Typography, { variant: 'body2', color: 'text.secondary' }, `${Math.round(props.value)}%`))));
|
|
32
|
+
}
|
|
33
|
+
export default function DropFileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, sizeLimit = 4, xs = 12, sm, md, route = '', tstToken = '', }) {
|
|
34
|
+
const { getRootProps, getInputProps } = useDropzone({
|
|
35
|
+
multiple,
|
|
36
|
+
onDrop: (dropFiles) => {
|
|
37
|
+
const fileList = [];
|
|
38
|
+
setProgress(-1);
|
|
39
|
+
dropFiles
|
|
40
|
+
.filter((file) => {
|
|
41
|
+
if (bytesToMegabytes(file.size) > sizeLimit) {
|
|
42
|
+
setErrorMsg(`Por favor, escolha um arquivo com tamanho inferior a ${sizeLimit} MB`);
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
setErrorMsg('');
|
|
45
|
+
}, 3000);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
})
|
|
50
|
+
.forEach((file, index) => {
|
|
51
|
+
let id = Date.now() + index;
|
|
52
|
+
// fetch API
|
|
53
|
+
const fd = new FormData();
|
|
54
|
+
fd.append('files', file);
|
|
55
|
+
fd.append('tipoArquivo', tipoArquivo);
|
|
56
|
+
axios
|
|
57
|
+
.post(apiURL, fd, {
|
|
58
|
+
onUploadProgress: (progressEvent) => {
|
|
59
|
+
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
60
|
+
setProgress(percentCompleted);
|
|
61
|
+
if (percentCompleted >= 100) {
|
|
62
|
+
setFiles((f) => [...f, { id: id, name: file.name, loading: true, error: false, file: file, size: file.size }]);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
headers: { Authorization: `Bearer ${tstToken === '' ? (user ? user.token : '') : tstToken}` },
|
|
66
|
+
})
|
|
67
|
+
.then((res) => {
|
|
68
|
+
if (res.status > 200) {
|
|
69
|
+
const fileIdFromApi = get(res.data, route, res.data)[0];
|
|
70
|
+
const fileId = fileIdFromApi['coSeqArquivo'];
|
|
71
|
+
context.setFilesUid((fId) => [
|
|
72
|
+
...fId,
|
|
73
|
+
{
|
|
74
|
+
CO_SEQ_ARQUIVO: fileId,
|
|
75
|
+
CO_TIPO_ARQUIVO: parseInt(tipoArquivo),
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
setFilesLoaded((fl) => [...fl, id]);
|
|
79
|
+
const f = {};
|
|
80
|
+
f[id] = fileId;
|
|
81
|
+
setFilesIds((ids) => (Object.assign(Object.assign({}, ids), f)));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
setProgress(-1);
|
|
85
|
+
removeFile(id);
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.catch((err) => {
|
|
89
|
+
console.log(err);
|
|
90
|
+
setProgress(-1);
|
|
91
|
+
removeFile(id);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const context = useContext(FormContext);
|
|
97
|
+
const { user } = useContext(AuthContext);
|
|
98
|
+
const theme = useTheme();
|
|
99
|
+
const isSmall = useMediaQuery(theme.breakpoints.only('xs'));
|
|
100
|
+
const [progress, setProgress] = useState(-1);
|
|
101
|
+
const [files, setFiles] = useState([]);
|
|
102
|
+
const [filesLoaded, setFilesLoaded] = useState([]);
|
|
103
|
+
const [fileIds, setFilesIds] = useState({});
|
|
104
|
+
// const [filesError, setFilesError] = useState<number[]>([])
|
|
105
|
+
const [errorMsg, setErrorMsg] = useState('');
|
|
106
|
+
const removeFile = (id, hideMsg, fileId) => {
|
|
107
|
+
setFiles(files.filter((x) => x.id !== id));
|
|
108
|
+
if (fileId)
|
|
109
|
+
context.setFilesUid((fId) => fId.filter((idd) => idd.CO_SEQ_ARQUIVO !== fileId));
|
|
110
|
+
if (!hideMsg) {
|
|
111
|
+
setErrorMsg('Erro ao enviar arquivo. Verifique o formato e tente mais tarde.');
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
setErrorMsg('');
|
|
114
|
+
}, 3000);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const deleteFile = (e, id) => {
|
|
118
|
+
if (Object.keys(fileIds).includes(id.toString())) {
|
|
119
|
+
fetch(`${apiURL}/${fileIds[id]}`, {
|
|
120
|
+
method: 'DELETE',
|
|
121
|
+
headers: {
|
|
122
|
+
Authorization: `Bearer ${tstToken === '' ? (user ? user.token : '') : tstToken}`,
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
.then((res) => {
|
|
126
|
+
if (!res.ok)
|
|
127
|
+
removeFile(id, true, fileIds[id]);
|
|
128
|
+
if (res.status === 200) {
|
|
129
|
+
removeFile(id, true, fileIds[id]);
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.catch((err) => console.log(err));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const dt = new DataTransfer();
|
|
137
|
+
files.forEach((x) => {
|
|
138
|
+
dt.items.add(x.file);
|
|
139
|
+
});
|
|
140
|
+
context === null || context === void 0 ? void 0 : context.formSetValue(name, dt.files);
|
|
141
|
+
}, [files, context, name]);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
return () => {
|
|
144
|
+
context.setFilesUid((files) => files.filter((x) => x.CO_TIPO_ARQUIVO !== parseInt(tipoArquivo)));
|
|
145
|
+
};
|
|
146
|
+
}, []);
|
|
147
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }, { sx: { width: '100%' } }),
|
|
148
|
+
React.createElement(Box, { bgcolor: 'white', p: 2, borderRadius: '8px', color: '#1E293B' },
|
|
149
|
+
React.createElement(InputLabel, { required: required, sx: { marginBottom: 2, textTransform: 'capitalize' } }, title),
|
|
150
|
+
React.createElement(Stack, Object.assign({}, getRootProps({ className: 'dropzone' }), { bgcolor: '#EFEFEF', justifyContent: 'center', alignItems: 'center', textAlign: 'center', borderRadius: '6px', py: 8, border: 'solid 1.5px #989898', sx: {
|
|
151
|
+
borderStyle: 'dashed',
|
|
152
|
+
cursor: 'pointer',
|
|
153
|
+
} }),
|
|
154
|
+
React.createElement("input", Object.assign({}, getInputProps(), context.formRegister(name, {
|
|
155
|
+
validate: (v, f) => {
|
|
156
|
+
if ((v.length && filesLoaded.length) <= 0 && required)
|
|
157
|
+
return 'O campo de arquivo é obrigatório';
|
|
158
|
+
},
|
|
159
|
+
}))),
|
|
160
|
+
React.createElement(Stack, { spacing: 2, alignItems: 'center' },
|
|
161
|
+
React.createElement(Box, null,
|
|
162
|
+
React.createElement(Typography, { fontWeight: 600, fontSize: 18 }, "Arraste seus arquivos at\u00E9 aqui"),
|
|
163
|
+
React.createElement(Typography, null, "ou selecione arquivos que est\u00E3o no seu computador")),
|
|
164
|
+
React.createElement(Button, { variant: 'contained', sx: {
|
|
165
|
+
backgroundColor: '#64748B',
|
|
166
|
+
pointerEvents: 'none',
|
|
167
|
+
borderRadius: '8px',
|
|
168
|
+
width: 'fit-content',
|
|
169
|
+
} }, "Selecionar"),
|
|
170
|
+
React.createElement(Typography, { fontWeight: 300 },
|
|
171
|
+
"Tamanho m\u00E1ximo por arquivo ",
|
|
172
|
+
sizeLimit,
|
|
173
|
+
"MB"))),
|
|
174
|
+
React.createElement(Typography, { pt: 2, fontSize: 16, fontWeight: 600 },
|
|
175
|
+
"Voc\u00EA selecionou ",
|
|
176
|
+
files.length,
|
|
177
|
+
" arquivo",
|
|
178
|
+
files.length > 1 ? 's' : '',
|
|
179
|
+
"."),
|
|
180
|
+
React.createElement(Stack, { width: '100%', marginTop: 1, spacing: 1 },
|
|
181
|
+
files.map((x) => (React.createElement(Stack, { direction: 'row', justifyContent: 'space-between', border: 'solid 1px #E2E8F0', borderRadius: 2, p: 1 },
|
|
182
|
+
React.createElement(Stack, { direction: 'row' },
|
|
183
|
+
React.createElement(Stack, { direction: 'row', justifyContent: 'center', alignItems: 'center', minWidth: 30, pr: 1.5 },
|
|
184
|
+
React.createElement(PDFIcon, { sx: {
|
|
185
|
+
filter: 'invert(42%) sepia(86%) saturate(2412%) hue-rotate(326deg) brightness(86%) contrast(102%)',
|
|
186
|
+
transform: 'scale(1.5)',
|
|
187
|
+
width: 30,
|
|
188
|
+
} })),
|
|
189
|
+
React.createElement(Stack, null,
|
|
190
|
+
React.createElement(Typography, { fontWeight: 600 }, x.name),
|
|
191
|
+
React.createElement(Typography, { fontSize: 14 }, bytesToKBorMB(x.size)))),
|
|
192
|
+
React.createElement(Button, { size: 'small', startIcon: React.createElement(TrashIcon, null), variant: 'contained', onClick: (e) => deleteFile(e, x.id), sx: {
|
|
193
|
+
height: 40,
|
|
194
|
+
backgroundColor: '#DE3F50',
|
|
195
|
+
borderRadius: '8px',
|
|
196
|
+
} }, "Remover")))),
|
|
197
|
+
progress > 0 && progress < 100 && (React.createElement(LinearProgressWithLabel, { value: progress, sx: {
|
|
198
|
+
backgroundColor: '#103D6A',
|
|
199
|
+
'.MuiLinearProgress-bar': {
|
|
200
|
+
backgroundColor: '#BDDDFA',
|
|
201
|
+
},
|
|
202
|
+
} }))),
|
|
203
|
+
errorMsg && (React.createElement(React.Fragment, null,
|
|
204
|
+
React.createElement(Typography, { variant: 'caption', color: '#e53935', fontWeight: 600, fontSize: 14, paddingTop: 2 }, errorMsg),
|
|
205
|
+
React.createElement("br", null))),
|
|
206
|
+
get(context === null || context === void 0 ? void 0 : context.errors, name) && (React.createElement(Typography, { variant: 'caption', color: '#e53935', fontWeight: 600, fontSize: 14 }, "* O campo de arquivo \u00E9 obrigat\u00F3rio")))));
|
|
207
|
+
}
|