@@ -89,25 +89,6 @@ import { UpgradesPage } from "./upgrades/upgrades-page";
8989
9090export const ACCOUNT_SETTINGS_ICON_NAME : IconName = "settings" ;
9191
92- const BILLING_MENU_KEYS = new Set ( [
93- "subscriptions" ,
94- "licenses" ,
95- "payg" ,
96- "upgrades" ,
97- "purchases" ,
98- "payments" ,
99- "payment-methods" ,
100- "statements" ,
101- ] ) ;
102-
103- function getParentMenuKey ( key ?: string ) : string | undefined {
104- if ( ! key ) return ;
105- if ( BILLING_MENU_KEYS . has ( key ) ) return "billing" ;
106- const dashIndex = key . indexOf ( "-" ) ;
107- if ( dashIndex === - 1 ) return ;
108- return key . slice ( 0 , dashIndex ) ;
109- }
110-
11192// Type for valid menu keys
11293type MenuKey =
11394 | "settings"
@@ -365,7 +346,7 @@ export const AccountPage: React.FC = () => {
365346 ) ,
366347 children : active_page === "payg" && < PayAsYouGoPage /> ,
367348 } ,
368- ...( is_commercial && kucalc === KUCALC_COCALC_COM
349+ ...( kucalc === KUCALC_COCALC_COM
369350 ? [
370351 {
371352 key : "upgrades" ,
@@ -482,11 +463,12 @@ export const AccountPage: React.FC = () => {
482463 }
483464
484465 const tabs = getTabs ( ) ;
466+ const parentByChildKey = new Map < string , string > ( ) ;
485467
486468 useEffect ( ( ) => {
487- const parentKey = getParentMenuKey (
488- active_sub_tab ? active_sub_tab : active_page ,
489- ) ;
469+ const parentKey =
470+ parentByChildKey . get ( active_sub_tab ?? "" ) ??
471+ parentByChildKey . get ( active_page ?? "" ) ;
490472 setOpenKeys ( ( prevOpenKeys ) =>
491473 parentKey == null
492474 ? [ ]
@@ -497,10 +479,13 @@ export const AccountPage: React.FC = () => {
497479 } , [ active_page , active_sub_tab ] ) ;
498480
499481 useEffect ( ( ) => {
500- if ( active_page !== "preferences" && active_sub_tab ) {
482+ if (
483+ active_sub_tab &&
484+ parentByChildKey . get ( active_sub_tab ) !== active_page
485+ ) {
501486 redux . getActions ( "account" ) . setState ( { active_sub_tab : undefined } ) ;
502487 }
503- } , [ active_page , active_sub_tab ] ) ;
488+ } , [ active_page , active_sub_tab , parentByChildKey ] ) ;
504489
505490 function handleOpenChange ( keys : string [ ] ) {
506491 setOpenKeys ( ( prevOpenKeys ) => {
@@ -516,11 +501,11 @@ export const AccountPage: React.FC = () => {
516501 if ( tab . type == "divider" ) {
517502 continue ;
518503 }
519- if ( tab . key === "preferences" && Array . isArray ( tab . children ) ) {
520- // Handle sub-tabs for preferences
504+ if ( Array . isArray ( tab . children ) ) {
505+ // Handle nested submenus generically ( preferences, billing, etc.)
521506 const subTabs = tab . children ;
522507 tab . children = subTabs . map ( ( subTab ) => {
523- // Extract just the icon (first child) from the span when hidden
508+ // When collapsed, show only the icon; otherwise show full label.
524509 const label = hidden ? (
525510 < span style = { { paddingLeft : "5px" } } >
526511 { subTab . label . props . children [ 0 ] }
@@ -533,30 +518,12 @@ export const AccountPage: React.FC = () => {
533518 label,
534519 } ;
535520 } ) ;
536- // Store sub-tab children and full labels
537521 for ( const subTab of subTabs ) {
522+ // Track child -> parent mapping for openKeys/title lookup.
523+ parentByChildKey . set ( subTab . key , tab . key ) ;
538524 children [ subTab . key ] = subTab . children ;
539525 titles [ subTab . key ] = subTab . label ; // Always store original full label
540526 }
541- } else if ( tab . key === "billing" && Array . isArray ( tab . children ) ) {
542- const subTabs = tab . children ;
543- tab . children = subTabs . map ( ( subTab ) => {
544- const label = hidden ? (
545- < span style = { { paddingLeft : "5px" } } >
546- { subTab . label . props . children [ 0 ] }
547- </ span >
548- ) : (
549- subTab . label
550- ) ;
551- return {
552- key : subTab . key ,
553- label,
554- } ;
555- } ) ;
556- for ( const subTab of subTabs ) {
557- children [ subTab . key ] = subTab . children ;
558- titles [ subTab . key ] = subTab . label ;
559- }
560527 } else if ( tab . key === "settings" || tab . key === "profile" ) {
561528 // Handle settings and profile as top-level pages
562529 // Store original full label for renderTitle()
@@ -589,12 +556,11 @@ export const AccountPage: React.FC = () => {
589556 }
590557 }
591558
559+ const activeChildKey = active_sub_tab ?? active_page ;
592560 function renderTitle ( ) {
593561 return (
594562 < Title level = { 3 } >
595- { active_page === "preferences" && active_sub_tab
596- ? titles [ active_sub_tab ]
597- : titles [ active_page ] }
563+ { titles [ activeChildKey ] }
598564 </ Title >
599565 ) ;
600566 }
@@ -702,9 +668,7 @@ export const AccountPage: React.FC = () => {
702668 < div style = { { flex : 1 } } />
703669 { renderExtraContent ( ) }
704670 </ Flex >
705- { active_page === "preferences" && active_sub_tab
706- ? children [ active_sub_tab ]
707- : children [ active_page ] }
671+ { children [ activeChildKey ] ?? children [ active_page ] }
708672 < Footer />
709673 </ div >
710674 </ div >
0 commit comments