diff --git a/components/settings/OrganizationSettings.tsx b/components/settings/OrganizationSettings.tsx index aada2fe..e441e68 100644 --- a/components/settings/OrganizationSettings.tsx +++ b/components/settings/OrganizationSettings.tsx @@ -41,11 +41,20 @@ export default function OrganizationSettings() { const { user } = useAuth() const router = useRouter() const searchParams = useSearchParams() + // Initialize from URL, default to 'general' const [activeTab, setActiveTab] = useState<'general' | 'members' | 'billing' | 'audit'>(() => { const tab = searchParams.get('tab') - return tab === 'billing' || tab === 'members' || tab === 'audit' ? tab : 'general' + return (tab === 'billing' || tab === 'members' || tab === 'audit') ? tab : 'general' }) + // Sync URL with state without triggering navigation/reload + const handleTabChange = (tab: 'general' | 'members' | 'billing' | 'audit') => { + setActiveTab(tab) + const url = new URL(window.location.href) + url.searchParams.set('tab', tab) + window.history.replaceState({}, '', url) + } + const [showDeletePrompt, setShowDeletePrompt] = useState(false) const [deleteConfirm, setDeleteConfirm] = useState('') const [isDeleting, setIsDeleting] = useState(false) @@ -169,6 +178,9 @@ export default function OrganizationSettings() { } }, [currentOrgId, loadMembers]) + // Removed useEffect that syncs searchParams to activeTab to prevent flickering + // The initial state is already set from searchParams, and handleTabChange updates the URL manually + /* useEffect(() => { const tab = searchParams.get('tab') const validTab = (tab === 'billing' || tab === 'members' || tab === 'audit') ? tab : 'general' @@ -176,6 +188,7 @@ export default function OrganizationSettings() { setActiveTab(validTab) } }, [searchParams, activeTab]) + */ useEffect(() => { if (activeTab === 'billing' && currentOrgId) { @@ -335,10 +348,7 @@ export default function OrganizationSettings() { // We can find the current user's membership entry which has org name. const currentOrgName = members.find(m => m.user_id === user?.id)?.organization_name || 'Organization' - const handleTabChange = (tab: 'general' | 'members' | 'billing' | 'audit') => { - // setActiveTab(tab) // Let the useEffect handle the state update based on URL - router.push(`?tab=${tab}`) - } + // handleTabChange is defined above return (