@terreno/admin-frontend 0.13.0 → 0.14.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 +5 -53
- package/dist/AdminFieldRenderer.js +6 -168
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +26 -0
- package/dist/AdminFieldRendererCore.js +138 -0
- package/dist/AdminFieldRendererCore.js.map +1 -0
- package/dist/AdminModelForm.d.ts +6 -7
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +2 -3
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -2
- package/dist/AdminModelTable.js +2 -1
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +6 -7
- package/dist/AdminNestedArrayField.js +26 -2
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +2 -2
- package/dist/AdminObjectPicker.js +12 -7
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +2 -3
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminScriptList.d.ts +2 -2
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +2 -2
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminVersionConfig.d.ts +2 -2
- package/dist/AdminVersionConfig.js +15 -10
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.d.ts +2 -2
- package/dist/ConfigurationScreen.js +18 -9
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.d.ts +27 -2
- package/dist/ConsentFormEditor.js +7 -5
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.d.ts +2 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.d.ts +2 -1
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/types.d.ts +29 -4
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +2 -2
- package/dist/useAdminApi.js +9 -5
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.d.ts +2 -3
- package/dist/useAdminConfig.js +1 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.d.ts +2 -3
- package/dist/useAdminScripts.js +5 -3
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.d.ts +11 -8
- package/dist/useConfigurationApi.js +6 -4
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.d.ts +2 -2
- package/dist/useDocumentStorageApi.js +8 -6
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +1 -0
- package/src/AdminFieldRenderer.tsx +18 -371
- package/src/AdminFieldRendererCore.tsx +356 -0
- package/src/AdminModelForm.test.tsx +1 -0
- package/src/AdminModelForm.tsx +22 -17
- package/src/AdminModelList.test.tsx +1 -0
- package/src/AdminModelList.tsx +5 -5
- package/src/AdminModelTable.test.tsx +1 -0
- package/src/AdminModelTable.tsx +11 -10
- package/src/AdminNestedArrayField.tsx +91 -26
- package/src/AdminObjectPicker.tsx +32 -16
- package/src/AdminPrimitiveArrayField.test.tsx +1 -0
- package/src/AdminPrimitiveArrayField.tsx +2 -3
- package/src/AdminScriptList.test.tsx +1 -0
- package/src/AdminScriptList.tsx +2 -3
- package/src/AdminScriptRunModal.test.tsx +3 -2
- package/src/AdminScriptRunModal.tsx +2 -3
- package/src/AdminVersionConfig.test.tsx +21 -0
- package/src/AdminVersionConfig.tsx +28 -5
- package/src/CheckboxListEditor.test.tsx +1 -0
- package/src/ConfigurationScreen.test.tsx +1 -0
- package/src/ConfigurationScreen.tsx +43 -29
- package/src/ConsentFormEditor.test.tsx +1 -0
- package/src/ConsentFormEditor.tsx +34 -18
- package/src/ConsentFormList.test.tsx +1 -0
- package/src/ConsentFormList.tsx +14 -2
- package/src/ConsentResponseViewer.test.tsx +1 -0
- package/src/ConsentResponseViewer.tsx +3 -2
- package/src/DocumentStorageBrowser.test.tsx +1 -0
- package/src/DocumentStorageBrowser.tsx +4 -4
- package/src/LocaleContentEditor.test.tsx +1 -0
- package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -0
- package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -0
- package/src/isolated/AdminObjectPicker.isolated.tsx +1 -0
- package/src/isolated/AdminRefField.isolated.tsx +1 -0
- package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -0
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -0
- package/src/isolated/hooks.isolated.tsx +1 -0
- package/src/types.ts +34 -4
- package/src/useAdminApi.ts +22 -13
- package/src/useAdminConfig.ts +4 -4
- package/src/useAdminScripts.ts +8 -7
- package/src/useConfigurationApi.ts +25 -12
- package/src/useDocumentStorageApi.ts +11 -9
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {
|
|
3
2
|
BooleanField,
|
|
4
3
|
Box,
|
|
@@ -14,14 +13,22 @@ import {
|
|
|
14
13
|
} from "@terreno/ui";
|
|
15
14
|
import startCase from "lodash/startCase";
|
|
16
15
|
import React, {useCallback, useMemo, useState} from "react";
|
|
16
|
+
import type {AdminApi} from "./types";
|
|
17
17
|
import {useConfigurationApi} from "./useConfigurationApi";
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Configuration field/section values are heterogeneous across consumer apps — each app
|
|
21
|
+
* registers its own configuration schema with arbitrary field types. We treat them as
|
|
22
|
+
* unknown shapes at this boundary and narrow when rendering individual fields.
|
|
23
|
+
*/
|
|
24
|
+
type ConfigValue = unknown;
|
|
25
|
+
|
|
19
26
|
interface ConfigFieldMeta {
|
|
20
27
|
type: string;
|
|
21
28
|
required: boolean;
|
|
22
29
|
description?: string;
|
|
23
30
|
enum?: string[];
|
|
24
|
-
default?:
|
|
31
|
+
default?: ConfigValue;
|
|
25
32
|
secret?: boolean;
|
|
26
33
|
widget?: string;
|
|
27
34
|
}
|
|
@@ -41,7 +48,7 @@ interface ConfigurationScreenProps {
|
|
|
41
48
|
/** Base URL for configuration routes (e.g., "/configuration"). */
|
|
42
49
|
basePath?: string;
|
|
43
50
|
/** RTK Query API instance. */
|
|
44
|
-
api:
|
|
51
|
+
api: AdminApi;
|
|
45
52
|
/** Optional title override. Defaults to "Configuration". */
|
|
46
53
|
title?: string;
|
|
47
54
|
}
|
|
@@ -52,8 +59,8 @@ interface ConfigurationScreenProps {
|
|
|
52
59
|
const ConfigField: React.FC<{
|
|
53
60
|
fieldKey: string;
|
|
54
61
|
fieldMeta: ConfigFieldMeta;
|
|
55
|
-
value:
|
|
56
|
-
onChange: (value:
|
|
62
|
+
value: ConfigValue;
|
|
63
|
+
onChange: (value: ConfigValue) => void;
|
|
57
64
|
sectionName: string;
|
|
58
65
|
}> = ({fieldKey, fieldMeta, value, onChange, sectionName}) => {
|
|
59
66
|
const label = startCase(fieldKey);
|
|
@@ -61,13 +68,10 @@ const ConfigField: React.FC<{
|
|
|
61
68
|
const testID = `config-${sectionName}-${fieldKey}`;
|
|
62
69
|
|
|
63
70
|
if (fieldMeta.type === "boolean") {
|
|
71
|
+
const boolValue =
|
|
72
|
+
typeof value === "boolean" ? value : ((fieldMeta.default as boolean) ?? false);
|
|
64
73
|
return (
|
|
65
|
-
<BooleanField
|
|
66
|
-
helperText={helperText}
|
|
67
|
-
onChange={onChange}
|
|
68
|
-
title={label}
|
|
69
|
-
value={value ?? fieldMeta.default ?? false}
|
|
70
|
-
/>
|
|
74
|
+
<BooleanField helperText={helperText} onChange={onChange} title={label} value={boolValue} />
|
|
71
75
|
);
|
|
72
76
|
}
|
|
73
77
|
|
|
@@ -76,8 +80,14 @@ const ConfigField: React.FC<{
|
|
|
76
80
|
<TextField
|
|
77
81
|
helperText={helperText}
|
|
78
82
|
onChange={(text: string) => {
|
|
83
|
+
if (text === "") {
|
|
84
|
+
onChange("");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
79
87
|
const num = Number(text);
|
|
80
|
-
|
|
88
|
+
if (!Number.isNaN(num)) {
|
|
89
|
+
onChange(num);
|
|
90
|
+
}
|
|
81
91
|
}}
|
|
82
92
|
testID={testID}
|
|
83
93
|
title={label}
|
|
@@ -93,7 +103,7 @@ const ConfigField: React.FC<{
|
|
|
93
103
|
onChange={onChange}
|
|
94
104
|
testID={testID}
|
|
95
105
|
title={label}
|
|
96
|
-
value={value
|
|
106
|
+
value={typeof value === "string" ? value : ""}
|
|
97
107
|
/>
|
|
98
108
|
);
|
|
99
109
|
}
|
|
@@ -106,7 +116,7 @@ const ConfigField: React.FC<{
|
|
|
106
116
|
testID={testID}
|
|
107
117
|
title={`${label} (Secret)`}
|
|
108
118
|
type="password"
|
|
109
|
-
value={value
|
|
119
|
+
value={typeof value === "string" ? value : ""}
|
|
110
120
|
/>
|
|
111
121
|
);
|
|
112
122
|
}
|
|
@@ -117,7 +127,7 @@ const ConfigField: React.FC<{
|
|
|
117
127
|
onChange={onChange}
|
|
118
128
|
testID={testID}
|
|
119
129
|
title={label}
|
|
120
|
-
value={value
|
|
130
|
+
value={typeof value === "string" ? value : ""}
|
|
121
131
|
/>
|
|
122
132
|
);
|
|
123
133
|
};
|
|
@@ -130,10 +140,13 @@ const SectionDescription: React.FC<{description: string}> = ({description}) => (
|
|
|
130
140
|
|
|
131
141
|
const SectionCard: React.FC<{
|
|
132
142
|
section: ConfigSectionMeta;
|
|
133
|
-
formState: Record<string,
|
|
134
|
-
onFieldChange: (sectionName: string, fieldKey: string, value:
|
|
143
|
+
formState: Record<string, ConfigValue>;
|
|
144
|
+
onFieldChange: (sectionName: string, fieldKey: string, value: ConfigValue) => void;
|
|
135
145
|
}> = ({section, formState, onFieldChange}) => {
|
|
136
|
-
const sectionValues =
|
|
146
|
+
const sectionValues =
|
|
147
|
+
section.name === "__root__"
|
|
148
|
+
? formState
|
|
149
|
+
: ((formState[section.name] as Record<string, ConfigValue> | undefined) ?? {});
|
|
137
150
|
return (
|
|
138
151
|
<Card padding={4}>
|
|
139
152
|
<Box gap={3}>
|
|
@@ -146,7 +159,7 @@ const SectionCard: React.FC<{
|
|
|
146
159
|
fieldKey={fieldKey}
|
|
147
160
|
fieldMeta={fieldMeta}
|
|
148
161
|
key={fieldKey}
|
|
149
|
-
onChange={(value:
|
|
162
|
+
onChange={(value: ConfigValue) => onFieldChange(section.name, fieldKey, value)}
|
|
150
163
|
sectionName={section.name}
|
|
151
164
|
value={sectionValues[fieldKey]}
|
|
152
165
|
/>
|
|
@@ -190,7 +203,7 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
|
|
|
190
203
|
const [updateConfig, {isLoading: isSaving}] = useUpdateMutation();
|
|
191
204
|
|
|
192
205
|
// Tracks only the fields the user has explicitly edited. null = no edits yet.
|
|
193
|
-
const [userEdits, setUserEdits] = useState<Record<string,
|
|
206
|
+
const [userEdits, setUserEdits] = useState<Record<string, ConfigValue> | null>(null);
|
|
194
207
|
const [isDirty, setIsDirty] = useState(false);
|
|
195
208
|
|
|
196
209
|
const toast = useToast();
|
|
@@ -198,26 +211,27 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
|
|
|
198
211
|
const configMeta = meta as ConfigurationMetaResponse | undefined;
|
|
199
212
|
// The baseQuery in emptyApi.ts unwraps {data: ...} responses, so valuesResponse
|
|
200
213
|
// is already the config document — not a wrapper object.
|
|
201
|
-
const configValues = valuesResponse as Record<string,
|
|
214
|
+
const configValues = valuesResponse as Record<string, ConfigValue> | undefined;
|
|
202
215
|
|
|
203
216
|
// Derived synchronously so the form is never blank when data is already cached.
|
|
204
|
-
const serverValues = useMemo((): Record<string,
|
|
217
|
+
const serverValues = useMemo((): Record<string, ConfigValue> => {
|
|
205
218
|
if (!configValues || !configMeta) return {};
|
|
206
219
|
const emptyDefault = (fieldMeta: ConfigFieldMeta) =>
|
|
207
220
|
fieldMeta.type === "boolean" ? false : "";
|
|
208
|
-
const initial: Record<string,
|
|
221
|
+
const initial: Record<string, ConfigValue> = {};
|
|
209
222
|
for (const section of configMeta.sections) {
|
|
210
223
|
if (section.name === "__root__") {
|
|
211
224
|
for (const [key, fieldMeta] of Object.entries(section.fields)) {
|
|
212
225
|
initial[key] = configValues[key] ?? fieldMeta.default ?? emptyDefault(fieldMeta);
|
|
213
226
|
}
|
|
214
227
|
} else {
|
|
215
|
-
|
|
216
|
-
const sectionValues =
|
|
228
|
+
const nestedInitial: Record<string, ConfigValue> = {};
|
|
229
|
+
const sectionValues =
|
|
230
|
+
(configValues[section.name] as Record<string, ConfigValue> | undefined) ?? {};
|
|
217
231
|
for (const [key, fieldMeta] of Object.entries(section.fields)) {
|
|
218
|
-
|
|
219
|
-
sectionValues[key] ?? fieldMeta.default ?? emptyDefault(fieldMeta);
|
|
232
|
+
nestedInitial[key] = sectionValues[key] ?? fieldMeta.default ?? emptyDefault(fieldMeta);
|
|
220
233
|
}
|
|
234
|
+
initial[section.name] = nestedInitial;
|
|
221
235
|
}
|
|
222
236
|
}
|
|
223
237
|
return initial;
|
|
@@ -226,7 +240,7 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
|
|
|
226
240
|
const formState = userEdits ?? serverValues;
|
|
227
241
|
|
|
228
242
|
const handleFieldChange = useCallback(
|
|
229
|
-
(sectionName: string, fieldKey: string, value:
|
|
243
|
+
(sectionName: string, fieldKey: string, value: ConfigValue) => {
|
|
230
244
|
setIsDirty(true);
|
|
231
245
|
setUserEdits((prev) => {
|
|
232
246
|
const base = prev ?? serverValues;
|
|
@@ -236,7 +250,7 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
|
|
|
236
250
|
return {
|
|
237
251
|
...base,
|
|
238
252
|
[sectionName]: {
|
|
239
|
-
...(base[sectionName] as Record<string,
|
|
253
|
+
...(base[sectionName] as Record<string, ConfigValue>),
|
|
240
254
|
[fieldKey]: value,
|
|
241
255
|
},
|
|
242
256
|
};
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
useToast,
|
|
16
16
|
} from "@terreno/ui";
|
|
17
17
|
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
|
18
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
18
19
|
import {useAdminApi} from "./useAdminApi";
|
|
19
20
|
|
|
20
21
|
interface CheckboxConfig {
|
|
@@ -23,13 +24,33 @@ interface CheckboxConfig {
|
|
|
23
24
|
confirmationPrompt?: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/** Consent form document — shape comes from the consumer's Mongoose model. */
|
|
28
|
+
interface ConsentFormDocument {
|
|
29
|
+
_id?: string;
|
|
30
|
+
title?: string;
|
|
31
|
+
slug?: string;
|
|
32
|
+
type?: string;
|
|
33
|
+
order?: number;
|
|
34
|
+
required?: boolean;
|
|
35
|
+
active?: boolean;
|
|
36
|
+
captureSignature?: boolean;
|
|
37
|
+
requireScrollToBottom?: boolean;
|
|
38
|
+
defaultLocale?: string;
|
|
39
|
+
agreeButtonText?: string;
|
|
40
|
+
allowDecline?: boolean;
|
|
41
|
+
declineButtonText?: string;
|
|
42
|
+
content?: Record<string, string>;
|
|
43
|
+
checkboxes?: CheckboxConfig[];
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
26
47
|
interface ConsentFormEditorProps {
|
|
27
48
|
baseUrl: string;
|
|
28
|
-
api:
|
|
49
|
+
api: AdminApi;
|
|
29
50
|
id?: string;
|
|
30
51
|
supportedLocales?: string[];
|
|
31
52
|
hasAiSupport?: boolean;
|
|
32
|
-
onSave?: (form:
|
|
53
|
+
onSave?: (form: ConsentFormDocument | undefined) => void;
|
|
33
54
|
onCancel?: () => void;
|
|
34
55
|
}
|
|
35
56
|
|
|
@@ -116,7 +137,7 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
|
|
|
116
137
|
const enhancedApi = useMemo(
|
|
117
138
|
() =>
|
|
118
139
|
api.injectEndpoints({
|
|
119
|
-
endpoints: (build:
|
|
140
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
120
141
|
generateConsentContent: build.mutation({
|
|
121
142
|
query: (body: {type: string; description: string; locale: string}) => ({
|
|
122
143
|
body,
|
|
@@ -143,17 +164,12 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
|
|
|
143
164
|
[api, consentApiPath]
|
|
144
165
|
);
|
|
145
166
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const [
|
|
151
|
-
|
|
152
|
-
).useGenerateConsentContentMutation();
|
|
153
|
-
|
|
154
|
-
const [translateContent, {isLoading: isTranslating}] = (
|
|
155
|
-
enhancedApi as any
|
|
156
|
-
).useTranslateConsentContentMutation();
|
|
167
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
168
|
+
const enhanced = enhancedApi as any;
|
|
169
|
+
const [publishConsentForm, {isLoading: isPublishing}] = enhanced.usePublishConsentFormMutation();
|
|
170
|
+
const [generateContent, {isLoading: isGenerating}] = enhanced.useGenerateConsentContentMutation();
|
|
171
|
+
const [translateContent, {isLoading: isTranslating}] =
|
|
172
|
+
enhanced.useTranslateConsentContentMutation();
|
|
157
173
|
|
|
158
174
|
const {data: formData, isLoading: isFormLoading} = useReadQuery(id ?? "", {
|
|
159
175
|
skip: !isEditMode || !id,
|
|
@@ -224,7 +240,7 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
|
|
|
224
240
|
}, []);
|
|
225
241
|
|
|
226
242
|
const handleCheckboxChange = useCallback(
|
|
227
|
-
(index: number, field: keyof CheckboxConfig, value:
|
|
243
|
+
(index: number, field: keyof CheckboxConfig, value: string | boolean) => {
|
|
228
244
|
setCheckboxes((prev) => {
|
|
229
245
|
const updated = [...prev];
|
|
230
246
|
updated[index] = {...updated[index], [field]: value};
|
|
@@ -285,11 +301,11 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
|
|
|
285
301
|
const payload = buildPayload();
|
|
286
302
|
|
|
287
303
|
try {
|
|
288
|
-
let result:
|
|
304
|
+
let result: ConsentFormDocument | undefined;
|
|
289
305
|
if (isEditMode && id) {
|
|
290
|
-
result = await updateForm({body: payload, id}).unwrap();
|
|
306
|
+
result = (await updateForm({body: payload, id}).unwrap()) as ConsentFormDocument;
|
|
291
307
|
} else {
|
|
292
|
-
result = await createForm(payload).unwrap();
|
|
308
|
+
result = (await createForm(payload).unwrap()) as ConsentFormDocument;
|
|
293
309
|
}
|
|
294
310
|
console.info("Consent form saved", {id: result?._id ?? id});
|
|
295
311
|
onSave?.(result);
|
package/src/ConsentFormList.tsx
CHANGED
|
@@ -12,15 +12,27 @@ import {
|
|
|
12
12
|
Text,
|
|
13
13
|
} from "@terreno/ui";
|
|
14
14
|
import React, {useCallback, useMemo, useState} from "react";
|
|
15
|
+
import type {AdminApi} from "./types";
|
|
15
16
|
import {useAdminApi} from "./useAdminApi";
|
|
16
17
|
|
|
17
18
|
interface ConsentFormListProps {
|
|
18
19
|
baseUrl: string;
|
|
19
|
-
api:
|
|
20
|
+
api: AdminApi;
|
|
20
21
|
onCreateNew?: () => void;
|
|
21
22
|
onRowClick?: (id: string) => void;
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/** Row shape returned by the consent forms list endpoint. */
|
|
26
|
+
interface ConsentFormListItem {
|
|
27
|
+
_id: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
type?: string;
|
|
30
|
+
version?: number;
|
|
31
|
+
active?: boolean;
|
|
32
|
+
order?: number;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
const DEFAULT_LIMIT = 20;
|
|
25
37
|
|
|
26
38
|
const ACTIONS_COLUMN_TYPE = "consentFormActions";
|
|
@@ -103,7 +115,7 @@ export const ConsentFormList: React.FC<ConsentFormListProps> = ({
|
|
|
103
115
|
: []),
|
|
104
116
|
];
|
|
105
117
|
|
|
106
|
-
const rows = (listData?.data ?? []).map((item
|
|
118
|
+
const rows = ((listData?.data ?? []) as ConsentFormListItem[]).map((item) => {
|
|
107
119
|
const dataCells = DATA_COLUMN_KEYS.map((key) => {
|
|
108
120
|
const value = item[key];
|
|
109
121
|
if (key === "active") {
|
|
@@ -3,15 +3,16 @@ import {DateTime} from "luxon";
|
|
|
3
3
|
import React, {useCallback, useState} from "react";
|
|
4
4
|
import {Image} from "react-native";
|
|
5
5
|
import {generateConsentPdf} from "./generateConsentPdf";
|
|
6
|
+
import type {AdminApi} from "./types";
|
|
6
7
|
import {useAdminApi} from "./useAdminApi";
|
|
7
8
|
|
|
8
9
|
interface ConsentResponseViewerProps {
|
|
9
10
|
baseUrl: string;
|
|
10
|
-
api:
|
|
11
|
+
api: AdminApi;
|
|
11
12
|
id: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const formatDate = (value:
|
|
15
|
+
const formatDate = (value: unknown): string => {
|
|
15
16
|
if (!value) {
|
|
16
17
|
return "";
|
|
17
18
|
}
|
|
@@ -79,7 +79,7 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
|
|
|
79
79
|
data: DocumentListResponse | undefined;
|
|
80
80
|
isLoading: boolean;
|
|
81
81
|
isError: boolean;
|
|
82
|
-
error:
|
|
82
|
+
error: {status?: number; originalStatus?: number} | undefined;
|
|
83
83
|
refetch: () => void;
|
|
84
84
|
};
|
|
85
85
|
const [uploadFile, {isLoading: isUploading}] = useUploadMutation();
|
|
@@ -391,7 +391,7 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
|
|
|
391
391
|
);
|
|
392
392
|
|
|
393
393
|
const tableData = useMemo(() => {
|
|
394
|
-
const rows:
|
|
394
|
+
const rows: DataTableCellData[][] = [];
|
|
395
395
|
|
|
396
396
|
for (const folder of listData?.folders ?? []) {
|
|
397
397
|
const folderName = folder.split("/").filter(Boolean).pop() ?? folder;
|
|
@@ -507,8 +507,8 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
|
|
|
507
507
|
<>
|
|
508
508
|
<input
|
|
509
509
|
accept="*/*"
|
|
510
|
-
onChange={handleFileChange
|
|
511
|
-
ref={fileInputRef
|
|
510
|
+
onChange={handleFileChange}
|
|
511
|
+
ref={fileInputRef}
|
|
512
512
|
style={{display: "none"}}
|
|
513
513
|
type="file"
|
|
514
514
|
/>
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Type alias for an RTK Query API instance with type-erased generic parameters.
|
|
6
|
+
*
|
|
7
|
+
* The admin panel dynamically injects endpoints into the consumer's RTK Query API at
|
|
8
|
+
* runtime via `api.injectEndpoints()`. The consumer's API is built from a generated
|
|
9
|
+
* OpenAPI SDK with thousands of distinct endpoint types — there is no shared base
|
|
10
|
+
* type we can constrain to, so the generic parameters are erased.
|
|
11
|
+
*/
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query's Api generics are erased at the dynamic endpoint injection boundary
|
|
13
|
+
export type AdminApi = Api<any, any, any, any>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generic field/document value used throughout the admin panel.
|
|
17
|
+
*
|
|
18
|
+
* Admin screens operate over arbitrary Mongoose documents whose field types are not
|
|
19
|
+
* known statically — they are discovered at runtime via the `/admin/config` endpoint.
|
|
20
|
+
* Read sites must narrow with `typeof` checks before passing to typed UI components.
|
|
21
|
+
*/
|
|
22
|
+
export type AdminFieldValue = unknown;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* RTK Query's `build` argument from `api.injectEndpoints({ endpoints: (build) => ... })`.
|
|
26
|
+
*
|
|
27
|
+
* The build helper is generic over the full endpoint set; since the admin panel injects
|
|
28
|
+
* endpoints dynamically into a consumer-supplied API, the endpoint shapes are not
|
|
29
|
+
* statically expressible here.
|
|
30
|
+
*/
|
|
31
|
+
// biome-ignore lint/suspicious/noExplicitAny: build helper from RTK Query's dynamic injectEndpoints API
|
|
32
|
+
export type EndpointBuilder = any;
|
|
33
|
+
|
|
4
34
|
export interface AdminFieldConfig {
|
|
5
35
|
type: string;
|
|
6
36
|
required: boolean;
|
|
7
37
|
description?: string;
|
|
8
38
|
enum?: string[];
|
|
9
|
-
default?:
|
|
39
|
+
default?: AdminFieldValue;
|
|
10
40
|
ref?: string;
|
|
11
41
|
searchable?: boolean;
|
|
12
42
|
widget?: string;
|
|
@@ -78,7 +108,7 @@ export interface BackgroundTask {
|
|
|
78
108
|
|
|
79
109
|
export interface AdminScreenProps {
|
|
80
110
|
baseUrl: string;
|
|
81
|
-
api:
|
|
111
|
+
api: AdminApi;
|
|
82
112
|
}
|
|
83
113
|
|
|
84
114
|
/**
|
|
@@ -86,7 +116,7 @@ export interface AdminScreenProps {
|
|
|
86
116
|
* custom renderer is a drop-in replacement.
|
|
87
117
|
*/
|
|
88
118
|
export interface RefFieldRendererProps {
|
|
89
|
-
api:
|
|
119
|
+
api: AdminApi;
|
|
90
120
|
baseUrl: string;
|
|
91
121
|
routePath: string;
|
|
92
122
|
refModelName: string;
|
|
@@ -125,7 +155,7 @@ export interface DocumentListResponse {
|
|
|
125
155
|
}
|
|
126
156
|
|
|
127
157
|
export interface DocumentStorageBrowserProps {
|
|
128
|
-
api:
|
|
158
|
+
api: AdminApi;
|
|
129
159
|
basePath: string;
|
|
130
160
|
title?: string;
|
|
131
161
|
allowDelete?: boolean;
|
package/src/useAdminApi.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
2
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
3
|
+
|
|
4
|
+
// biome-ignore lint/suspicious/noExplicitAny: payload bodies vary across admin models — handled at runtime
|
|
5
|
+
type AdminPayload = any;
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query tag callback args have a complex generic shape we erase here
|
|
7
|
+
type TagArg = any;
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Hook that generates RTK Query CRUD hooks for a specific admin model.
|
|
@@ -44,7 +49,7 @@ import {useMemo} from "react";
|
|
|
44
49
|
* @see useAdminConfig for fetching model configurations
|
|
45
50
|
* @see AdminModelTable for usage in the table view
|
|
46
51
|
*/
|
|
47
|
-
export const useAdminApi = (api:
|
|
52
|
+
export const useAdminApi = (api: AdminApi, routePath: string, modelName: string) => {
|
|
48
53
|
const enhancedApi = useMemo(() => {
|
|
49
54
|
const listKey = `adminList_${modelName}`;
|
|
50
55
|
const readKey = `adminRead_${modelName}`;
|
|
@@ -54,17 +59,17 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
54
59
|
|
|
55
60
|
const tagType = `admin_${modelName}`;
|
|
56
61
|
return api.enhanceEndpoints({addTagTypes: [tagType]}).injectEndpoints({
|
|
57
|
-
endpoints: (build:
|
|
62
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
58
63
|
[listKey]: build.query({
|
|
59
64
|
providesTags: [`admin_${modelName}`],
|
|
60
|
-
query: (params:
|
|
65
|
+
query: (params: Record<string, unknown> | undefined) => ({
|
|
61
66
|
method: "GET",
|
|
62
67
|
params: params ?? {},
|
|
63
68
|
url: routePath,
|
|
64
69
|
}),
|
|
65
70
|
}),
|
|
66
71
|
[readKey]: build.query({
|
|
67
|
-
providesTags: (_result:
|
|
72
|
+
providesTags: (_result: TagArg, _error: TagArg, id: string) => [
|
|
68
73
|
{id, type: `admin_${modelName}`},
|
|
69
74
|
],
|
|
70
75
|
query: (id: string) => ({
|
|
@@ -74,18 +79,18 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
74
79
|
}),
|
|
75
80
|
[createKey]: build.mutation({
|
|
76
81
|
invalidatesTags: [`admin_${modelName}`],
|
|
77
|
-
query: (body:
|
|
82
|
+
query: (body: AdminPayload) => ({
|
|
78
83
|
body,
|
|
79
84
|
method: "POST",
|
|
80
85
|
url: routePath,
|
|
81
86
|
}),
|
|
82
87
|
}),
|
|
83
88
|
[updateKey]: build.mutation({
|
|
84
|
-
invalidatesTags: (_result:
|
|
89
|
+
invalidatesTags: (_result: TagArg, _error: TagArg, {id}: {id: string}) => [
|
|
85
90
|
{id, type: `admin_${modelName}`},
|
|
86
91
|
`admin_${modelName}`,
|
|
87
92
|
],
|
|
88
|
-
query: ({id, body}: {id: string; body:
|
|
93
|
+
query: ({id, body}: {id: string; body: AdminPayload}) => ({
|
|
89
94
|
body,
|
|
90
95
|
method: "PATCH",
|
|
91
96
|
url: `${routePath}/${id}`,
|
|
@@ -111,11 +116,15 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
111
116
|
const updateKey = `adminUpdate_${modelName}`;
|
|
112
117
|
const deleteKey = `adminDelete_${modelName}`;
|
|
113
118
|
|
|
119
|
+
// RTK Query generates these hook names dynamically from the endpoint keys; the resulting
|
|
120
|
+
// shape is not statically expressible through @reduxjs/toolkit's public types.
|
|
121
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
122
|
+
const enhanced = enhancedApi as any;
|
|
114
123
|
return {
|
|
115
|
-
useCreateMutation:
|
|
116
|
-
useDeleteMutation:
|
|
117
|
-
useListQuery:
|
|
118
|
-
useReadQuery:
|
|
119
|
-
useUpdateMutation:
|
|
124
|
+
useCreateMutation: enhanced[`use${capitalize(createKey)}Mutation`],
|
|
125
|
+
useDeleteMutation: enhanced[`use${capitalize(deleteKey)}Mutation`],
|
|
126
|
+
useListQuery: enhanced[`use${capitalize(listKey)}Query`],
|
|
127
|
+
useReadQuery: enhanced[`use${capitalize(readKey)}Query`],
|
|
128
|
+
useUpdateMutation: enhanced[`use${capitalize(updateKey)}Mutation`],
|
|
120
129
|
};
|
|
121
130
|
};
|
package/src/useAdminConfig.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
3
|
-
import type {AdminConfigResponse} from "./types";
|
|
2
|
+
import type {AdminApi, AdminConfigResponse, EndpointBuilder} from "./types";
|
|
4
3
|
|
|
5
4
|
const ENDPOINT_NAME = "adminConfig";
|
|
6
5
|
|
|
@@ -33,10 +32,10 @@ const ENDPOINT_NAME = "adminConfig";
|
|
|
33
32
|
* @see AdminConfigResponse for the returned configuration structure
|
|
34
33
|
* @see AdminModelList for usage in the model list screen
|
|
35
34
|
*/
|
|
36
|
-
export const useAdminConfig = (api:
|
|
35
|
+
export const useAdminConfig = (api: AdminApi, baseUrl: string) => {
|
|
37
36
|
const enhancedApi = useMemo(() => {
|
|
38
37
|
return api.injectEndpoints({
|
|
39
|
-
endpoints: (build:
|
|
38
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
40
39
|
[ENDPOINT_NAME]: build.query({
|
|
41
40
|
query: () => ({
|
|
42
41
|
method: "GET",
|
|
@@ -48,6 +47,7 @@ export const useAdminConfig = (api: Api<any, any, any, any>, baseUrl: string) =>
|
|
|
48
47
|
});
|
|
49
48
|
}, [api, baseUrl]);
|
|
50
49
|
|
|
50
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
51
51
|
const useConfigQuery = (enhancedApi as any).useAdminConfigQuery;
|
|
52
52
|
|
|
53
53
|
const {data, isLoading, error} = useConfigQuery();
|