@terreno/admin-frontend 0.7.2 → 0.8.0
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.
- package/dist/AdminFieldRenderer.d.ts +2 -0
- package/dist/AdminFieldRenderer.js +96 -3
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminModelForm.d.ts +11 -0
- package/dist/AdminModelForm.js +95 -24
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +4 -0
- package/dist/AdminModelList.js +10 -4
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.js +33 -33
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +26 -0
- package/dist/AdminNestedArrayField.js +118 -0
- package/dist/AdminNestedArrayField.js.map +1 -0
- package/dist/CheckboxListEditor.d.ts +15 -0
- package/dist/CheckboxListEditor.js +21 -0
- package/dist/CheckboxListEditor.js.map +1 -0
- package/dist/ConsentFormEditor.d.ts +12 -0
- package/dist/ConsentFormEditor.js +299 -0
- package/dist/ConsentFormEditor.js.map +1 -0
- package/dist/ConsentFormList.d.ts +9 -0
- package/dist/ConsentFormList.js +70 -0
- package/dist/ConsentFormList.js.map +1 -0
- package/dist/ConsentResponseViewer.d.ts +8 -0
- package/dist/ConsentResponseViewer.js +61 -0
- package/dist/ConsentResponseViewer.js.map +1 -0
- package/dist/LocaleContentEditor.d.ts +10 -0
- package/dist/LocaleContentEditor.js +48 -0
- package/dist/LocaleContentEditor.js.map +1 -0
- package/dist/generateConsentPdf.d.ts +26 -0
- package/dist/generateConsentPdf.js +210 -0
- package/dist/generateConsentPdf.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.js +2 -1
- package/dist/useAdminApi.js.map +1 -1
- package/package.json +3 -2
- package/src/AdminFieldRenderer.tsx +190 -2
- package/src/AdminModelForm.tsx +134 -40
- package/src/AdminModelList.tsx +35 -19
- package/src/AdminModelTable.tsx +40 -36
- package/src/AdminNestedArrayField.tsx +228 -0
- package/src/CheckboxListEditor.tsx +107 -0
- package/src/ConsentFormEditor.tsx +677 -0
- package/src/ConsentFormList.tsx +164 -0
- package/src/ConsentResponseViewer.tsx +228 -0
- package/src/LocaleContentEditor.tsx +151 -0
- package/src/generateConsentPdf.ts +264 -0
- package/src/index.tsx +7 -0
- package/src/types.ts +4 -0
- package/src/useAdminApi.ts +2 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import {jsPDF} from "jspdf";
|
|
2
|
+
import {DateTime} from "luxon";
|
|
3
|
+
|
|
4
|
+
interface ConsentResponseData {
|
|
5
|
+
_id?: string;
|
|
6
|
+
agreed: boolean;
|
|
7
|
+
agreedAt?: string;
|
|
8
|
+
checkboxValues?: Record<string, boolean>;
|
|
9
|
+
consentFormId?: {title?: string; slug?: string; version?: number; type?: string} | string;
|
|
10
|
+
contentSnapshot?: string;
|
|
11
|
+
formVersionSnapshot?: number;
|
|
12
|
+
ipAddress?: string;
|
|
13
|
+
locale?: string;
|
|
14
|
+
signature?: string;
|
|
15
|
+
signedAt?: string;
|
|
16
|
+
userAgent?: string;
|
|
17
|
+
userId?: {_id?: string; email?: string; name?: string} | string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const PAGE_WIDTH = 210;
|
|
21
|
+
const MARGIN_LEFT = 20;
|
|
22
|
+
const MARGIN_RIGHT = 20;
|
|
23
|
+
const CONTENT_WIDTH = PAGE_WIDTH - MARGIN_LEFT - MARGIN_RIGHT;
|
|
24
|
+
const PAGE_HEIGHT = 297;
|
|
25
|
+
const MARGIN_BOTTOM = 20;
|
|
26
|
+
|
|
27
|
+
const formatDate = (value: unknown): string => {
|
|
28
|
+
if (!value) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
const dt = DateTime.fromISO(String(value));
|
|
32
|
+
if (!dt.isValid) {
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
return dt.toLocaleString(DateTime.DATETIME_FULL);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const ensureSpace = (doc: jsPDF, y: number, needed: number): number => {
|
|
39
|
+
if (y + needed > PAGE_HEIGHT - MARGIN_BOTTOM) {
|
|
40
|
+
doc.addPage();
|
|
41
|
+
return 20;
|
|
42
|
+
}
|
|
43
|
+
return y;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const generateConsentPdf = async (response: ConsentResponseData): Promise<void> => {
|
|
47
|
+
const doc = new jsPDF({format: "a4", orientation: "portrait", unit: "mm"});
|
|
48
|
+
|
|
49
|
+
const formTitle =
|
|
50
|
+
typeof response.consentFormId === "object"
|
|
51
|
+
? (response.consentFormId?.title ?? "Unknown Form")
|
|
52
|
+
: "Unknown Form";
|
|
53
|
+
|
|
54
|
+
const formSlug =
|
|
55
|
+
typeof response.consentFormId === "object" ? (response.consentFormId?.slug ?? "") : "";
|
|
56
|
+
|
|
57
|
+
const formType =
|
|
58
|
+
typeof response.consentFormId === "object" ? (response.consentFormId?.type ?? "") : "";
|
|
59
|
+
|
|
60
|
+
const formVersion =
|
|
61
|
+
typeof response.consentFormId === "object"
|
|
62
|
+
? response.consentFormId?.version
|
|
63
|
+
: response.formVersionSnapshot;
|
|
64
|
+
|
|
65
|
+
const userId =
|
|
66
|
+
typeof response.userId === "object"
|
|
67
|
+
? (response.userId?._id ?? String(response.userId))
|
|
68
|
+
: String(response.userId ?? "");
|
|
69
|
+
|
|
70
|
+
const userEmail = typeof response.userId === "object" ? (response.userId?.email ?? "") : "";
|
|
71
|
+
|
|
72
|
+
const userName = typeof response.userId === "object" ? (response.userId?.name ?? "") : "";
|
|
73
|
+
|
|
74
|
+
let y = 20;
|
|
75
|
+
|
|
76
|
+
// Title
|
|
77
|
+
doc.setFontSize(18);
|
|
78
|
+
doc.setFont("helvetica", "bold");
|
|
79
|
+
doc.text("Consent Record", MARGIN_LEFT, y);
|
|
80
|
+
y += 10;
|
|
81
|
+
|
|
82
|
+
// Form title
|
|
83
|
+
doc.setFontSize(14);
|
|
84
|
+
doc.setFont("helvetica", "normal");
|
|
85
|
+
doc.text(formTitle, MARGIN_LEFT, y);
|
|
86
|
+
y += 10;
|
|
87
|
+
|
|
88
|
+
// Separator
|
|
89
|
+
doc.setDrawColor(200, 200, 200);
|
|
90
|
+
doc.line(MARGIN_LEFT, y, PAGE_WIDTH - MARGIN_RIGHT, y);
|
|
91
|
+
y += 8;
|
|
92
|
+
|
|
93
|
+
// Helper to add a labeled field
|
|
94
|
+
const addField = (label: string, value: string) => {
|
|
95
|
+
y = ensureSpace(doc, y, 8);
|
|
96
|
+
doc.setFontSize(9);
|
|
97
|
+
doc.setFont("helvetica", "bold");
|
|
98
|
+
doc.setTextColor(100, 100, 100);
|
|
99
|
+
doc.text(label, MARGIN_LEFT, y);
|
|
100
|
+
doc.setFont("helvetica", "normal");
|
|
101
|
+
doc.setTextColor(0, 0, 0);
|
|
102
|
+
doc.setFontSize(10);
|
|
103
|
+
doc.text(value, MARGIN_LEFT + 45, y);
|
|
104
|
+
y += 6;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Response Details
|
|
108
|
+
doc.setFontSize(12);
|
|
109
|
+
doc.setFont("helvetica", "bold");
|
|
110
|
+
doc.setTextColor(0, 0, 0);
|
|
111
|
+
doc.text("Response Details", MARGIN_LEFT, y);
|
|
112
|
+
y += 8;
|
|
113
|
+
|
|
114
|
+
if (formSlug) {
|
|
115
|
+
addField("Form Slug:", formSlug);
|
|
116
|
+
}
|
|
117
|
+
if (formType) {
|
|
118
|
+
addField("Form Type:", formType);
|
|
119
|
+
}
|
|
120
|
+
if (formVersion !== undefined) {
|
|
121
|
+
addField("Form Version:", String(formVersion));
|
|
122
|
+
}
|
|
123
|
+
addField("Decision:", response.agreed ? "Agreed" : "Declined");
|
|
124
|
+
if (response.agreedAt) {
|
|
125
|
+
addField("Agreed At:", formatDate(response.agreedAt));
|
|
126
|
+
}
|
|
127
|
+
if (response.locale) {
|
|
128
|
+
addField("Locale:", response.locale);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
y += 4;
|
|
132
|
+
|
|
133
|
+
// User Info
|
|
134
|
+
y = ensureSpace(doc, y, 20);
|
|
135
|
+
doc.setFontSize(12);
|
|
136
|
+
doc.setFont("helvetica", "bold");
|
|
137
|
+
doc.setTextColor(0, 0, 0);
|
|
138
|
+
doc.text("User Information", MARGIN_LEFT, y);
|
|
139
|
+
y += 8;
|
|
140
|
+
|
|
141
|
+
addField("User ID:", userId);
|
|
142
|
+
if (userName) {
|
|
143
|
+
addField("Name:", userName);
|
|
144
|
+
}
|
|
145
|
+
if (userEmail) {
|
|
146
|
+
addField("Email:", userEmail);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
y += 4;
|
|
150
|
+
|
|
151
|
+
// Checkbox Values
|
|
152
|
+
const checkboxEntries =
|
|
153
|
+
response.checkboxValues && typeof response.checkboxValues === "object"
|
|
154
|
+
? Object.entries(response.checkboxValues)
|
|
155
|
+
: [];
|
|
156
|
+
|
|
157
|
+
if (checkboxEntries.length > 0) {
|
|
158
|
+
y = ensureSpace(doc, y, 12 + checkboxEntries.length * 6);
|
|
159
|
+
doc.setFontSize(12);
|
|
160
|
+
doc.setFont("helvetica", "bold");
|
|
161
|
+
doc.setTextColor(0, 0, 0);
|
|
162
|
+
doc.text("Checkbox Responses", MARGIN_LEFT, y);
|
|
163
|
+
y += 8;
|
|
164
|
+
|
|
165
|
+
for (const [index, checked] of checkboxEntries) {
|
|
166
|
+
y = ensureSpace(doc, y, 6);
|
|
167
|
+
doc.setFontSize(10);
|
|
168
|
+
doc.setFont("helvetica", "normal");
|
|
169
|
+
const checkmark = checked ? "[x]" : "[ ]";
|
|
170
|
+
doc.text(`${checkmark} Checkbox ${index}`, MARGIN_LEFT + 4, y);
|
|
171
|
+
y += 6;
|
|
172
|
+
}
|
|
173
|
+
y += 4;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Audit Trail
|
|
177
|
+
const hasAuditTrail = response.ipAddress || response.userAgent || response.formVersionSnapshot;
|
|
178
|
+
|
|
179
|
+
if (hasAuditTrail) {
|
|
180
|
+
y = ensureSpace(doc, y, 20);
|
|
181
|
+
doc.setFontSize(12);
|
|
182
|
+
doc.setFont("helvetica", "bold");
|
|
183
|
+
doc.setTextColor(0, 0, 0);
|
|
184
|
+
doc.text("Audit Trail", MARGIN_LEFT, y);
|
|
185
|
+
y += 8;
|
|
186
|
+
|
|
187
|
+
if (response.ipAddress) {
|
|
188
|
+
addField("IP Address:", response.ipAddress);
|
|
189
|
+
}
|
|
190
|
+
if (response.userAgent) {
|
|
191
|
+
addField("User Agent:", response.userAgent);
|
|
192
|
+
}
|
|
193
|
+
if (response.formVersionSnapshot !== undefined) {
|
|
194
|
+
addField("Form Version:", String(response.formVersionSnapshot));
|
|
195
|
+
}
|
|
196
|
+
if (response.signedAt) {
|
|
197
|
+
addField("Signed At:", formatDate(response.signedAt));
|
|
198
|
+
}
|
|
199
|
+
y += 4;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Signature
|
|
203
|
+
if (response.signature) {
|
|
204
|
+
y = ensureSpace(doc, y, 50);
|
|
205
|
+
doc.setFontSize(12);
|
|
206
|
+
doc.setFont("helvetica", "bold");
|
|
207
|
+
doc.setTextColor(0, 0, 0);
|
|
208
|
+
doc.text("Signature", MARGIN_LEFT, y);
|
|
209
|
+
y += 6;
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
// signature is a base64 data URI (e.g. data:image/png;base64,...)
|
|
213
|
+
const sigData = response.signature;
|
|
214
|
+
const format = sigData.includes("image/png") ? "PNG" : "JPEG";
|
|
215
|
+
doc.addImage(sigData, format, MARGIN_LEFT, y, 80, 30);
|
|
216
|
+
y += 34;
|
|
217
|
+
} catch {
|
|
218
|
+
doc.setFontSize(10);
|
|
219
|
+
doc.setFont("helvetica", "italic");
|
|
220
|
+
doc.text("(Signature image could not be embedded)", MARGIN_LEFT, y);
|
|
221
|
+
y += 6;
|
|
222
|
+
}
|
|
223
|
+
y += 4;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Content Snapshot
|
|
227
|
+
if (response.contentSnapshot) {
|
|
228
|
+
y = ensureSpace(doc, y, 20);
|
|
229
|
+
doc.setFontSize(12);
|
|
230
|
+
doc.setFont("helvetica", "bold");
|
|
231
|
+
doc.setTextColor(0, 0, 0);
|
|
232
|
+
doc.text("Content Snapshot", MARGIN_LEFT, y);
|
|
233
|
+
y += 8;
|
|
234
|
+
|
|
235
|
+
doc.setFontSize(9);
|
|
236
|
+
doc.setFont("helvetica", "normal");
|
|
237
|
+
doc.setTextColor(50, 50, 50);
|
|
238
|
+
|
|
239
|
+
const lines = doc.splitTextToSize(response.contentSnapshot, CONTENT_WIDTH);
|
|
240
|
+
for (const line of lines) {
|
|
241
|
+
y = ensureSpace(doc, y, 5);
|
|
242
|
+
doc.text(line, MARGIN_LEFT, y);
|
|
243
|
+
y += 4;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Footer
|
|
248
|
+
y = ensureSpace(doc, y, 20);
|
|
249
|
+
y += 8;
|
|
250
|
+
doc.setDrawColor(200, 200, 200);
|
|
251
|
+
doc.line(MARGIN_LEFT, y, PAGE_WIDTH - MARGIN_RIGHT, y);
|
|
252
|
+
y += 6;
|
|
253
|
+
doc.setFontSize(8);
|
|
254
|
+
doc.setFont("helvetica", "italic");
|
|
255
|
+
doc.setTextColor(150, 150, 150);
|
|
256
|
+
doc.text(`Generated ${DateTime.now().toLocaleString(DateTime.DATETIME_FULL)}`, MARGIN_LEFT, y);
|
|
257
|
+
if (response._id) {
|
|
258
|
+
doc.text(`Response ID: ${response._id}`, PAGE_WIDTH - MARGIN_RIGHT, y, {align: "right"});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Download
|
|
262
|
+
const filename = `consent-${formSlug || "response"}-${userId.slice(-6)}-${DateTime.now().toFormat("yyyy-MM-dd")}.pdf`;
|
|
263
|
+
doc.save(filename);
|
|
264
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -2,14 +2,21 @@ export {AdminFieldRenderer} from "./AdminFieldRenderer";
|
|
|
2
2
|
export {AdminModelForm} from "./AdminModelForm";
|
|
3
3
|
export {AdminModelList} from "./AdminModelList";
|
|
4
4
|
export {AdminModelTable} from "./AdminModelTable";
|
|
5
|
+
export {AdminNestedArrayField} from "./AdminNestedArrayField";
|
|
5
6
|
export {AdminRefField} from "./AdminRefField";
|
|
6
7
|
export {AdminScriptList} from "./AdminScriptList";
|
|
7
8
|
export {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
8
9
|
export {AdminVersionConfig} from "./AdminVersionConfig";
|
|
10
|
+
export {CheckboxListEditor} from "./CheckboxListEditor";
|
|
9
11
|
export {ConfigurationScreen} from "./ConfigurationScreen";
|
|
12
|
+
export {ConsentFormEditor} from "./ConsentFormEditor";
|
|
13
|
+
export {ConsentFormList} from "./ConsentFormList";
|
|
14
|
+
export {ConsentResponseViewer} from "./ConsentResponseViewer";
|
|
10
15
|
export {DocumentStorageBrowser} from "./DocumentStorageBrowser";
|
|
16
|
+
export {LocaleContentEditor} from "./LocaleContentEditor";
|
|
11
17
|
export type {
|
|
12
18
|
AdminConfigResponse,
|
|
19
|
+
AdminCustomScreen,
|
|
13
20
|
AdminFieldConfig,
|
|
14
21
|
AdminModelConfig,
|
|
15
22
|
AdminScreenProps,
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface AdminFieldConfig {
|
|
|
8
8
|
default?: any;
|
|
9
9
|
ref?: string;
|
|
10
10
|
widget?: string;
|
|
11
|
+
/** For array fields: metadata about each item's sub-fields */
|
|
12
|
+
items?: Record<string, AdminFieldConfig>;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface AdminModelConfig {
|
|
@@ -17,9 +19,11 @@ export interface AdminModelConfig {
|
|
|
17
19
|
listFields: string[];
|
|
18
20
|
defaultSort: string;
|
|
19
21
|
fields: Record<string, AdminFieldConfig>;
|
|
22
|
+
fieldOrder?: string[];
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export interface AdminCustomScreen {
|
|
26
|
+
description?: string;
|
|
23
27
|
displayName: string;
|
|
24
28
|
name: string;
|
|
25
29
|
}
|
package/src/useAdminApi.ts
CHANGED
|
@@ -52,7 +52,8 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
52
52
|
const updateKey = `adminUpdate_${modelName}`;
|
|
53
53
|
const deleteKey = `adminDelete_${modelName}`;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const tagType = `admin_${modelName}`;
|
|
56
|
+
return api.enhanceEndpoints({addTagTypes: [tagType]}).injectEndpoints({
|
|
56
57
|
endpoints: (build: any) => ({
|
|
57
58
|
[listKey]: build.query({
|
|
58
59
|
providesTags: [`admin_${modelName}`],
|