@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,4 +1,4 @@
1
- import React, { useMemo, useState } from "react";
1
+ import React, { useMemo, useState, useRef, useEffect } from "react";
2
2
  import { ResponsiveContainer, BarChart, Bar, XAxis, YAxis, Tooltip, CartesianGrid, PieChart, Pie, Cell, Legend } from "recharts";
3
3
 
4
4
  import { Card, SubmitBar, ActionBar, Menu, Loader, Table } from "@djb25/digit-ui-react-components";
@@ -7,6 +7,7 @@ import { useTranslation } from "react-i18next";
7
7
  import { useParams } from "react-router-dom";
8
8
 
9
9
  import AssignEkycModal from "./AssignEkycModal";
10
+ import { downloadSurveyorPDF } from "../utils/reportDownloader";
10
11
 
11
12
  const SurveyorDetailsDashboard = () => {
12
13
  const tenantId = Digit.ULBService.getCurrentTenantId();
@@ -29,6 +30,25 @@ const SurveyorDetailsDashboard = () => {
29
30
  return surveyorSearchResponse?.surveyors?.[0] || null;
30
31
  }, [surveyorSearchResponse]);
31
32
 
33
+ const { data: vendorData } = Digit.Hooks.fsm.useDsoSearch(tenantId, { status: "ACTIVE" }, { enabled: !!tenantId });
34
+ const { data: supervisorSearchResponse } = Digit.Hooks.fsm.useSupervisorSearch(tenantId, { status: "ACTIVE" }, { enabled: !!tenantId });
35
+
36
+ const vendorName = useMemo(() => {
37
+ if (!vendorData || !surveyor?.vendorId) return "N/A";
38
+ const mappedVendor = vendorData.find((v) => v.dsoDetails?.id === surveyor.vendorId || v.dsoDetails?.vendorId === surveyor.vendorId);
39
+ return mappedVendor?.dsoDetails?.name || surveyor.vendorId || "N/A";
40
+ }, [vendorData, surveyor?.vendorId]);
41
+
42
+ const supervisorName = useMemo(() => {
43
+ if (!supervisorSearchResponse?.supervisors || !surveyor?.supervisorId) return "N/A";
44
+ const mappedSupervisor = supervisorSearchResponse.supervisors.find((s) => s.id === surveyor.supervisorId || s.owner?.uuid === surveyor.supervisorId);
45
+ return mappedSupervisor?.name || mappedSupervisor?.owner?.name || surveyor.supervisorId || "N/A";
46
+ }, [supervisorSearchResponse, surveyor?.supervisorId]);
47
+
48
+ const fullName = surveyor?.owner?.name || surveyor?.name || "N/A";
49
+ const employeeId = surveyor?.employeeId || surveyor?.owner?.uuid || surveyor?.id;
50
+ const mobileNumber = surveyor?.owner?.mobileNumber || surveyor?.mobileNo || "N/A";
51
+
32
52
  const [currentPage, setCurrentPage] = useState(0);
33
53
  const [pageSize, setPageSize] = useState(20);
34
54
  const queryParams = {
@@ -82,6 +102,24 @@ const SurveyorDetailsDashboard = () => {
82
102
  []
83
103
  );
84
104
 
105
+ // ─── Download Report hooks (must be before any early returns) ───────
106
+
107
+ const [showReportMenu, setShowReportMenu] = useState(false);
108
+ const [customDate, setCustomDate] = useState({ from: "", to: "" });
109
+ const [showCustomPicker, setShowCustomPicker] = useState(false);
110
+ const reportMenuRef = useRef(null);
111
+
112
+ useEffect(() => {
113
+ const handler = (e) => {
114
+ if (reportMenuRef.current && !reportMenuRef.current.contains(e.target)) {
115
+ setShowReportMenu(false);
116
+ setShowCustomPicker(false);
117
+ }
118
+ };
119
+ document.addEventListener("mousedown", handler);
120
+ return () => document.removeEventListener("mousedown", handler);
121
+ }, []);
122
+
85
123
  if (isLoading) {
86
124
  return <Loader />;
87
125
  }
@@ -122,6 +160,85 @@ const SurveyorDetailsDashboard = () => {
122
160
  },
123
161
  ];
124
162
 
163
+ const getDateRange = (filter) => {
164
+ const now = new Date();
165
+ const start = new Date(now);
166
+ if (filter === "today") {
167
+ start.setHours(0, 0, 0, 0);
168
+ return { from: start, to: now };
169
+ }
170
+ if (filter === "week") {
171
+ start.setDate(now.getDate() - now.getDay());
172
+ start.setHours(0, 0, 0, 0);
173
+ return { from: start, to: now };
174
+ }
175
+ if (filter === "month") {
176
+ start.setDate(1);
177
+ start.setHours(0, 0, 0, 0);
178
+ return { from: start, to: now };
179
+ }
180
+ return null;
181
+ };
182
+
183
+ const handlePresetDownload = (filter) => {
184
+ const allRows = dashboardData?.dashboardInfo?.consumerList || [];
185
+
186
+ const range = getDateRange(filter);
187
+
188
+ if (!range) return;
189
+
190
+ const filtered = allRows.filter((r) => {
191
+ const ts =
192
+ r.submittedAt ||
193
+ r.createdTime ||
194
+ r.lastModifiedTime ||
195
+ 0;
196
+
197
+ return ts >= range.from.getTime() && ts <= range.to.getTime();
198
+ });
199
+
200
+ downloadSurveyorPDF({
201
+ rows: filtered.length ? filtered : allRows,
202
+ surveyorName: fullName,
203
+ vendorName,
204
+ supervisorName,
205
+ employeeId,
206
+ mobileNumber,
207
+ dashboardInfo: dashboardData?.dashboardInfo,
208
+ t,
209
+ });
210
+
211
+ setShowReportMenu(false);
212
+ setShowCustomPicker(false);
213
+ };
214
+
215
+ const handleCustomDownload = () => {
216
+ if (!customDate.from || !customDate.to) {
217
+ alert(t("SELECT_DATE_RANGE") || "Please select both From and To dates.");
218
+ return;
219
+ }
220
+ const from = new Date(customDate.from);
221
+ const to = new Date(customDate.to);
222
+ to.setHours(23, 59, 59, 999);
223
+ const allRows = dashboardData?.dashboardInfo?.consumerList || [];
224
+ const filtered = allRows.filter((r) => {
225
+ const ts = r.createdTime || r.lastModifiedTime || 0;
226
+ return ts >= from.getTime() && ts <= to.getTime();
227
+ });
228
+ downloadSurveyorPDF({
229
+ rows: filtered.length ? filtered : allRows,
230
+ surveyorName: fullName,
231
+ vendorName,
232
+ supervisorName,
233
+ employeeId,
234
+ mobileNumber,
235
+ dashboardInfo: dashboardData?.dashboardInfo,
236
+ t,
237
+ });
238
+ setShowReportMenu(false);
239
+ setShowCustomPicker(false);
240
+ };
241
+
125
242
  const StatCard = ({ title, value, type, isLoading }) => (
126
243
  <div className={`stat-card ${type}`}>
127
244
  {isLoading ? (
@@ -140,23 +257,18 @@ const SurveyorDetailsDashboard = () => {
140
257
 
141
258
  const options = [{ action: "Assign" }];
142
259
 
143
- const fullName = surveyor?.owner?.name || surveyor?.name || "N/A";
144
-
145
- const employeeId = surveyor?.employeeId || surveyor?.owner?.uuid || surveyor?.id;
146
-
147
260
  const handleMenuSelect = (option) => {
148
261
  setShowOptions(false); // close menu
149
262
  setShowModal(true);
150
263
  };
151
264
 
152
265
  const closeModal = async () => {
153
- await refetchDashboard();
154
266
  setShowModal(false);
155
267
  };
156
268
 
157
269
  return (
158
270
  <Card className="surveyor-dashboard">
159
- {/* Header */}
271
+ {/* Header + Download Report */}
160
272
  <div className="ekyc-dashboard-section">
161
273
  <div className="ekyc-dashboard-header">
162
274
  <div className="avatar">{fullName?.charAt(0)?.toUpperCase()}</div>
@@ -171,6 +283,83 @@ const SurveyorDetailsDashboard = () => {
171
283
  </div>
172
284
  </div>
173
285
  </div>
286
+
287
+ {/* Download Report — far right */}
288
+ <div className="report-download" ref={reportMenuRef}>
289
+ <button
290
+ className="download-btn"
291
+ onClick={() => {
292
+ setShowReportMenu((p) => !p);
293
+ setShowCustomPicker(false);
294
+ }}
295
+ >
296
+ {t("DOWNLOAD_REPORT") || "Download Report"}
297
+ </button>
298
+
299
+ {showReportMenu && (
300
+ <div className="report-menu">
301
+ {[
302
+ { label: t("TODAY") || "Today", key: "today" },
303
+ { label: t("THIS_WEEK") || "This Week", key: "week" },
304
+ { label: t("THIS_MONTH") || "This Month", key: "month" },
305
+ ].map(({ label, key }) => (
306
+ <div
307
+ key={key}
308
+ className="menu-item"
309
+ onClick={() => handlePresetDownload(key)}
310
+ >
311
+ {label}
312
+ </div>
313
+ ))}
314
+
315
+ <div
316
+ className="custom-date-trigger"
317
+ onClick={() => setShowCustomPicker((p) => !p)}
318
+ >
319
+ {t("CUSTOM_DATE") || "Custom Date"}
320
+ </div>
321
+
322
+ {showCustomPicker && (
323
+ <div className="custom-picker">
324
+ <div className="date-field">
325
+ <label className="date-label">
326
+ {t("FROM_DATE") || "From"}
327
+ </label>
328
+ <input
329
+ type="date"
330
+ className="date-input"
331
+ value={customDate.from}
332
+ onChange={(e) =>
333
+ setCustomDate((d) => ({ ...d, from: e.target.value }))
334
+ }
335
+ />
336
+ </div>
337
+
338
+ <div className="date-field">
339
+ <label className="date-label">
340
+ {t("TO_DATE") || "To"}
341
+ </label>
342
+ <input
343
+ type="date"
344
+ className="date-input"
345
+ value={customDate.to}
346
+ onChange={(e) =>
347
+ setCustomDate((d) => ({ ...d, to: e.target.value }))
348
+ }
349
+ />
350
+ </div>
351
+
352
+ <button
353
+ className="download-action-btn"
354
+ onClick={handleCustomDownload}
355
+ >
356
+ {t("DOWNLOAD") || "Download"}
357
+ </button>
358
+ </div>
359
+ )}
360
+ </div>
361
+ )}
362
+ </div>
174
363
  </div>
175
364
 
176
365
  {/* Stats */}
@@ -291,27 +480,31 @@ const SurveyorDetailsDashboard = () => {
291
480
  />
292
481
  </Card>
293
482
  {/* Actions */}
294
- {(!roles.includes("EKYC_SURVEYOR") || roles.includes("EMPLOYEE")) && (
295
- <ActionBar>
296
- <SubmitBar label={t("EKYC_ASSIGN_KNOS")} onSubmit={() => setShowOptions((prev) => !prev)} />
297
-
298
- {showOptions && (
299
- <Menu
300
- options={options}
301
- optionKey={"action"}
302
- t={t}
303
- onSelect={handleMenuSelect}
304
- style={{
305
- color: "#FFFFFF",
306
- fontSize: "18px",
307
- }}
308
- />
309
- )}
310
- </ActionBar>
311
- )}
312
-
313
- {showModal && <AssignEkycModal surveyor={surveyor} closeModal={closeModal} />}
483
+ {
484
+ (!roles.includes("EKYC_SURVEYOR") || roles.includes("EMPLOYEE")) && (
485
+ <ActionBar>
486
+ <SubmitBar label={t("EKYC_ASSIGN_KNOS")} onSubmit={() => setShowOptions((prev) => !prev)} />
487
+
488
+ {showOptions && (
489
+ <Menu
490
+ options={options}
491
+ optionKey={"action"}
492
+ t={t}
493
+ onSelect={handleMenuSelect}
494
+ style={{
495
+ color: "#FFFFFF",
496
+ fontSize: "18px",
497
+ }}
498
+ />
499
+ )}
500
+ </ActionBar>
501
+
502
+ )
503
+ }
504
+
505
+ {showModal && <AssignEkycModal surveyor={surveyor} closeModal={closeModal} refetchDashboard={refetchDashboard} />}
314
506
  </Card>
507
+
315
508
  );
316
509
  };
317
510
 
@@ -0,0 +1,367 @@
1
+ import React from "react";
2
+ import { UploadFile, CheckBox, Dropdown } from "@djb25/digit-ui-react-components";
3
+
4
+ const AadhaarVerificationConfig = (t, formData = {}, uploadFile, setDocumentId, documentId) => {
5
+ const consumerType = formData?.consumerType?.name || formData?.consumerType;
6
+ const occupantType = formData?.occupantType?.name || formData?.occupantType;
7
+ const informantIsConsumer = formData?.informantIsConsumer ?? true;
8
+
9
+ const fields = [
10
+ {
11
+ label: t("Consumer Type"),
12
+ isMandatory: true,
13
+ type: "custom",
14
+ key: "consumerType",
15
+ populators: {
16
+ name: "consumerType",
17
+ component: (props) => (
18
+ <Dropdown
19
+ option={[{ name: "Individual" }, { name: "Govt" }, { name: "Company_Society_Org" }]}
20
+ optionKey="name"
21
+ selected={props.value}
22
+ select={props.onChange}
23
+ />
24
+ ),
25
+ },
26
+ },
27
+ {
28
+ label: t("Occupant Type"),
29
+ isMandatory: true,
30
+ type: "custom",
31
+ key: "occupantType",
32
+ populators: {
33
+ name: "occupantType",
34
+ component: (props) => (
35
+ <Dropdown
36
+ option={[{ name: "Self" }, { name: "Tenanted" }]}
37
+ optionKey="name"
38
+ selected={props.value}
39
+ select={props.onChange}
40
+ />
41
+ ),
42
+ },
43
+ },
44
+ {
45
+ label: t("Category Type"),
46
+ isMandatory: true,
47
+ type: "custom",
48
+ key: "categoryType",
49
+ populators: {
50
+ name: "categoryType",
51
+ component: (props) => (
52
+ <Dropdown
53
+ option={[{ name: "Bulk" }, { name: "Non-Bulk" }]}
54
+ optionKey="name"
55
+ selected={props.value}
56
+ select={props.onChange}
57
+ />
58
+ ),
59
+ },
60
+ },
61
+ {
62
+ label: t("First Name"),
63
+ isMandatory: true,
64
+ type: "text",
65
+ populators: {
66
+ name: "firstName",
67
+ validation: { required: true },
68
+ },
69
+ },
70
+ {
71
+ label: t("Middle Name"),
72
+ isMandatory: false,
73
+ type: "text",
74
+ populators: {
75
+ name: "middleName",
76
+ },
77
+ },
78
+ {
79
+ label: t("Last Name"),
80
+ isMandatory: false,
81
+ type: "text",
82
+ populators: {
83
+ name: "lastName",
84
+ },
85
+ },
86
+ {
87
+ label: t("Gender"),
88
+ isMandatory: false,
89
+ type: "custom",
90
+ key: "gender",
91
+ populators: {
92
+ name: "gender",
93
+ component: (props) => (
94
+ <Dropdown
95
+ option={[{ name: "Male" }, { name: "Female" }, { name: "Others" }, { name: "Not prefer to say" }]}
96
+ optionKey="name"
97
+ selected={props.value}
98
+ select={props.onChange}
99
+ />
100
+ ),
101
+ },
102
+ },
103
+ {
104
+ label: t("Parent/Spouse Name"),
105
+ isMandatory: false,
106
+ type: "text",
107
+ populators: {
108
+ name: "parentSpouseName",
109
+ },
110
+ },
111
+ {
112
+ label: t("Mobile"),
113
+ isMandatory: true,
114
+ type: "text",
115
+ populators: {
116
+ name: "mobile",
117
+ validation: {
118
+ required: true,
119
+ pattern: /^[6-9]\d{9}$/,
120
+ },
121
+ error: t("Invalid mobile number"),
122
+ },
123
+ },
124
+ {
125
+ label: t("WhatsApp"),
126
+ isMandatory: false,
127
+ type: "text",
128
+ populators: {
129
+ name: "whatsapp",
130
+ },
131
+ },
132
+ {
133
+ label: t("Email"),
134
+ isMandatory: false,
135
+ type: "text",
136
+ populators: {
137
+ name: "email",
138
+ validation: {
139
+ pattern: /^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+$/,
140
+ },
141
+ error: t("Invalid email address"),
142
+ },
143
+ },
144
+ {
145
+ label: t("No. of Residents"),
146
+ isMandatory: true,
147
+ type: "text",
148
+ populators: {
149
+ name: "residents",
150
+ validation: {
151
+ required: true,
152
+ min: 1,
153
+ },
154
+ },
155
+ },
156
+ {
157
+ label: t("Type of Identity"),
158
+ isMandatory: true,
159
+ type: "custom",
160
+ key: "identityType",
161
+ populators: {
162
+ name: "identityType",
163
+ component: (props) => (
164
+ <Dropdown
165
+ option={[{ name: "Aadhaar Card" }, { name: "Driving License" }, { name: "Passport" }, { name: "Voter ID" }]}
166
+ optionKey="name"
167
+ selected={props.value}
168
+ select={props.onChange}
169
+ />
170
+ ),
171
+ },
172
+ },
173
+ {
174
+ label: t("Proof of Identity"),
175
+ isMandatory: false,
176
+ type: "custom",
177
+ key: "idFile",
178
+ populators: {
179
+ name: "idFile",
180
+ component: (props) => (
181
+ <UploadFile
182
+ onUpload={(e) => uploadFile(e, props.onChange)}
183
+ onDelete={() => {
184
+ props.onChange(null);
185
+ setDocumentId(null);
186
+ }}
187
+ message={props.value ? t("Uploaded") : t("No file selected")}
188
+ />
189
+ ),
190
+ },
191
+ },
192
+ {
193
+ label: t("Document Number"),
194
+ isMandatory: false,
195
+ type: "text",
196
+ populators: {
197
+ name: "documentNumber",
198
+ },
199
+ },
200
+ {
201
+ label: t("Informant Is Consumer"),
202
+ isMandatory: false,
203
+ type: "custom",
204
+ key: "informantIsConsumer",
205
+ populators: {
206
+ name: "informantIsConsumer",
207
+ component: (props) => (
208
+ <CheckBox
209
+ label={t("Yes, the informant is the consumer")}
210
+ checked={props.value ?? true}
211
+ onChange={(e) => props.onChange(e.target.checked)}
212
+ />
213
+ ),
214
+ },
215
+ },
216
+ ];
217
+
218
+ // Informant conditional fields
219
+ if (!informantIsConsumer) {
220
+ fields.push(
221
+ {
222
+ label: t("Informant Name"),
223
+ isMandatory: false,
224
+ type: "text",
225
+ populators: {
226
+ name: "informantName",
227
+ },
228
+ },
229
+ {
230
+ label: t("Informant Relation"),
231
+ isMandatory: false,
232
+ type: "text",
233
+ populators: {
234
+ name: "informantRelation",
235
+ },
236
+ }
237
+ );
238
+ }
239
+
240
+ // Tenant conditional fields
241
+ if (occupantType === "Tenanted") {
242
+ fields.push({
243
+ label: t("Document Proof"),
244
+ isMandatory: false,
245
+ type: "custom",
246
+ key: "documentProof",
247
+ populators: {
248
+ name: "documentProof",
249
+ component: (props) => (
250
+ <UploadFile
251
+ onUpload={(e) => uploadFile(e, props.onChange)}
252
+ onDelete={() => {
253
+ props.onChange(null);
254
+ setDocumentId(null);
255
+ }}
256
+ message={props.value ? t("Uploaded") : t("No file selected")}
257
+ />
258
+ ),
259
+ },
260
+ });
261
+
262
+ if (!documentId) {
263
+ fields.push(
264
+ {
265
+ label: t("Owner Mobile"),
266
+ isMandatory: true,
267
+ type: "text",
268
+ populators: {
269
+ name: "ownerMobile",
270
+ validation: {
271
+ required: true,
272
+ pattern: /^[6-9]\d{9}$/,
273
+ },
274
+ },
275
+ },
276
+ {
277
+ label: t("Tenant Verification"),
278
+ isMandatory: false,
279
+ type: "text",
280
+ populators: {
281
+ name: "tenantVerification",
282
+ },
283
+ }
284
+ );
285
+ }
286
+ }
287
+
288
+ // Govt conditional fields
289
+ if (consumerType === "Govt") {
290
+ fields.push(
291
+ {
292
+ label: t("Designation"),
293
+ isMandatory: false,
294
+ type: "text",
295
+ populators: {
296
+ name: "designation",
297
+ },
298
+ },
299
+ {
300
+ label: t("Department"),
301
+ isMandatory: false,
302
+ type: "text",
303
+ populators: {
304
+ name: "department",
305
+ },
306
+ },
307
+ {
308
+ label: t("Employee ID"),
309
+ isMandatory: false,
310
+ type: "text",
311
+ populators: {
312
+ name: "employeeId",
313
+ },
314
+ }
315
+ );
316
+ }
317
+
318
+ // Company / Society / Org conditional fields
319
+ if (consumerType === "Company_Society_Org") {
320
+ fields.push(
321
+ {
322
+ label: t("Entity Name"),
323
+ isMandatory: false,
324
+ type: "text",
325
+ populators: {
326
+ name: "entityName",
327
+ },
328
+ },
329
+ {
330
+ label: t("Contact Person"),
331
+ isMandatory: false,
332
+ type: "text",
333
+ populators: {
334
+ name: "contactPerson",
335
+ },
336
+ }
337
+ );
338
+ }
339
+
340
+ // Consent checkbox field
341
+ fields.push({
342
+ label: t("Consent"),
343
+ isMandatory: true,
344
+ type: "custom",
345
+ key: "consent",
346
+ populators: {
347
+ name: "consent",
348
+ validation: { required: true },
349
+ component: (props) => (
350
+ <CheckBox
351
+ label={t("I hereby consent to verify my Aadhaar details.")}
352
+ checked={props.value ?? false}
353
+ onChange={(e) => props.onChange(e.target.checked)}
354
+ />
355
+ ),
356
+ },
357
+ });
358
+
359
+ return [
360
+ {
361
+ head: t("EKYC_CONSUMER_CONNECTION"),
362
+ body: fields,
363
+ },
364
+ ];
365
+ };
366
+
367
+ export default AadhaarVerificationConfig;