@arkyn/components 1.3.130 → 1.3.131
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/FormController/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/E,OAAO,cAAc,CAAC;AAItB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/FormController/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/E,OAAO,cAAc,CAAC;AAItB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CAuCjD;AAED,iBAAS,iBAAiB,+BAEzB;AAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
|
@@ -1,14 +1,22 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useActionData } from "@remix-run/react";
|
2
|
+
import { useActionData, useFetchers } from "@remix-run/react";
|
3
3
|
import { createContext, useContext, useId, useRef } from "react";
|
4
4
|
import "./styles.css";
|
5
5
|
const FormControllerContext = createContext({});
|
6
6
|
function FormController(props) {
|
7
|
-
const actionData = useActionData();
|
8
7
|
const { children, className: baseClassName, id: formControllerId, ...rest } = props;
|
8
|
+
const actionData = useActionData();
|
9
|
+
const fetchers = useFetchers();
|
10
|
+
let fieldErrors = {};
|
11
|
+
fieldErrors = { ...actionData?.fieldErrors };
|
12
|
+
fetchers.forEach((fetcher) => {
|
13
|
+
if (fetcher.data?.fieldErrors) {
|
14
|
+
fieldErrors = { ...fieldErrors, ...fetcher.data.fieldErrors };
|
15
|
+
}
|
16
|
+
});
|
9
17
|
const inputRef = useRef(null);
|
10
18
|
const name = inputRef.current?.name || "";
|
11
|
-
const error =
|
19
|
+
const error = fieldErrors?.[name] || null;
|
12
20
|
const id = useId();
|
13
21
|
const className = `arkynFormController ${baseClassName}`;
|
14
22
|
return (_jsx(FormControllerContext.Provider, { value: { error, id, inputRef }, children: _jsx("section", { id: formControllerId || name || undefined, className: className.trim(), ...rest, children: children }) }));
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FormControllerContextProps, FormControllerProps } from "@arkyn/types";
|
2
|
-
import { useActionData } from "@remix-run/react";
|
2
|
+
import { useActionData, useFetchers } from "@remix-run/react";
|
3
3
|
import { createContext, useContext, useId, useRef } from "react";
|
4
4
|
|
5
5
|
import "./styles.css";
|
@@ -7,7 +7,6 @@ import "./styles.css";
|
|
7
7
|
const FormControllerContext = createContext({} as FormControllerContextProps);
|
8
8
|
|
9
9
|
function FormController(props: FormControllerProps) {
|
10
|
-
const actionData = useActionData<any>();
|
11
10
|
const {
|
12
11
|
children,
|
13
12
|
className: baseClassName,
|
@@ -15,10 +14,22 @@ function FormController(props: FormControllerProps) {
|
|
15
14
|
...rest
|
16
15
|
} = props;
|
17
16
|
|
17
|
+
const actionData = useActionData<any>();
|
18
|
+
const fetchers = useFetchers();
|
19
|
+
|
20
|
+
let fieldErrors: { [x: string]: string } = {};
|
21
|
+
|
22
|
+
fieldErrors = { ...actionData?.fieldErrors };
|
23
|
+
fetchers.forEach((fetcher) => {
|
24
|
+
if (fetcher.data?.fieldErrors) {
|
25
|
+
fieldErrors = { ...fieldErrors, ...fetcher.data.fieldErrors };
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
18
29
|
const inputRef = useRef<HTMLInputElement>(null);
|
19
30
|
|
20
31
|
const name = inputRef.current?.name || "";
|
21
|
-
const error =
|
32
|
+
const error = fieldErrors?.[name] || null;
|
22
33
|
|
23
34
|
const id = useId();
|
24
35
|
const className = `arkynFormController ${baseClassName}`;
|