From 352aba4c88a18fd3a101dc492fc390a94a1cdb64 Mon Sep 17 00:00:00 2001 From: seaznCode Date: Mon, 19 Jan 2026 23:16:13 +0100 Subject: [PATCH] feat: add warning handling for contract preview in UserDetailModal --- src/app/components/UserDetailModal.tsx | 21 +++++++++++++-------- src/app/utils/api.ts | 9 +++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/app/components/UserDetailModal.tsx b/src/app/components/UserDetailModal.tsx index 9843453..8270c62 100644 --- a/src/app/components/UserDetailModal.tsx +++ b/src/app/components/UserDetailModal.tsx @@ -49,8 +49,8 @@ export default function UserDetailModal({ isOpen, onClose, userId, onUserUpdated // Contract preview state (lazy-loaded, per contract type) const [activePreviewTab, setActivePreviewTab] = useState<'contract' | 'gdpr'>('contract') const [previewState, setPreviewState] = useState({ - contract: { loading: false, html: null as string | null, error: null as string | null }, - gdpr: { loading: false, html: null as string | null, error: null as string | null }, + contract: { loading: false, html: null as string | null, error: null as string | null, warning: null as string | null }, + gdpr: { loading: false, html: null as string | null, error: null as string | null, warning: null as string | null }, }) useEffect(() => { @@ -63,8 +63,8 @@ export default function UserDetailModal({ isOpen, onClose, userId, onUserUpdated if (!isOpen) return setActivePreviewTab('contract') setPreviewState({ - contract: { loading: false, html: null, error: null }, - gdpr: { loading: false, html: null, error: null } + contract: { loading: false, html: null, error: null, warning: null }, + gdpr: { loading: false, html: null, error: null, warning: null } }) }, [isOpen, userId]) @@ -153,19 +153,19 @@ export default function UserDetailModal({ isOpen, onClose, userId, onUserUpdated if (!userId || !token || !userDetails) return setPreviewState((prev) => ({ ...prev, - [contractType]: { ...prev[contractType], loading: true, error: null } + [contractType]: { ...prev[contractType], loading: true, error: null, warning: null } })) try { - const html = await AdminAPI.getContractPreviewHtml(token, String(userId), userDetails.user.user_type, contractType) + const result = await AdminAPI.getContractPreviewHtml(token, String(userId), userDetails.user.user_type, contractType) setPreviewState((prev) => ({ ...prev, - [contractType]: { loading: false, html, error: null } + [contractType]: { loading: false, html: result.html, error: null, warning: result.warning || null } })) } catch (e: any) { console.error('UserDetailModal.loadContractPreview error:', e) setPreviewState((prev) => ({ ...prev, - [contractType]: { loading: false, html: null, error: e?.message || 'Failed to load contract preview' } + [contractType]: { loading: false, html: null, error: e?.message || 'Failed to load contract preview', warning: e?.warning || null } })) } } @@ -459,6 +459,11 @@ export default function UserDetailModal({ isOpen, onClose, userId, onUserUpdated
+ {previewState[activePreviewTab].warning && ( +
+ {previewState[activePreviewTab].warning} +
+ )} {previewState[activePreviewTab].error && (
{previewState[activePreviewTab].error} diff --git a/src/app/utils/api.ts b/src/app/utils/api.ts index 1754142..48d4902 100644 --- a/src/app/utils/api.ts +++ b/src/app/utils/api.ts @@ -449,12 +449,17 @@ export class AdminAPI { const qsStr = qs.toString() if (qsStr) endpoint += `?${qsStr}` const response = await ApiClient.get(endpoint, token) + const warningHeader = response.headers.get('x-contract-preview-warning') if (!response.ok) { const error = await response.json().catch(() => ({ message: 'Failed to fetch contract preview' })) - throw new Error(error.message || 'Failed to fetch contract preview') + const err: any = new Error(error.message || 'Failed to fetch contract preview') + if (warningHeader) err.warning = warningHeader + if (error?.warning) err.warning = error.warning + throw err } // Return HTML string - return response.text() + const html = await response.text() + return { html, warning: warningHeader } } }