diff --git a/components/dashboard/WelcomeOnboarding.tsx b/components/dashboard/WelcomeOnboarding.tsx index 3a93e3ec..7cb73849 100644 --- a/components/dashboard/WelcomeOnboarding.tsx +++ b/components/dashboard/WelcomeOnboarding.tsx @@ -1,12 +1,11 @@ 'use client' -import { useState, useEffect } from 'react' +import { useState } from 'react' import { useRouter } from 'next/navigation' -import { createClient } from '@/lib/supabase/client' import { createCompanyFromOnboarding } from '@/lib/company/actions' import { computeFiscalPeriod } from '@/lib/company/compute-fiscal-period' import { useToast } from '@/components/ui/use-toast' -import { Loader2, Building2 } from 'lucide-react' +import { Building2 } from 'lucide-react' import { cn } from '@/lib/utils' import { ENABLED_EXTENSION_IDS } from '@/lib/extensions/_generated/enabled-extensions' import type { CompanyLookupResult } from '@/lib/company-lookup/types' @@ -61,10 +60,8 @@ export default function WelcomeOnboarding({ }: WelcomeOnboardingProps) { const router = useRouter() const { toast } = useToast() - const supabase = createClient() const [started, setStarted] = useState(skipWelcome ?? false) - const [isLoading, setIsLoading] = useState(true) const [isSaving, setIsSaving] = useState(false) const [currentStep, setCurrentStep] = useState(1) const [settings, setSettings] = useState>( @@ -78,46 +75,6 @@ export default function WelcomeOnboarding({ const hour = new Date().getHours() const greeting = hour < 5 ? 'God natt' : hour < 10 ? 'Godmorgon' : hour < 14 ? 'Hej' : hour < 18 ? 'God eftermiddag' : 'God kväll' - // Pre-fill the user's folkbokföringsadress from BankID/SPAR enrichment when - // available. The row is persisted (not consumed here) so /select-company and - // repeat /onboarding visits still see it; it's deleted only once a company - // is successfully created (see createCompanyFromOnboarding). - useEffect(() => { - async function loadSparAddress() { - const { data: { user } } = await supabase.auth.getUser() - if (!user) { - router.push('/login') - return - } - - try { - const { data: enrichmentRow } = await supabase - .from('extension_data') - .select('value') - .eq('user_id', user.id) - .eq('extension_id', 'tic') - .eq('key', 'bankid_enrichment') - .maybeSingle() - - const spar = (enrichmentRow?.value as { spar?: Record } | null)?.spar - if (spar) { - setSettings((prev) => ({ - ...prev, - address_line1: spar.Folkbokforingsadress_SvenskAdress_Utdelningsadress1 || prev.address_line1, - postal_code: spar.Folkbokforingsadress_SvenskAdress_PostNr || prev.postal_code, - city: spar.Folkbokforingsadress_SvenskAdress_Postort || prev.city, - })) - } - } catch (err) { - console.warn(LOG, 'enrichment loading failed (non-blocking)', err) - } - - setIsLoading(false) - } - - loadSparAddress() - }, [supabase, router]) - const handleNext = async (stepData: Partial) => { // Reset org_number/company_name only on a genuine change (user going back // and picking a different entity type). First-time selection must not @@ -226,14 +183,6 @@ export default function WelcomeOnboarding({ } } - if (isLoading) { - return ( -
- -
- ) - } - const stepInfo = STEP_INFO[currentStep - 1] // Welcome screen — show before user clicks "Lägg till ditt första företag" diff --git a/lib/company/actions.ts b/lib/company/actions.ts index 144249cb..d7de4a91 100644 --- a/lib/company/actions.ts +++ b/lib/company/actions.ts @@ -232,11 +232,11 @@ export async function createCompanyFromOnboarding(params: { * fetched from `/api/extensions/ext/tic/lookup`, plus the `EnrichmentCompanyRole` * minimums (org number, legal name, legal entity type). This action derives * sensible defaults (accrual, quarterly moms for VAT-registered, Jan-Dec - * fiscal year), reads SPAR address from `extension_data` as a fallback, and - * then delegates to `createCompanyFromOnboarding` so the provisioning path is - * identical to the manual wizard. On success it clears the enrichment row - * consumed by this path — the manual wizard leaves it intact so a returning - * BankID user can still reach `/select-company` and pick another directorship. + * fiscal year) and delegates to `createCompanyFromOnboarding` so the + * provisioning path is identical to the manual wizard. On success it clears + * the enrichment row consumed by this path — the manual wizard leaves it + * intact so a returning BankID user can still reach `/select-company` and + * pick another directorship. * * Requires `lookup` to be non-null: if TIC `/lookup` is unreachable, the client * must route to the manual wizard instead. Silently defaulting `vat_registered` @@ -277,23 +277,20 @@ export async function createCompanyFromTicRole(params: { return { error: 'company_ceased' } } - // SPAR address fallback if the TIC lookup didn't include one. + // Look up the enrichment row so we can delete it after successful + // provisioning (one-time use). We only need `id` here; the picker has + // already used the `companyRoles` field server-side to render the cards. const { data: enrichmentRow } = await supabase .from('extension_data') - .select('id, value') + .select('id') .eq('user_id', user.id) .eq('extension_id', 'tic') .eq('key', 'bankid_enrichment') .maybeSingle() - const spar = (enrichmentRow?.value as { spar?: Record } | null)?.spar - const sparStreet = spar?.Folkbokforingsadress_SvenskAdress_Utdelningsadress1 - const sparPostal = spar?.Folkbokforingsadress_SvenskAdress_PostNr - const sparCity = spar?.Folkbokforingsadress_SvenskAdress_Postort - - const addressStreet = params.lookup.address?.street ?? sparStreet ?? null - const addressPostal = params.lookup.address?.postalCode ?? sparPostal ?? null - const addressCity = params.lookup.address?.city ?? sparCity ?? null + const addressStreet = params.lookup.address?.street ?? null + const addressPostal = params.lookup.address?.postalCode ?? null + const addressCity = params.lookup.address?.city ?? null const fTax = params.lookup.registration.fTax const vatRegistered = params.lookup.registration.vat