@arkyn/components 1.3.134 → 1.3.135
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +1044 -1029
- package/dist/bundle.umd.cjs +51 -51
- package/dist/components/Form/FormController/index.d.ts.map +1 -1
- package/dist/components/Form/FormController/index.js +3 -18
- package/dist/hooks/useFieldErrors.d.ts +5 -0
- package/dist/hooks/useFieldErrors.d.ts.map +1 -0
- package/dist/hooks/useFieldErrors.js +39 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/components/Form/FormController/index.tsx +2 -20
- package/src/hooks/useFieldErrors.ts +48 -0
- package/src/index.ts +1 -0
@@ -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;AAW/E,OAAO,cAAc,CAAC;
|
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;AAW/E,OAAO,cAAc,CAAC;AAKtB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CA4BjD;AAED,iBAAS,iBAAiB,+BAEzB;AAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
|
@@ -1,26 +1,11 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import {
|
3
|
-
import { createContext, useContext, useEffect, useId, useRef, useState, } from "react";
|
2
|
+
import { createContext, useContext, useId, useRef, } from "react";
|
4
3
|
import "./styles.css";
|
4
|
+
import { useFieldErrors } from "../../../hooks/useFieldErrors";
|
5
5
|
const FormControllerContext = createContext({});
|
6
6
|
function FormController(props) {
|
7
7
|
const { children, className: baseClassName, id: formControllerId, ...rest } = props;
|
8
|
-
const
|
9
|
-
const fetchers = useFetchers();
|
10
|
-
const [fieldErrors, setFieldErrors] = useState({});
|
11
|
-
useEffect(() => {
|
12
|
-
let newFieldErrors = {};
|
13
|
-
if (actionData?.fieldErrors)
|
14
|
-
newFieldErrors = actionData.fieldErrors;
|
15
|
-
fetchers.forEach((fetcher) => {
|
16
|
-
if (fetcher.data?.fieldErrors && fetcher.state === "loading") {
|
17
|
-
newFieldErrors = { ...newFieldErrors, ...fetcher.data.fieldErrors };
|
18
|
-
}
|
19
|
-
});
|
20
|
-
if (JSON.stringify(newFieldErrors) !== JSON.stringify(fieldErrors)) {
|
21
|
-
setFieldErrors(newFieldErrors);
|
22
|
-
}
|
23
|
-
}, [fetchers, actionData, fieldErrors]);
|
8
|
+
const fieldErrors = useFieldErrors();
|
24
9
|
const inputRef = useRef(null);
|
25
10
|
const name = inputRef.current?.name || "";
|
26
11
|
const error = fieldErrors?.[name] || null;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useFieldErrors.d.ts","sourceRoot":"","sources":["../../src/hooks/useFieldErrors.ts"],"names":[],"mappings":"AAGA,iBAAS,cAAc;;EA0CtB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { useActionData, useFetchers, useNavigation } from "@remix-run/react";
|
2
|
+
import { useEffect, useState } from "react";
|
3
|
+
function useFieldErrors() {
|
4
|
+
const actionData = useActionData();
|
5
|
+
const navigation = useNavigation();
|
6
|
+
const fetchers = useFetchers();
|
7
|
+
const [fetcherFieldErrors, setFetcherFieldErrors] = useState(null);
|
8
|
+
function compareObjects(obj1, obj2) {
|
9
|
+
return JSON.stringify(obj1) === JSON.stringify(obj2);
|
10
|
+
}
|
11
|
+
function handleClearFields() {
|
12
|
+
if (fetcherFieldErrors)
|
13
|
+
setFetcherFieldErrors(null);
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
// create field errors
|
17
|
+
useEffect(() => {
|
18
|
+
let newFieldErrors = fetchers[0]?.data?.fieldErrors || {};
|
19
|
+
if (!compareObjects(fetcherFieldErrors, newFieldErrors)) {
|
20
|
+
if (Object.entries(newFieldErrors).length !== 0) {
|
21
|
+
setFetcherFieldErrors(newFieldErrors);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}, [fetchers, actionData]);
|
25
|
+
// clear field errors
|
26
|
+
useEffect(() => {
|
27
|
+
if (fetchers[0]?.state === "submitting")
|
28
|
+
handleClearFields();
|
29
|
+
}, [fetchers, navigation]);
|
30
|
+
const responseFieldErrors = actionData?.fieldErrors || fetcherFieldErrors;
|
31
|
+
let mappedResponse = {};
|
32
|
+
Object.entries(responseFieldErrors || {}).forEach(([key, value]) => {
|
33
|
+
if (typeof value === "string" && typeof key === "string") {
|
34
|
+
mappedResponse[key] = value;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
return mappedResponse;
|
38
|
+
}
|
39
|
+
export { useFieldErrors };
|
package/dist/index.d.ts
CHANGED
@@ -26,6 +26,7 @@ export { Toast } from "./components/Toast";
|
|
26
26
|
export { Tooltip } from "./components/Tooltip";
|
27
27
|
export { useAutomation } from "./hooks/useAutomation";
|
28
28
|
export { useDrawer } from "./hooks/useDrawer";
|
29
|
+
export { useFieldErrors } from "./hooks/useFieldErrors";
|
29
30
|
export { useModal } from "./hooks/useModal";
|
30
31
|
export { useScopedParams } from "./hooks/useScopedParams";
|
31
32
|
export { useToast } from "./hooks/useToast";
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OA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AG5C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
@@ -31,6 +31,7 @@ export { Tooltip } from "./components/Tooltip";
|
|
31
31
|
// Hooks
|
32
32
|
export { useAutomation } from "./hooks/useAutomation";
|
33
33
|
export { useDrawer } from "./hooks/useDrawer";
|
34
|
+
export { useFieldErrors } from "./hooks/useFieldErrors";
|
34
35
|
export { useModal } from "./hooks/useModal";
|
35
36
|
export { useScopedParams } from "./hooks/useScopedParams";
|
36
37
|
export { useToast } from "./hooks/useToast";
|
package/package.json
CHANGED
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
} from "react";
|
11
11
|
|
12
12
|
import "./styles.css";
|
13
|
+
import { useFieldErrors } from "../../../hooks/useFieldErrors";
|
13
14
|
|
14
15
|
const FormControllerContext = createContext({} as FormControllerContextProps);
|
15
16
|
|
@@ -21,26 +22,7 @@ function FormController(props: FormControllerProps) {
|
|
21
22
|
...rest
|
22
23
|
} = props;
|
23
24
|
|
24
|
-
const
|
25
|
-
const fetchers = useFetchers();
|
26
|
-
|
27
|
-
const [fieldErrors, setFieldErrors] = useState<{ [x: string]: string }>({});
|
28
|
-
|
29
|
-
useEffect(() => {
|
30
|
-
let newFieldErrors = {};
|
31
|
-
if (actionData?.fieldErrors) newFieldErrors = actionData.fieldErrors;
|
32
|
-
|
33
|
-
fetchers.forEach((fetcher) => {
|
34
|
-
if (fetcher.data?.fieldErrors && fetcher.state === "loading") {
|
35
|
-
newFieldErrors = { ...newFieldErrors, ...fetcher.data.fieldErrors };
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
if (JSON.stringify(newFieldErrors) !== JSON.stringify(fieldErrors)) {
|
40
|
-
setFieldErrors(newFieldErrors);
|
41
|
-
}
|
42
|
-
}, [fetchers, actionData, fieldErrors]);
|
43
|
-
|
25
|
+
const fieldErrors = useFieldErrors();
|
44
26
|
const inputRef = useRef<HTMLInputElement>(null);
|
45
27
|
|
46
28
|
const name = inputRef.current?.name || "";
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { useActionData, useFetchers, useNavigation } from "@remix-run/react";
|
2
|
+
import { useEffect, useState } from "react";
|
3
|
+
|
4
|
+
function useFieldErrors() {
|
5
|
+
const actionData = useActionData<any>();
|
6
|
+
const navigation = useNavigation();
|
7
|
+
const fetchers = useFetchers();
|
8
|
+
|
9
|
+
const [fetcherFieldErrors, setFetcherFieldErrors] = useState<any>(null);
|
10
|
+
|
11
|
+
function compareObjects(obj1: any, obj2: any) {
|
12
|
+
return JSON.stringify(obj1) === JSON.stringify(obj2);
|
13
|
+
}
|
14
|
+
|
15
|
+
function handleClearFields() {
|
16
|
+
if (fetcherFieldErrors) setFetcherFieldErrors(null);
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
|
20
|
+
// create field errors
|
21
|
+
useEffect(() => {
|
22
|
+
let newFieldErrors = fetchers[0]?.data?.fieldErrors || {};
|
23
|
+
|
24
|
+
if (!compareObjects(fetcherFieldErrors, newFieldErrors)) {
|
25
|
+
if (Object.entries(newFieldErrors).length !== 0) {
|
26
|
+
setFetcherFieldErrors(newFieldErrors);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}, [fetchers, actionData]);
|
30
|
+
|
31
|
+
// clear field errors
|
32
|
+
useEffect(() => {
|
33
|
+
if (fetchers[0]?.state === "submitting") handleClearFields();
|
34
|
+
}, [fetchers, navigation]);
|
35
|
+
|
36
|
+
const responseFieldErrors = actionData?.fieldErrors || fetcherFieldErrors;
|
37
|
+
let mappedResponse: { [x: string]: string | undefined | null } = {};
|
38
|
+
|
39
|
+
Object.entries(responseFieldErrors || {}).forEach(([key, value]) => {
|
40
|
+
if (typeof value === "string" && typeof key === "string") {
|
41
|
+
mappedResponse[key] = value;
|
42
|
+
}
|
43
|
+
});
|
44
|
+
|
45
|
+
return mappedResponse;
|
46
|
+
}
|
47
|
+
|
48
|
+
export { useFieldErrors };
|
package/src/index.ts
CHANGED
@@ -47,6 +47,7 @@ export { Tooltip } from "./components/Tooltip";
|
|
47
47
|
// Hooks
|
48
48
|
export { useAutomation } from "./hooks/useAutomation";
|
49
49
|
export { useDrawer } from "./hooks/useDrawer";
|
50
|
+
export { useFieldErrors } from "./hooks/useFieldErrors";
|
50
51
|
export { useModal } from "./hooks/useModal";
|
51
52
|
export { useScopedParams } from "./hooks/useScopedParams";
|
52
53
|
export { useToast } from "./hooks/useToast";
|