@ssplib/react-components 0.0.31 → 0.0.33
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/components/form/checkbox/CheckBox.js +2 -2
- package/components/form/checkbox/CheckBoxWarning.js +2 -2
- package/components/form/date/DatePicker.js +20 -20
- package/components/form/date/TimePicker.js +14 -15
- package/components/form/file/FileUpload.js +2 -2
- package/components/form/input/ActiveInput.js +2 -2
- package/components/form/input/AutoComplete.js +2 -2
- package/components/form/input/Input.js +2 -2
- package/components/form/input/MultInput.js +2 -2
- package/components/form/input/OtherCheckBox.js +2 -2
- package/components/form/stepper/Stepper.d.ts +2 -0
- package/components/form/stepper/Stepper.js +4 -2
- package/components/form/stepper/StepperBlock.js +2 -2
- package/components/form/switch/Switch.js +2 -6
- package/components/form/table/Table.d.ts +7 -1
- package/components/form/table/Table.js +25 -8
- package/components/providers/FormProvider.d.ts +2 -1
- package/components/providers/FormProvider.js +3 -7
- package/context/form.d.ts +1 -2
- package/context/form.js +2 -1
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +1 -1
|
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const material_1 = require("@mui/material");
|
|
7
7
|
const react_1 = require("react");
|
|
8
|
-
const form_1 =
|
|
8
|
+
const form_1 = require("../../../context/form");
|
|
9
9
|
const react_2 = __importDefault(require("react"));
|
|
10
10
|
function CheckBox({ name, title, xs = 12, sm, md }) {
|
|
11
|
-
const context = (0, react_1.useContext)(form_1.
|
|
11
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
12
12
|
return (react_2.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
13
13
|
react_2.default.createElement(material_1.FormControlLabel, Object.assign({ control: react_2.default.createElement(material_1.Checkbox, { size: 'small' }), label: title }, context === null || context === void 0 ? void 0 : context.formRegister(name)))));
|
|
14
14
|
}
|
|
@@ -29,9 +29,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const material_1 = require("@mui/material");
|
|
30
30
|
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
31
31
|
const react_1 = __importStar(require("react"));
|
|
32
|
-
const form_1 =
|
|
32
|
+
const form_1 = require("../../../context/form");
|
|
33
33
|
function CheckBoxWarning({ name, title, customWarning, xs = 12, sm, md }) {
|
|
34
|
-
const context = (0, react_1.useContext)(form_1.
|
|
34
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
35
35
|
return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
36
36
|
react_1.default.createElement(material_1.FormControlLabel, { control: react_1.default.createElement(material_1.Checkbox, Object.assign({ size: 'small' }, context.formRegister(name))), label: title }),
|
|
37
37
|
context.formWatch(name) && (react_1.default.createElement(material_1.Card, { sx: { bgcolor: '#FFFBF5', color: '#F59E0B', padding: 1, paddingLeft: 2 } }, customWarning ? (customWarning) : (react_1.default.createElement(Typography_1.default, null,
|
|
@@ -40,15 +40,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
40
40
|
const material_1 = require("@mui/material");
|
|
41
41
|
const x_date_pickers_1 = require("@mui/x-date-pickers");
|
|
42
42
|
const AdapterDayjs_1 = require("@mui/x-date-pickers/AdapterDayjs");
|
|
43
|
-
const
|
|
43
|
+
const x_date_pickers_2 = require("@mui/x-date-pickers");
|
|
44
44
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
45
45
|
const pt_br_1 = __importDefault(require("dayjs/locale/pt-br"));
|
|
46
46
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
47
47
|
const react_1 = __importStar(require("react"));
|
|
48
|
-
const form_1 =
|
|
48
|
+
const form_1 = require("../../../context/form");
|
|
49
49
|
function DatePicker(_a) {
|
|
50
|
+
var _b;
|
|
50
51
|
var { name, required = false, title, xs = 12, sm, md, minDt, maxDt } = _a, props = __rest(_a, ["name", "required", "title", "xs", "sm", "md", "minDt", "maxDt"]);
|
|
51
|
-
const context = (0, react_1.useContext)(form_1.
|
|
52
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
52
53
|
const [value, setValue] = (0, react_1.useState)(null);
|
|
53
54
|
const handleChange = (newValue) => {
|
|
54
55
|
setValue(newValue);
|
|
@@ -58,22 +59,21 @@ function DatePicker(_a) {
|
|
|
58
59
|
react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
59
60
|
title && react_1.default.createElement(material_1.InputLabel, null, title),
|
|
60
61
|
react_1.default.createElement(x_date_pickers_1.LocalizationProvider, { adapterLocale: pt_br_1.default, dateAdapter: AdapterDayjs_1.AdapterDayjs },
|
|
61
|
-
react_1.default.createElement(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} })))));
|
|
62
|
+
react_1.default.createElement(x_date_pickers_2.DatePicker, { minDate: (0, dayjs_1.default)(minDt, 'DD/MM/YYYY'), maxDate: (0, dayjs_1.default)(maxDt, 'DD/MM/YYYY'), format: 'DD/MM/YYYY', value: value, onChange: handleChange, disableHighlightToday: true, sx: { outline: (0, lodash_get_1.default)(context.errors, name) ? '1px solid red' : '' }, inputRef: (params) => (react_1.default.createElement(material_1.TextField, Object.assign({ size: 'small' }, params, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
63
|
+
validate: (v, f) => {
|
|
64
|
+
console.log('meu valor: ', v);
|
|
65
|
+
if (!v)
|
|
66
|
+
v = '';
|
|
67
|
+
if (v.length <= 0 && required)
|
|
68
|
+
return 'Este campo é obrigatório';
|
|
69
|
+
if (v.length < 10 && required)
|
|
70
|
+
return 'A data precisa seguir o padrão DD/MM/AAAA';
|
|
71
|
+
if (minDt && !((0, dayjs_1.default)(minDt, 'DD/MM/YYYY').isSame((0, dayjs_1.default)(v, 'DD/MM/YYYY')) || (0, dayjs_1.default)(minDt, 'DD/MM/YYYY').isBefore((0, dayjs_1.default)(v, 'DD/MM/YYYY'))))
|
|
72
|
+
return 'Inicio precisa ser no mínimo 30 dias antes e no máximo 60 dias.';
|
|
73
|
+
if (maxDt && !((0, dayjs_1.default)(maxDt, 'DD/MM/YYYY').isSame((0, dayjs_1.default)(v, 'DD/MM/YYYY')) || (0, dayjs_1.default)(maxDt, 'DD/MM/YYYY').isAfter((0, dayjs_1.default)(v, 'DD/MM/YYYY'))))
|
|
74
|
+
return 'A data escolhida não é válida';
|
|
75
|
+
},
|
|
76
|
+
}), { helperText: 'Agora nao foi', fullWidth: true }))) }),
|
|
77
|
+
react_1.default.createElement(material_1.Typography, { sx: { color: 'red' } }, (_b = (0, lodash_get_1.default)(context.errors, name)) === null || _b === void 0 ? void 0 : _b.message)))));
|
|
78
78
|
}
|
|
79
79
|
exports.default = DatePicker;
|
|
@@ -32,9 +32,10 @@ const AdapterDayjs_1 = require("@mui/x-date-pickers/AdapterDayjs");
|
|
|
32
32
|
const pt_br_1 = __importDefault(require("dayjs/locale/pt-br"));
|
|
33
33
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
34
34
|
const react_1 = __importStar(require("react"));
|
|
35
|
-
const form_1 =
|
|
35
|
+
const form_1 = require("../../../context/form");
|
|
36
36
|
function TimePicker({ name, required = false, title, xs = 12, sm, md }) {
|
|
37
|
-
|
|
37
|
+
var _a;
|
|
38
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
38
39
|
const [value, setValue] = (0, react_1.useState)(null);
|
|
39
40
|
const handleChange = (newValue) => {
|
|
40
41
|
setValue(newValue);
|
|
@@ -43,18 +44,16 @@ function TimePicker({ name, required = false, title, xs = 12, sm, md }) {
|
|
|
43
44
|
return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
44
45
|
title && react_1.default.createElement(material_1.InputLabel, { required: required }, title),
|
|
45
46
|
react_1.default.createElement(x_date_pickers_1.LocalizationProvider, { adapterLocale: pt_br_1.default, dateAdapter: AdapterDayjs_1.AdapterDayjs },
|
|
46
|
-
react_1.default.createElement(x_date_pickers_1.TimePicker, { value: value, ampm: false, onChange: handleChange, inputRef: (params) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}), { 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, fullWidth: true })));
|
|
58
|
-
} }))));
|
|
47
|
+
react_1.default.createElement(x_date_pickers_1.TimePicker, { value: value, ampm: false, onChange: handleChange, sx: { outline: (0, lodash_get_1.default)(context.errors, name) ? '1px solid red' : '' }, inputRef: (params) => (react_1.default.createElement(material_1.TextField, Object.assign({ size: 'small' }, params, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
48
|
+
validate: (v, f) => {
|
|
49
|
+
if (!v)
|
|
50
|
+
v = '';
|
|
51
|
+
if (v.length <= 0 && required)
|
|
52
|
+
return 'Este campo é obrigatório';
|
|
53
|
+
if (v.length < 5 && required)
|
|
54
|
+
return 'A hora precisa seguir o padrão HH:MM';
|
|
55
|
+
},
|
|
56
|
+
}), { fullWidth: true }))) }),
|
|
57
|
+
react_1.default.createElement(material_1.Typography, { sx: { color: 'red' } }, (_a = (0, lodash_get_1.default)(context.errors, name)) === null || _a === void 0 ? void 0 : _a.message))));
|
|
59
58
|
}
|
|
60
59
|
exports.default = TimePicker;
|
|
@@ -37,9 +37,9 @@ const system_1 = require("@mui/system");
|
|
|
37
37
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const auth_1 = require("../../../context/auth");
|
|
40
|
-
const form_1 =
|
|
40
|
+
const form_1 = require("../../../context/form");
|
|
41
41
|
function FileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, xs = 12, sm, md, }) {
|
|
42
|
-
const context = (0, react_1.useContext)(form_1.
|
|
42
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
43
43
|
const { user } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
44
44
|
const [files, setFiles] = (0, react_1.useState)([]);
|
|
45
45
|
const [filesLoaded, setFilesLoaded] = (0, react_1.useState)([]);
|
|
@@ -41,13 +41,13 @@ const material_1 = require("@mui/material");
|
|
|
41
41
|
const InputLabel_1 = __importDefault(require("@mui/material/InputLabel"));
|
|
42
42
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
43
43
|
const react_1 = __importStar(require("react"));
|
|
44
|
-
const form_1 =
|
|
44
|
+
const form_1 = require("../../../context/form");
|
|
45
45
|
const Switch_1 = __importDefault(require("../switch/Switch"));
|
|
46
46
|
const MaskInput_1 = __importDefault(require("./MaskInput"));
|
|
47
47
|
function FileUpload(_a) {
|
|
48
48
|
var _b;
|
|
49
49
|
var { name, required = false, title, customPlaceholder, defaultChecked = false, xs = 12, sm, md } = _a, props = __rest(_a, ["name", "required", "title", "customPlaceholder", "defaultChecked", "xs", "sm", "md"]);
|
|
50
|
-
const context = (0, react_1.useContext)(form_1.
|
|
50
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
51
51
|
const switchName = `${name}-switch`;
|
|
52
52
|
let oldValue = (0, react_1.useRef)(null);
|
|
53
53
|
(0, react_1.useEffect)(() => {
|
|
@@ -32,9 +32,9 @@ const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
33
|
const react_query_1 = require("react-query");
|
|
34
34
|
const auth_1 = require("../../../context/auth");
|
|
35
|
-
const form_1 =
|
|
35
|
+
const form_1 = require("../../../context/form");
|
|
36
36
|
function AutoComplete({ name, required = false, title, customPlaceholder, url, xs = 12, sm, md, }) {
|
|
37
|
-
const context = (0, react_1.useContext)(form_1.
|
|
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)([]);
|
|
40
40
|
const { isLoading, data, error } = (0, react_query_1.useQuery)(`autocomplete-${name}`, () => fetch(url, {
|
|
@@ -42,10 +42,10 @@ const material_1 = require("@mui/material");
|
|
|
42
42
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
43
43
|
const react_1 = __importStar(require("react"));
|
|
44
44
|
const MaskInput_1 = __importDefault(require("./MaskInput"));
|
|
45
|
-
const form_1 =
|
|
45
|
+
const form_1 = require("../../../context/form");
|
|
46
46
|
function Input(_a) {
|
|
47
47
|
var { type = 'input', numberMask = '000000000000000', xs = 12, sm, md } = _a, props = __rest(_a, ["type", "numberMask", "xs", "sm", "md"]);
|
|
48
|
-
const context = (0, react_1.useContext)(form_1.
|
|
48
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
49
49
|
const chooseInput = (0, react_1.useCallback)(() => {
|
|
50
50
|
const inputConfig = {
|
|
51
51
|
fullWidth: true,
|
|
@@ -41,11 +41,11 @@ const material_1 = require("@mui/material");
|
|
|
41
41
|
const InputLabel_1 = __importDefault(require("@mui/material/InputLabel"));
|
|
42
42
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
43
43
|
const react_1 = __importStar(require("react"));
|
|
44
|
-
const form_1 =
|
|
44
|
+
const form_1 = require("../../../context/form");
|
|
45
45
|
function MultInput(_a) {
|
|
46
46
|
var _b;
|
|
47
47
|
var { name, required = false, title, customPlaceholder, xs = 12, sm, md } = _a, props = __rest(_a, ["name", "required", "title", "customPlaceholder", "xs", "sm", "md"]);
|
|
48
|
-
const context = (0, react_1.useContext)(form_1.
|
|
48
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
49
49
|
return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
50
50
|
title && (react_1.default.createElement(InputLabel_1.default, { required: required, sx: { textTransform: 'capitalize' } }, title)),
|
|
51
51
|
react_1.default.createElement(material_1.TextField, Object.assign({ multiline: true, fullWidth: true, rows: 3 }, context.formRegister(name, {
|
|
@@ -29,10 +29,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const material_1 = require("@mui/material");
|
|
30
30
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
31
31
|
const react_1 = __importStar(require("react"));
|
|
32
|
-
const form_1 =
|
|
32
|
+
const form_1 = require("../../../context/form");
|
|
33
33
|
function SSPOtherCheckBox({ name, required = false, xs = 12, sm, md }) {
|
|
34
34
|
var _a;
|
|
35
|
-
const context = (0, react_1.useContext)(form_1.
|
|
35
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
36
36
|
const checkName = `switch-${name}`;
|
|
37
37
|
return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
38
38
|
react_1.default.createElement(material_1.Stack, { direction: 'row' },
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
2
3
|
export declare function Stepper(props: {
|
|
3
4
|
children: ReactElement | ReactElement[];
|
|
5
|
+
debugData?: (data: FieldValues) => void;
|
|
4
6
|
}): JSX.Element;
|
|
5
7
|
declare const _default: React.MemoExoticComponent<typeof Stepper>;
|
|
6
8
|
export default _default;
|
|
@@ -42,7 +42,7 @@ const Save_1 = __importDefault(require("@mui/icons-material/Save"));
|
|
|
42
42
|
const lab_1 = require("@mui/lab");
|
|
43
43
|
const material_1 = require("@mui/material");
|
|
44
44
|
const react_1 = __importStar(require("react"));
|
|
45
|
-
const form_1 =
|
|
45
|
+
const form_1 = require("../../../context/form");
|
|
46
46
|
const getKeys = (values, id) => {
|
|
47
47
|
if (!values || Object.keys(values).length <= 0)
|
|
48
48
|
return [];
|
|
@@ -55,7 +55,7 @@ const getKeys = (values, id) => {
|
|
|
55
55
|
};
|
|
56
56
|
function Stepper(props) {
|
|
57
57
|
const length = Array.isArray(props.children) ? props.children.length : 1;
|
|
58
|
-
const context = (0, react_1.useContext)(form_1.
|
|
58
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
59
59
|
const theme = (0, material_1.useTheme)();
|
|
60
60
|
const [activeStep, setActiveStep] = (0, react_1.useState)(0);
|
|
61
61
|
const [canPass, setCanPass] = (0, react_1.useState)(false);
|
|
@@ -68,6 +68,7 @@ function Stepper(props) {
|
|
|
68
68
|
const result = yield context.formTrigger(getKeys(context.formGetValues(), activeStep));
|
|
69
69
|
if (!result) {
|
|
70
70
|
setCanPass(true);
|
|
71
|
+
console.log('teste: ', context.formGetValues());
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
74
|
setActiveStep((prevActiveStep) => prevActiveStep + 1);
|
|
@@ -77,6 +78,7 @@ function Stepper(props) {
|
|
|
77
78
|
if (!result) {
|
|
78
79
|
e.preventDefault();
|
|
79
80
|
setCanPass(true);
|
|
81
|
+
console.log('teste: ', context.formGetValues());
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
});
|
|
@@ -43,7 +43,7 @@ const material_1 = require("@mui/material");
|
|
|
43
43
|
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
44
44
|
const react_1 = __importStar(require("react"));
|
|
45
45
|
const Switch_1 = __importDefault(require("../switch/Switch"));
|
|
46
|
-
const form_1 =
|
|
46
|
+
const form_1 = require("../../../context/form");
|
|
47
47
|
function childrenTree(component, prefix, idx) {
|
|
48
48
|
if (!component.props)
|
|
49
49
|
return component;
|
|
@@ -67,7 +67,7 @@ function childrenTree(component, prefix, idx) {
|
|
|
67
67
|
}
|
|
68
68
|
function StepperBlock(_a) {
|
|
69
69
|
var { optional = false, title, prefix = 0 } = _a, props = __rest(_a, ["optional", "title", "prefix"]);
|
|
70
|
-
const context = (0, react_1.useContext)(form_1.
|
|
70
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
71
71
|
const switchName = `switch-${prefix}`;
|
|
72
72
|
const fields = Array.isArray(props.children) ? props.children : [props.children];
|
|
73
73
|
const cloneChildren = fields.map((x, index) => {
|
|
@@ -33,19 +33,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
33
33
|
}
|
|
34
34
|
return t;
|
|
35
35
|
};
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
37
|
exports.Switch = void 0;
|
|
41
38
|
const material_1 = require("@mui/material");
|
|
42
39
|
const react_1 = __importStar(require("react"));
|
|
43
|
-
const form_1 =
|
|
40
|
+
const form_1 = require("../../../context/form");
|
|
44
41
|
function Switch(_a) {
|
|
45
42
|
var { defaultChecked = false } = _a, props = __rest(_a, ["defaultChecked"]);
|
|
46
|
-
const context = (0, react_1.useContext)(form_1.
|
|
43
|
+
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
47
44
|
(0, react_1.useEffect)(() => {
|
|
48
|
-
console.log(context);
|
|
49
45
|
context === null || context === void 0 ? void 0 : context.formSetValue(props.name, defaultChecked);
|
|
50
46
|
}, []);
|
|
51
47
|
return (react_1.default.createElement(material_1.Stack, { sx: { alignItems: 'center', justifyContent: 'center' } },
|
|
@@ -3,7 +3,7 @@ interface ColumnData {
|
|
|
3
3
|
title: string;
|
|
4
4
|
keyName: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, }: {
|
|
6
|
+
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, filters, }: {
|
|
7
7
|
columns: ColumnData[];
|
|
8
8
|
tableName: string;
|
|
9
9
|
action: (prop: any) => JSX.Element;
|
|
@@ -17,6 +17,12 @@ export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableNam
|
|
|
17
17
|
public: string;
|
|
18
18
|
};
|
|
19
19
|
dataPath?: string;
|
|
20
|
+
isPublic?: boolean;
|
|
21
|
+
filters?: {
|
|
22
|
+
key: string;
|
|
23
|
+
options: string[];
|
|
24
|
+
name: string;
|
|
25
|
+
}[];
|
|
20
26
|
}): JSX.Element;
|
|
21
27
|
declare const _default: React.MemoExoticComponent<typeof Table>;
|
|
22
28
|
export default _default;
|
|
@@ -41,13 +41,13 @@ const auth_1 = require("../../../context/auth");
|
|
|
41
41
|
function Table({ columns, fetchFunc, emptyMsg = {
|
|
42
42
|
user: 'Nenhum dado encontrado',
|
|
43
43
|
public: 'Nenhum dado encontrado',
|
|
44
|
-
}, dataPath = '', tableName, csv, columnSize, action, }) {
|
|
44
|
+
}, dataPath = '', tableName, csv, columnSize, action, isPublic = false, filters, }) {
|
|
45
45
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
46
46
|
const [error, setError] = (0, react_1.useState)(null);
|
|
47
47
|
const [data, setData] = (0, react_1.useState)(null);
|
|
48
48
|
const { user, userLoaded } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
49
49
|
(0, react_1.useEffect)(() => {
|
|
50
|
-
if (userLoaded)
|
|
50
|
+
if (userLoaded || isPublic)
|
|
51
51
|
fetchFunc().then((res) => res.json().then((j) => {
|
|
52
52
|
if (j.statusCode === 204)
|
|
53
53
|
setData({ body: { data: [] } });
|
|
@@ -87,7 +87,6 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
87
87
|
return (0, lodash_get_1.default)(dt, dataPath);
|
|
88
88
|
}, []);
|
|
89
89
|
(0, react_1.useEffect)(() => {
|
|
90
|
-
console.log('é array', getData(data));
|
|
91
90
|
if (isLoading || error || !getData(data))
|
|
92
91
|
return;
|
|
93
92
|
setList(getData(data));
|
|
@@ -107,8 +106,8 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
107
106
|
return;
|
|
108
107
|
}
|
|
109
108
|
const listData = getData(data);
|
|
110
|
-
setList([])
|
|
111
|
-
setListPage(1)
|
|
109
|
+
// setList([])
|
|
110
|
+
// setListPage(1)
|
|
112
111
|
const newList = [];
|
|
113
112
|
listData.forEach((x) => {
|
|
114
113
|
const dataStr = [];
|
|
@@ -207,6 +206,23 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
207
206
|
return (react_1.default.createElement(Typography_1.default, { color: '#EF4444', fontWeight: 600, fontFamily: 'Inter' }, "REPROVADO"));
|
|
208
207
|
}
|
|
209
208
|
}, []);
|
|
209
|
+
const onFilterSelect = (0, react_1.useCallback)((key, newValue) => {
|
|
210
|
+
if (!newValue) {
|
|
211
|
+
setList(getData(data));
|
|
212
|
+
setPagCount(getCount(getData(data)));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const listData = getData(data);
|
|
216
|
+
const newList = [];
|
|
217
|
+
listData.forEach((l) => {
|
|
218
|
+
if ((0, lodash_get_1.default)(l, key).toString() === newValue)
|
|
219
|
+
newList.push(l);
|
|
220
|
+
});
|
|
221
|
+
setList(newList);
|
|
222
|
+
setPagCount(getCount(newList));
|
|
223
|
+
console.log('minha lista:', listData);
|
|
224
|
+
console.log('selecionei:', newValue, 'minha chave:', key);
|
|
225
|
+
}, [data]);
|
|
210
226
|
if (error)
|
|
211
227
|
return (react_1.default.createElement(material_1.Box, { bgcolor: '#E2E8F0', padding: 2, marginX: 2 },
|
|
212
228
|
react_1.default.createElement(Typography_1.default, { fontSize: 24, textAlign: 'center', fontFamily: 'Inter' }, error.status === 403 && 'Acesso negado')));
|
|
@@ -216,14 +232,15 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
216
232
|
"Carregando ",
|
|
217
233
|
tableName),
|
|
218
234
|
react_1.default.createElement(material_1.CircularProgress, null)));
|
|
219
|
-
if (!userLoaded)
|
|
235
|
+
if (!userLoaded && !isPublic)
|
|
220
236
|
return react_1.default.createElement(material_1.LinearProgress, null);
|
|
221
237
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
222
238
|
react_1.default.createElement(material_1.Box, { marginX: isSmall ? 0 : 4 },
|
|
223
|
-
react_1.default.createElement(material_1.
|
|
239
|
+
react_1.default.createElement(material_1.Stack, { paddingBottom: 2, spacing: 2, direction: { xs: 'column', md: 'row' } },
|
|
224
240
|
react_1.default.createElement(TextField_1.default, { InputProps: {
|
|
225
241
|
startAdornment: react_1.default.createElement(Search_1.default, { sx: { marginRight: 1, fill: '#c0c0c0' } }),
|
|
226
|
-
}, size: 'small', onChange: onInputChange, fullWidth: true, placeholder: `Pesquisar ${tableName}
|
|
242
|
+
}, size: 'small', onChange: onInputChange, fullWidth: true, placeholder: `Pesquisar ${tableName}` }), filters === null || filters === void 0 ? void 0 :
|
|
243
|
+
filters.map((f) => (react_1.default.createElement(material_1.Autocomplete, { options: f.options.map((name) => name), onChange: (e, newValue) => onFilterSelect(f.key, newValue), renderInput: (args) => react_1.default.createElement(TextField_1.default, Object.assign({}, args, { label: f.name, size: 'small' })) })))),
|
|
227
244
|
react_1.default.createElement(material_1.Stack, { spacing: 0.2 }, getMaxItems().length <= 0 ? (react_1.default.createElement(material_1.Stack, { sx: { backgroundColor: '#E2E8F0', padding: 2, borderRadius: 2, marginX: { xs: 2, md: 0 } }, justifyContent: 'center', alignItems: 'center' },
|
|
228
245
|
react_1.default.createElement(Typography_1.default, { fontSize: 21, fontFamily: 'Inter', fontWeight: 600, textAlign: 'center' }, user ? emptyMsg.user : emptyMsg.public),
|
|
229
246
|
user && (react_1.default.createElement(material_1.Box, { sx: { '& a': { textDecoration: 'none' }, marginTop: 2 } },
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { FieldValues } from 'react-hook-form';
|
|
3
|
-
export default function FormProvider({ children, onSubmit, formMethod, }: {
|
|
3
|
+
export default function FormProvider({ children, onSubmit, formMethod, submiting, }: {
|
|
4
4
|
children: ReactElement | ReactElement[];
|
|
5
5
|
onSubmit: (data: FieldValues) => void;
|
|
6
6
|
formMethod?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'UPDATE';
|
|
7
|
+
submiting?: boolean;
|
|
7
8
|
}): JSX.Element;
|
|
@@ -22,18 +22,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
const react_1 = __importStar(require("react"));
|
|
30
27
|
const react_hook_form_1 = require("react-hook-form");
|
|
31
|
-
const form_1 =
|
|
32
|
-
function FormProvider({ children, onSubmit, formMethod = 'GET', }) {
|
|
28
|
+
const form_1 = require("../../context/form");
|
|
29
|
+
function FormProvider({ children, onSubmit, formMethod = 'GET', submiting = false, }) {
|
|
33
30
|
const { register, handleSubmit, formState: { errors }, reset, watch, trigger, setValue, unregister, getValues, } = (0, react_hook_form_1.useForm)();
|
|
34
|
-
const [submiting, setSubmiting] = (0, react_1.useState)(false);
|
|
35
31
|
const [filesUid, setFilesUid] = (0, react_1.useState)([]);
|
|
36
|
-
return (react_1.default.createElement(form_1.
|
|
32
|
+
return (react_1.default.createElement(form_1.FormContext.Provider, { value: {
|
|
37
33
|
formRegister: register,
|
|
38
34
|
formWatch: watch,
|
|
39
35
|
formReset: reset,
|
package/context/form.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
2
|
import { FieldErrors, FieldValues, UseFormRegister, UseFormReset, UseFormSetValue, UseFormTrigger, UseFormWatch } from 'react-hook-form';
|
|
3
3
|
import { UseFormGetValues, UseFormHandleSubmit, UseFormUnregister } from 'react-hook-form/dist/types';
|
|
4
|
-
declare const
|
|
4
|
+
export declare const FormContext: import("react").Context<{
|
|
5
5
|
formRegister: UseFormRegister<FieldValues>;
|
|
6
6
|
formWatch: UseFormWatch<FieldValues>;
|
|
7
7
|
formReset: UseFormReset<FieldValues>;
|
|
@@ -17,4 +17,3 @@ declare const _default: import("react").Context<{
|
|
|
17
17
|
errors: FieldErrors<FieldValues>;
|
|
18
18
|
submiting: boolean;
|
|
19
19
|
} | null>;
|
|
20
|
-
export default _default;
|
package/context/form.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ import NavBar from './components/navbar/NavBar';
|
|
|
17
17
|
import FormProvider from './components/providers/FormProvider';
|
|
18
18
|
import { OAuthProvider, cookieName as AUTH_COOKIE_NAME } from './components/providers/OAuthProvider';
|
|
19
19
|
import { AuthContext } from './context/auth';
|
|
20
|
-
import FormContext from './context/form';
|
|
20
|
+
import { FormContext } from './context/form';
|
|
21
21
|
export { CheckBox, CheckBoxWarning, DatePicker, TimePicker, FileUpload, ActiveInput, AutoComplete, Input, MaskInput, MultInput, OtherCheckBox, Stepper, StepperBlock, Switch, Table, NavBar, FormProvider, OAuthProvider, AUTH_COOKIE_NAME, AuthContext, FormContext };
|
package/index.js
CHANGED
|
@@ -43,5 +43,5 @@ Object.defineProperty(exports, "OAuthProvider", { enumerable: true, get: functio
|
|
|
43
43
|
Object.defineProperty(exports, "AUTH_COOKIE_NAME", { enumerable: true, get: function () { return OAuthProvider_1.cookieName; } });
|
|
44
44
|
const auth_1 = require("./context/auth");
|
|
45
45
|
Object.defineProperty(exports, "AuthContext", { enumerable: true, get: function () { return auth_1.AuthContext; } });
|
|
46
|
-
const form_1 =
|
|
47
|
-
exports
|
|
46
|
+
const form_1 = require("./context/form");
|
|
47
|
+
Object.defineProperty(exports, "FormContext", { enumerable: true, get: function () { return form_1.FormContext; } });
|