diff --git a/proto/src/app/(payload)/admin/importMap.js b/proto/src/app/(payload)/admin/importMap.js index e630098..ce16fee 100644 --- a/proto/src/app/(payload)/admin/importMap.js +++ b/proto/src/app/(payload)/admin/importMap.js @@ -1,8 +1,10 @@ +import { LegalValidationPrompt as LegalValidationPrompt_a8cca93565d7d00e7e22c4fe1497b43d } from '../../../../src/components/admin/LegalValidationPrompt' import { QuickSearch as QuickSearch_899db48c9ce30e524aae8643dea53f6d } from '../../../../src/components/admin/QuickSearch' import { CollectionCards as CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1 } from '@payloadcms/next/rsc' /** @type import('payload').ImportMap */ export const importMap = { + "./src/components/admin/LegalValidationPrompt#LegalValidationPrompt": LegalValidationPrompt_a8cca93565d7d00e7e22c4fe1497b43d, "./src/components/admin/QuickSearch#QuickSearch": QuickSearch_899db48c9ce30e524aae8643dea53f6d, "@payloadcms/next/rsc#CollectionCards": CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1 } diff --git a/proto/src/collections/LegalPages.ts b/proto/src/collections/LegalPages.ts index 9b00949..cfc81b1 100644 --- a/proto/src/collections/LegalPages.ts +++ b/proto/src/collections/LegalPages.ts @@ -76,5 +76,14 @@ export const LegalPages: CollectionConfig = { { name: 'reportRef', label: 'Validációs riport (hivatkozás)', type: 'text' }, ], }, + { + // MITHOME-113 (D8): copyable review prompt built from the saved hu + en texts. + name: 'validationPrompt', + type: 'ui', + admin: { + position: 'sidebar', + components: { Field: './src/components/admin/LegalValidationPrompt#LegalValidationPrompt' }, + }, + }, ], } diff --git a/proto/src/components/admin/LegalValidationPrompt.tsx b/proto/src/components/admin/LegalValidationPrompt.tsx new file mode 100644 index 0000000..00f96f1 --- /dev/null +++ b/proto/src/components/admin/LegalValidationPrompt.tsx @@ -0,0 +1,105 @@ +'use client' + +import { useEffect, useState } from 'react' +import { buildLegalValidationPrompt, type LegalText } from '@/lib/legal-validation-prompt' + +/** + * MITHOME-113 (design D8) — "Validation prompt" panel in the legal page + * editor sidebar: a ready-to-copy prompt for reviewing the English + * translation with a high-capability model. The prompt comes from the same + * template the project's own validation uses (src/lib/legal-validation-prompt.ts). + * + * WHY REST reads instead of the form state: the edit form holds one locale + * at a time; the prompt needs both. `draft=true` reads the latest saved + * version, `fallback-locale=none` keeps missing English empty instead of + * silently showing Hungarian as "English". + * WHY the id comes from the URL: avoids adding @payloadcms/ui as a direct + * dependency just for useDocumentInfo (same approach as QuickSearch). + */ + +type State = + | { kind: 'loading' } + | { kind: 'unsaved' } + | { kind: 'error'; message: string } + | { kind: 'empty' } + | { kind: 'ready'; prompt: string } + +function docIdFromPath(pathname: string): string | undefined { + const id = pathname.match(/\/collections\/legal-pages\/([^/?#]+)/)?.[1] + return id && id !== 'create' ? id : undefined +} + +async function readLocale(id: string, locale: 'hu' | 'en'): Promise { + const res = await fetch(`/api/legal-pages/${id}?locale=${locale}&fallback-locale=none&draft=true&depth=0`, { + credentials: 'include', + }) + if (!res.ok) throw new Error(`HTTP ${res.status}`) + return res.json() +} + +async function fetchPromptState(): Promise { + const id = docIdFromPath(window.location.pathname) + if (!id) return { kind: 'unsaved' } + try { + const [hu, en] = await Promise.all([readLocale(id, 'hu'), readLocale(id, 'en')]) + const prompt = buildLegalValidationPrompt(hu, en) + return prompt ? { kind: 'ready', prompt } : { kind: 'empty' } + } catch (error) { + return { kind: 'error', message: error instanceof Error ? error.message : String(error) } + } +} + +export function LegalValidationPrompt() { + const [state, setState] = useState({ kind: 'loading' }) + const [copied, setCopied] = useState(false) + + useEffect(() => { + let active = true + void fetchPromptState().then((next) => active && setState(next)) + return () => { + active = false + } + }, []) + + const reload = () => { + setState({ kind: 'loading' }) + void fetchPromptState().then(setState) + } + + const copy = async (prompt: string) => { + await navigator.clipboard.writeText(prompt) + setCopied(true) + setTimeout(() => setCopied(false), 2000) + } + + return ( +
+ +

+ Másold be egy magas szintű modellbe (legalább kettőbe, egymástól függetlenül), majd rögzítsd az eredményt a + „Jogi validáció” mezőkben. A prompt a legutóbb mentett változatból készül. +

+ {state.kind === 'loading' &&

Betöltés…

} + {state.kind === 'unsaved' &&

Előbb mentsd el a dokumentumot.

} + {state.kind === 'empty' &&

Még nincs angol szöveg — nincs mit validálni.

} + {state.kind === 'error' &&

A prompt nem tölthető be ({state.message}).

} + {state.kind === 'ready' && ( + <> +