@djb25/digit-ui-module-ekyc 1.0.0 → 1.0.2

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,77 +0,0 @@
1
- import React, { useEffect, useRef } from "react";
2
- import { useForm, Controller } from "react-hook-form";
3
- import { TextInput, Label, LinkLabel, Dropdown } from "@djb25/digit-ui-react-components";
4
- import { useTranslation } from "react-i18next";
5
-
6
- const SearchApplication = ({ onSearch, searchFields, searchParams }) => {
7
- const { t } = useTranslation();
8
- const { register, handleSubmit, reset, watch, control } = useForm({
9
- defaultValues: searchParams,
10
- });
11
-
12
- const onSubmitInput = (data) => {
13
- onSearch(data);
14
- };
15
-
16
- function clearSearch() {
17
- const resetValues = searchFields.reduce((acc, field) => ({ ...acc, [field?.name]: "" }), {});
18
- reset(resetValues);
19
- onSearch({ ...resetValues });
20
- }
21
-
22
- // Watch all fields
23
- const watchedFields = watch();
24
- const prevFields = useRef(watchedFields);
25
-
26
- // Trigger search only when fields actually change and compare values to avoid loops
27
- useEffect(() => {
28
- const isChanged = JSON.stringify(prevFields.current) !== JSON.stringify(watchedFields);
29
- if (isChanged) {
30
- prevFields.current = watchedFields;
31
- // Debounce or delay if needed, but for dropdowns immediate is fine
32
- const timeoutId = setTimeout(() => {
33
- onSearch(watchedFields);
34
- }, 300); // Small debounce to be safe
35
- return () => clearTimeout(timeoutId);
36
- }
37
- }, [watchedFields, onSearch]);
38
-
39
- return (
40
- <form onSubmit={handleSubmit(onSubmitInput)} style={{ flex: 1 }}>
41
- <div className="search-container" style={{ backgroundColor: "#ffffffff", padding: "24px" }}>
42
- <div className="complaint-input-container" style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(700px, 1fr))", gap: "20px", alignItems: "end" }}>
43
- {searchFields?.map((input) => (
44
- <div key={input.name} className="input-fields">
45
- <Label>{input.label}</Label>
46
- {input.type === "dropdown" ? (
47
- <Controller
48
- control={control}
49
- name={input.name}
50
- render={(props) => (
51
- <Dropdown
52
- selected={props.value}
53
- select={(val) => {
54
- props.onChange(val);
55
- }}
56
- onBlur={props.onBlur}
57
- option={input.options}
58
- optionKey={input.optionsKey}
59
- t={t}
60
- />
61
- )}
62
- />
63
- ) : (
64
- <TextInput {...input} inputRef={register} watch={watch} />
65
- )}
66
- </div>
67
- ))}
68
- {/* <div className="search-submit-wrapper" style={{ display: "flex", alignItems: "center", gap: "20px", height: "40px" }}>
69
- <LinkLabel onClick={clearSearch}>{t("ES_COMMON_CLEAR_ALL")}</LinkLabel>
70
- </div> */}
71
- </div>
72
- </div>
73
- </form>
74
- );
75
- };
76
-
77
- export default SearchApplication;