@djb25/digit-ui-module-ekyc 1.0.24 → 1.0.26

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,207 +0,0 @@
1
- import React, { useState, useEffect, Fragment } from "react";
2
- import { CardLabel, TextInput, Dropdown, UploadFile, Toast, FormStep, Loader } from "@djb25/digit-ui-react-components";
3
- import { useTranslation } from "react-i18next";
4
-
5
- const AddressDetails = ({ config, onSelect }) => {
6
- const { t } = useTranslation();
7
-
8
- const tenantId = Digit.ULBService.getCurrentTenantId();
9
-
10
- // 🔹 STATES
11
- const [houseNo, setHouseNo] = useState("");
12
- const [street, setStreet] = useState("");
13
- const [locality, setLocality] = useState("");
14
- const [landmark, setLandmark] = useState("");
15
- const [subLocality, setSubLocality] = useState(null);
16
-
17
- const [pinCode, setPinCode] = useState("");
18
- const [assembly, setAssembly] = useState(null);
19
- const [ward, setWard] = useState(null);
20
- const [zone, setZone] = useState(null);
21
-
22
- const [latitude, setLatitude] = useState("");
23
- const [longitude, setLongitude] = useState("");
24
-
25
- const [addressType, setAddressType] = useState(null);
26
-
27
- const [doorPhoto, setDoorPhoto] = useState(null);
28
- const [doorPhotoFileStoreId, setDoorPhotoFileStoreId] = useState(null);
29
-
30
- const [toast, setToast] = useState(null);
31
-
32
- // 🔹 MDMS DATA
33
- const { data: mdmsData, isLoading } = Digit.Hooks.useCommonMDMS(tenantId, "egov-location", ["TenantBoundary"]);
34
-
35
- const assemblies = mdmsData?.MdmsRes?.["egov-location"]?.TenantBoundary?.[0]?.boundary?.children || [];
36
-
37
- // 🔹 AUTO GPS
38
- useEffect(() => {
39
- let isMounted = true;
40
-
41
- if (navigator.geolocation) {
42
- navigator.geolocation.getCurrentPosition(
43
- (pos) => {
44
- if (!isMounted) return;
45
- setLatitude(pos.coords.latitude);
46
- setLongitude(pos.coords.longitude);
47
- },
48
- () => {
49
- if (!isMounted) return;
50
- setToast({ type: "error", message: "GPS access denied" });
51
- }
52
- );
53
- }
54
-
55
- return () => {
56
- isMounted = false;
57
- };
58
- }, []);
59
-
60
- // 🔹 PIN CODE HANDLER
61
- const handlePincodeChange = (e) => {
62
- const value = e.target.value;
63
- if (/^\d{0,6}$/.test(value)) {
64
- setPinCode(value);
65
-
66
- if (value.length === 6) {
67
- fetchLocationByPincode(value);
68
- }
69
- }
70
- };
71
-
72
- // 🔹 MOCK PIN API (Replace with real API)
73
- const fetchLocationByPincode = (pin) => {
74
- // 🔥 Replace this with backend API
75
- console.log("Fetching location for PIN:", pin);
76
- };
77
-
78
- // 🔹 FILE UPLOAD
79
- const selectphoto = async (e) => {
80
- let isMounted = true;
81
-
82
- const file = e.target.files[0];
83
- if (!file) return;
84
-
85
- if (file.size >= 2000000) {
86
- setToast({ type: "error", message: "Max size 2MB exceeded" });
87
- return;
88
- }
89
-
90
- try {
91
- const res = await Digit.UploadServices.Filestorage("EKYC", file, tenantId);
92
-
93
- if (!isMounted) return;
94
-
95
- const fileStoreId = res?.data?.files?.[0]?.fileStoreId;
96
-
97
- if (fileStoreId) {
98
- setDoorPhotoFileStoreId(fileStoreId);
99
-
100
- const reader = new FileReader();
101
- reader.onloadend = () => {
102
- if (!isMounted) return;
103
- setDoorPhoto(reader.result);
104
- };
105
- reader.readAsDataURL(file);
106
-
107
- setToast({ type: "success", message: "Upload successful" });
108
- }
109
- } catch {
110
- if (!isMounted) return;
111
- setToast({ type: "error", message: "Upload failed" });
112
- }
113
-
114
- return () => {
115
- isMounted = false;
116
- };
117
- };
118
-
119
- const removePhoto = () => {
120
- setDoorPhoto(null);
121
- setDoorPhotoFileStoreId(null);
122
- };
123
-
124
- // 🔹 VALIDATION
125
- const isValid = () => {
126
- return houseNo && street && pinCode.length === 6 && assembly && ward && zone && latitude && longitude && doorPhotoFileStoreId;
127
- };
128
-
129
- // 🔹 SUBMIT
130
- const onStepSelect = () => {
131
- if (!isValid()) {
132
- setToast({ type: "error", message: "Please fill all mandatory fields" });
133
- return;
134
- }
135
-
136
- const data = {
137
- houseNo,
138
- street,
139
- locality,
140
- landmark,
141
- subLocality,
142
- pinCode,
143
- assembly: assembly?.name,
144
- ward: ward?.name,
145
- zone: zone?.name,
146
- latitude,
147
- longitude,
148
- addressType: addressType?.name,
149
- doorPhotoFilestoreId: doorPhotoFileStoreId,
150
- };
151
-
152
- onSelect(config.key, data);
153
- };
154
-
155
- if (isLoading) return <Loader />;
156
-
157
- return (
158
- <Fragment>
159
- <FormStep t={t} onSelect={onStepSelect} config={config} label={t("ES_COMMON_CONTINUE")}>
160
- <CardLabel>House No / Flat No *</CardLabel>
161
- <TextInput value={houseNo} onChange={(e) => setHouseNo(e.target.value)} />
162
-
163
- <CardLabel>Street / Address Line *</CardLabel>
164
- <TextInput value={street} onChange={(e) => setStreet(e.target.value)} />
165
-
166
- <CardLabel>Locality</CardLabel>
167
- <TextInput value={locality} onChange={(e) => setLocality(e.target.value)} />
168
-
169
- <CardLabel>Landmark</CardLabel>
170
- <TextInput value={landmark} onChange={(e) => setLandmark(e.target.value)} />
171
-
172
- <CardLabel>Sub Locality</CardLabel>
173
- <Dropdown option={[]} selected={subLocality} select={setSubLocality} />
174
-
175
- <CardLabel>PIN Code *</CardLabel>
176
- <TextInput value={pinCode} onChange={handlePincodeChange} maxLength={6} />
177
-
178
- <CardLabel>Assembly *</CardLabel>
179
- <Dropdown option={assemblies} selected={assembly} select={setAssembly} />
180
-
181
- <CardLabel>Ward *</CardLabel>
182
- <Dropdown option={assembly?.children || []} selected={ward} select={setWard} />
183
-
184
- <CardLabel>Zone *</CardLabel>
185
- <Dropdown option={ward?.children || []} selected={zone} select={setZone} />
186
-
187
- <CardLabel>Latitude</CardLabel>
188
- <TextInput value={latitude} disabled />
189
-
190
- <CardLabel>Longitude</CardLabel>
191
- <TextInput value={longitude} disabled />
192
-
193
- <CardLabel>Address Type</CardLabel>
194
- <Dropdown option={[{ name: "Permanent" }, { name: "Correspondence" }, { name: "Other" }]} selected={addressType} select={setAddressType} />
195
-
196
- <CardLabel>Door Image *</CardLabel>
197
- <UploadFile onUpload={selectphoto} onDelete={removePhoto} message={doorPhotoFileStoreId ? "Uploaded" : "No file selected"} />
198
-
199
- {doorPhoto && <img src={doorPhoto} alt="preview" style={{ width: "100%", marginTop: "10px" }} />}
200
-
201
- {toast && <Toast label={toast.message} error={toast.type === "error"} onClose={() => setToast(null)} />}
202
- </FormStep>
203
- </Fragment>
204
- );
205
- };
206
-
207
- export default AddressDetails;