@ssplib/react-components 0.0.254 → 0.0.255
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,9 +1,11 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { FieldValues } from 'react-hook-form';
|
|
3
3
|
import type { FilesID } from '../../types/form';
|
|
4
|
-
|
|
4
|
+
interface FormProviderProps<T extends FieldValues> {
|
|
5
5
|
children: ReactElement | ReactElement[];
|
|
6
|
-
onSubmit: (data:
|
|
6
|
+
onSubmit: (data: T, filesUid: FilesID) => void;
|
|
7
7
|
formMethod?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'UPDATE';
|
|
8
8
|
submiting?: boolean;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export default function FormProvider<T extends FieldValues>({ children, onSubmit, formMethod, submiting }: FormProviderProps<T>): JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -27,7 +27,7 @@ const react_1 = __importStar(require("react"));
|
|
|
27
27
|
const react_hook_form_1 = require("react-hook-form");
|
|
28
28
|
const form_1 = require("../../context/form");
|
|
29
29
|
const react_toastify_1 = require("react-toastify");
|
|
30
|
-
function FormProvider({ children, onSubmit, formMethod = 'GET', submiting = false
|
|
30
|
+
function FormProvider({ children, onSubmit, formMethod = 'GET', submiting = false }) {
|
|
31
31
|
const { register, handleSubmit, control, formState: { errors }, reset, watch, trigger, setValue, unregister, getValues, } = (0, react_hook_form_1.useForm)();
|
|
32
32
|
const [filesUid, setFilesUid] = (0, react_1.useState)([]);
|
|
33
33
|
return (react_1.default.createElement(form_1.FormContext.Provider, { value: {
|
|
@@ -44,6 +44,10 @@ function FormProvider({ children, onSubmit, formMethod = 'GET', submiting = fals
|
|
|
44
44
|
errors: errors,
|
|
45
45
|
submiting: submiting,
|
|
46
46
|
} },
|
|
47
|
-
react_1.default.createElement("form", { method: formMethod, onSubmit: handleSubmit((
|
|
47
|
+
react_1.default.createElement("form", { method: formMethod, onSubmit: handleSubmit((data) => onSubmit(data, filesUid), () => (0, react_toastify_1.toast)('Formulário incompleto! Verifique os campos marcados e tente novamente.', {
|
|
48
|
+
type: 'warning',
|
|
49
|
+
position: 'top-right',
|
|
50
|
+
theme: 'colored',
|
|
51
|
+
})) }, children)));
|
|
48
52
|
}
|
|
49
53
|
exports.default = FormProvider;
|