@arkyn/components 1.3.130 → 1.3.132

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,2CA4BjD;AAED,iBAAS,iBAAiB,+BAEzB;AAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,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;AAItB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CA0CjD;AAED,iBAAS,iBAAiB,+BAEzB;AAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,14 +1,25 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useActionData } from "@remix-run/react";
3
- import { createContext, useContext, useId, useRef } from "react";
2
+ import { useActionData, useFetchers } from "@remix-run/react";
3
+ import { createContext, useContext, useEffect, useId, useRef, useState, } 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
+ const [fieldErrors, setFieldErrors] = useState({});
11
+ useEffect(() => {
12
+ let newFieldErrors = { ...actionData?.fieldErrors };
13
+ fetchers.forEach((fetcher) => {
14
+ if (fetcher.data?.fieldErrors) {
15
+ newFieldErrors = { ...newFieldErrors, ...fetcher.data.fieldErrors };
16
+ }
17
+ });
18
+ setFieldErrors(newFieldErrors);
19
+ }, [fetchers, actionData]);
9
20
  const inputRef = useRef(null);
10
21
  const name = inputRef.current?.name || "";
11
- const error = actionData?.fieldErrors?.[name] || null;
22
+ const error = fieldErrors?.[name] || null;
12
23
  const id = useId();
13
24
  const className = `arkynFormController ${baseClassName}`;
14
25
  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,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.130",
3
+ "version": "1.3.132",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -1,13 +1,19 @@
1
1
  import { FormControllerContextProps, FormControllerProps } from "@arkyn/types";
2
- import { useActionData } from "@remix-run/react";
3
- import { createContext, useContext, useId, useRef } from "react";
2
+ import { useActionData, useFetchers } from "@remix-run/react";
3
+ import {
4
+ createContext,
5
+ useContext,
6
+ useEffect,
7
+ useId,
8
+ useRef,
9
+ useState,
10
+ } from "react";
4
11
 
5
12
  import "./styles.css";
6
13
 
7
14
  const FormControllerContext = createContext({} as FormControllerContextProps);
8
15
 
9
16
  function FormController(props: FormControllerProps) {
10
- const actionData = useActionData<any>();
11
17
  const {
12
18
  children,
13
19
  className: baseClassName,
@@ -15,10 +21,25 @@ function FormController(props: FormControllerProps) {
15
21
  ...rest
16
22
  } = props;
17
23
 
24
+ const actionData = useActionData<any>();
25
+ const fetchers = useFetchers();
26
+
27
+ const [fieldErrors, setFieldErrors] = useState<{ [x: string]: string }>({});
28
+
29
+ useEffect(() => {
30
+ let newFieldErrors = { ...actionData?.fieldErrors };
31
+ fetchers.forEach((fetcher) => {
32
+ if (fetcher.data?.fieldErrors) {
33
+ newFieldErrors = { ...newFieldErrors, ...fetcher.data.fieldErrors };
34
+ }
35
+ });
36
+ setFieldErrors(newFieldErrors);
37
+ }, [fetchers, actionData]);
38
+
18
39
  const inputRef = useRef<HTMLInputElement>(null);
19
40
 
20
41
  const name = inputRef.current?.name || "";
21
- const error = actionData?.fieldErrors?.[name] || null;
42
+ const error = fieldErrors?.[name] || null;
22
43
 
23
44
  const id = useId();
24
45
  const className = `arkynFormController ${baseClassName}`;