From ed7a178ac65fb93647d8a7d3f2b222189e0e9435 Mon Sep 17 00:00:00 2001 From: Jakob Wennberg <149234542+jakobwennberg@users.noreply.github.com> Date: Tue, 7 Jul 2026 14:17:35 +0200 Subject: [PATCH] fix(import): scope bank account picker to the active company (#922) The chart_of_accounts query in BankFileConfirmStep had no company_id filter, so RLS returned bank accounts from every company the user is a member of, duplicating 1930/1940/etc. in the dropdown and making the selected value ambiguous across companies. Co-authored-by: Claude Opus 4.7 --- components/import/BankFileConfirmStep.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/import/BankFileConfirmStep.tsx b/components/import/BankFileConfirmStep.tsx index 88fed2ae..6962107a 100644 --- a/components/import/BankFileConfirmStep.tsx +++ b/components/import/BankFileConfirmStep.tsx @@ -17,6 +17,7 @@ import { } from 'lucide-react' import { formatCurrency } from '@/lib/utils' import { createClient } from '@/lib/supabase/client' +import { useCompany } from '@/contexts/CompanyContext' import type { BankFileParseResult } from '@/lib/import/bank-file/types' interface BankAccount { @@ -43,13 +44,16 @@ export default function BankFileConfirmStep({ const [bankAccounts, setBankAccounts] = useState([]) const [selectedAccount, setSelectedAccount] = useState('1930') + const { company } = useCompany() useEffect(() => { - async function fetchBankAccounts() { + if (!company?.id) return + async function fetchBankAccounts(companyId: string) { const supabase = createClient() const { data } = await supabase .from('chart_of_accounts') .select('account_number, account_name') + .eq('company_id', companyId) .eq('is_active', true) .gte('account_number', '1900') .lte('account_number', '1999') @@ -62,8 +66,8 @@ export default function BankFileConfirmStep({ if (!has1930) setSelectedAccount(data[0].account_number) } } - fetchBankAccounts() - }, []) + fetchBankAccounts(company.id) + }, [company?.id]) if (isLoading) { return (