#!/usr/bin/env python3 """Spec 037 V4 — painel DNS read-only no passo DNS do wizard (App.jsx). Idempotente.""" from pathlib import Path APP = Path("/opt/ligbox-wizard/frontend/src/App.jsx") text = APP.read_text(encoding="utf-8") if "dnsViewerData" in text: print("App.jsx: dns viewer V4 already patched") raise SystemExit(0) text = text.replace( " const [showAdvancedDns, setShowAdvancedDns] = useState(false)", " const [showAdvancedDns, setShowAdvancedDns] = useState(false)\n" " const [dnsViewerData, setDnsViewerData] = useState(null)\n" " const [dnsViewerLoading, setDnsViewerLoading] = useState(false)", ) LOAD_FN = """ async function refreshDnsViewer(dom) { const d = (dom || domain || '').trim().toLowerCase() if (!d || d.length < 3) return setDnsViewerLoading(true) try { const data = await api(`/onboarding/dns/viewer/${d}`) setDnsViewerData(data) } catch { setDnsViewerData(null) } finally { setDnsViewerLoading(false) } } """ if "refreshDnsViewer" not in text: text = text.replace(" async function choosePortalDns() {", LOAD_FN + " async function choosePortalDns() {") # Refresh when instructions load text = text.replace( " setDnsResolve(data.resolve || null)", " setDnsResolve(data.resolve || null)\n refreshDnsViewer(dom)", ) text = text.replace( " setDnsChoice('portal')\n setError(null)\n startBusy('dns_zone')", " setDnsChoice('portal')\n setError(null)\n refreshDnsViewer(domain)\n startBusy('dns_zone')", ) text = text.replace( " setDnsChoice('external')\n markActionDone('chooseExternalDns')", " setDnsChoice('external')\n refreshDnsViewer(domain)\n markActionDone('chooseExternalDns')", ) PANEL = """ {(dnsViewerData || dnsViewerLoading) && step === 1 && ( )} """ if "dns-viewer-wizard-panel" not in text: text = text.replace( " {dnsChoice === 'byo' && showAdvancedDns && (", PANEL + " {dnsChoice === 'byo' && showAdvancedDns && (", ) APP.write_text(text, encoding="utf-8") print("App.jsx: DNS viewer V4 panel OK")