// Panel admina: ustawienia serwisu - integracja z rejestrem REGON (GUS BIR1.1). import { useCallback, useEffect, useState } from 'react'; import { apiFetch } from '../auth'; type IconComponent = (props: { name: string }) => JSX.Element | null; type GusCfg = { userKeySet: boolean; sandbox: boolean }; const em = (e: unknown) => (e instanceof Error ? e.message : 'Wystąpił błąd.'); export function AdminSettingsView({ Icon }: { Icon: IconComponent }) { const [error, setError] = useState(null); const [note, setNote] = useState(null); const [gus, setGus] = useState({ userKey: '', sandbox: true }); const [keySet, setKeySet] = useState(false); const load = useCallback(async () => { try { const cfg = await apiFetch('/admin/gus-config'); setKeySet(cfg.userKeySet); setGus({ userKey: '', sandbox: cfg.sandbox }); } catch (e) { setError(em(e)); } }, []); useEffect(() => { load(); }, [load]); const save = async () => { try { const body = JSON.stringify({ userKey: gus.userKey || null, sandbox: gus.sandbox }); const cfg = await apiFetch('/admin/gus-config', { method: 'PUT', body }); setKeySet(cfg.userKeySet); setGus({ userKey: '', sandbox: cfg.sandbox }); setError(null); setNote('Zapisano konfigurację GUS.'); } catch (e) { setError(em(e)); } }; return (
{(error || note) && (error ?

{error}

:

{note}

)}

Rejestr REGON (GUS) - pobieranie danych firmy po NIP

Klucz użytkownika otrzymasz od GUS (usługa BIR1.1). W trybie testowym używamy środowiska testowego GUS i klucza testowego - zwraca ono wyłącznie dane przykładowe.

); }