diff --git a/admin-compliance/app/sdk/founding-wizard/_components/StepBasics.tsx b/admin-compliance/app/sdk/founding-wizard/_components/StepBasics.tsx index abb07705..c8038a71 100644 --- a/admin-compliance/app/sdk/founding-wizard/_components/StepBasics.tsx +++ b/admin-compliance/app/sdk/founding-wizard/_components/StepBasics.tsx @@ -1,5 +1,6 @@ 'use client' +import { useState } from 'react' import type { FoundingWizardState } from '@/lib/sdk/founding/types' interface Props { @@ -9,8 +10,73 @@ interface Props { export function StepBasics({ state, update }: Props) { const b = state.basics + const [prefillStatus, setPrefillStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle') + + async function prefillFromCompanyProfile() { + setPrefillStatus('loading') + try { + const res = await fetch('/api/sdk/v1/company-profile', { cache: 'no-store' }) + if (!res.ok) throw new Error(`HTTP ${res.status}`) + const payload = await res.json() + const p = payload?.profile ?? payload + if (!p || typeof p !== 'object') throw new Error('leeres Profil') + const industries = Array.isArray(p.industry) ? p.industry.filter(Boolean) : [] + const industry = industries.length > 0 + ? industries.join(', ') + : (p.industryOther || b.industry) + const address = [p.headquartersStreet, [p.headquartersZip, p.headquartersCity].filter(Boolean).join(' ')] + .filter(Boolean).join(', ') || b.company_address + const seat = p.headquartersCity || b.company_seat + // Purpose ableiten aus offerings/businessModel — Fallback wenn nichts da + const purposeBits: string[] = [] + if (p.businessModel) purposeBits.push(`Geschäftsmodell: ${p.businessModel}`) + if (Array.isArray(p.offerings) && p.offerings.length > 0) + purposeBits.push(`Leistungen: ${p.offerings.join(', ')}`) + const purpose = purposeBits.length > 0 + ? purposeBits.join('; ') + : b.company_purpose_description + update('basics', { + ...b, + company_name: p.companyName || b.company_name, + legal_form: (p.legalForm === 'UG' ? 'UG' : (p.legalForm === 'GmbH' ? 'GmbH' : b.legal_form)), + company_seat: seat, + company_address: address, + industry, + company_purpose_description: b.company_purpose_description.trim() === '' ? purpose : b.company_purpose_description, + }) + setPrefillStatus('success') + } catch (err) { + console.error('[founding-wizard] prefill failed', err) + setPrefillStatus('error') + } + } + return (
+ Stammdaten der Gesellschaft. Pflicht für Satzung, HRB-Anmeldung und SHA. +
+ ++ Zuständiges Amtsgericht für HRB-Eintragung +
+