11import {
22 __experimental_PricingTableContext ,
33 InvoicesContextProvider ,
4+ PlansContextProvider ,
45 SubscriberTypeContext ,
56 useSubscriptions ,
6- withPlans ,
77} from '../../contexts' ;
8- import { Col , descriptors , Heading , Hr , localizationKeys } from '../../customizables' ;
8+ import { Button , Col , descriptors , localizationKeys } from '../../customizables' ;
99import {
1010 Card ,
1111 Header ,
@@ -18,6 +18,7 @@ import {
1818 withCardStateProvider ,
1919} from '../../elements' ;
2020import { useTabState } from '../../hooks/useTabState' ;
21+ import { useRouter } from '../../router' ;
2122import { InvoicesList } from '../Invoices' ;
2223import { __experimental_PaymentSources } from '../PaymentSources/PaymentSources' ;
2324import { __experimental_PricingTable } from '../PricingTable' ;
@@ -29,95 +30,98 @@ const orgTabMap = {
2930 2 : 'payment-methods' ,
3031} as const ;
3132
32- const OrganizationBillingPageInternal = withPlans (
33- withCardStateProvider ( ( ) => {
34- const card = useCardState ( ) ;
35- const { data : subscriptions } = useSubscriptions ( 'org' ) ;
36- const { selectedTab, handleTabChange } = useTabState ( orgTabMap ) ;
33+ const OrganizationBillingPageInternal = withCardStateProvider ( ( ) => {
34+ const card = useCardState ( ) ;
35+ const { data : subscriptions } = useSubscriptions ( 'org' ) ;
36+ const { selectedTab, handleTabChange } = useTabState ( orgTabMap ) ;
37+ const { navigate } = useRouter ( ) ;
38+ if ( ! Array . isArray ( subscriptions ?. data ) ) {
39+ return null ;
40+ }
3741
38- if ( ! Array . isArray ( subscriptions ?. data ) ) {
39- return null ;
40- }
41-
42- return (
42+ return (
43+ < Col
44+ elementDescriptor = { descriptors . page }
45+ sx = { t => ( { gap : t . space . $8 , color : t . colors . $colorText } ) }
46+ >
4347 < Col
44- elementDescriptor = { descriptors . page }
45- sx = { t => ( { gap : t . space . $8 , color : t . colors . $colorText } ) }
48+ elementDescriptor = { descriptors . profilePage }
49+ elementId = { descriptors . profilePage . setId ( 'billing' ) }
50+ gap = { 4 }
4651 >
47- < Col
48- elementDescriptor = { descriptors . profilePage }
49- elementId = { descriptors . profilePage . setId ( 'billing' ) }
50- gap = { 4 }
51- >
52- < Header . Root >
53- < Header . Title
54- localizationKey = { localizationKeys ( 'userProfile.__experimental_billingPage.title' ) }
55- textVariant = 'h2'
56- />
57- </ Header . Root >
58-
59- < Card . Alert > { card . error } </ Card . Alert >
52+ < Header . Root >
53+ < Header . Title
54+ localizationKey = { localizationKeys ( 'userProfile.__experimental_billingPage.title' ) }
55+ textVariant = 'h2'
56+ />
57+ </ Header . Root >
6058
61- < Tabs
62- value = { selectedTab }
63- onChange = { handleTabChange }
64- >
65- < TabsList sx = { t => ( { gap : t . space . $6 } ) } >
66- < Tab
67- localizationKey = {
68- subscriptions . data . length > 0
69- ? localizationKeys ( 'userProfile.__experimental_billingPage.start.headerTitle__subscriptions' )
70- : localizationKeys ( 'userProfile.__experimental_billingPage.start.headerTitle__plans' )
71- }
72- />
73- < Tab
74- localizationKey = { localizationKeys ( 'userProfile.__experimental_billingPage.start.headerTitle__invoices' ) }
75- />
76- < Tab
77- localizationKey = { localizationKeys (
78- 'userProfile.__experimental_billingPage.start.headerTitle__paymentMethods' ,
79- ) }
80- />
81- </ TabsList >
82- < TabPanels >
83- < TabPanel sx = { { width : '100%' , flexDirection : 'column' } } >
84- { subscriptions . data . length > 0 && (
85- < >
86- < SubscriptionsList />
87- < Hr sx = { t => ( { marginBlock : t . space . $6 } ) } />
88- < Heading
89- textVariant = 'h3'
90- as = 'h2'
91- localizationKey = 'Available Plans'
92- sx = { t => ( { marginBlockEnd : t . space . $4 , fontWeight : t . fontWeights . $medium } ) }
93- />
94- </ >
95- ) }
59+ < Card . Alert > { card . error } </ Card . Alert >
9660
61+ < Tabs
62+ value = { selectedTab }
63+ onChange = { handleTabChange }
64+ >
65+ < TabsList sx = { t => ( { gap : t . space . $6 } ) } >
66+ < Tab
67+ localizationKey = {
68+ subscriptions . data . length > 0
69+ ? localizationKeys ( 'userProfile.__experimental_billingPage.start.headerTitle__subscriptions' )
70+ : localizationKeys ( 'userProfile.__experimental_billingPage.start.headerTitle__plans' )
71+ }
72+ />
73+ < Tab
74+ localizationKey = { localizationKeys ( 'userProfile.__experimental_billingPage.start.headerTitle__invoices' ) }
75+ />
76+ < Tab
77+ localizationKey = { localizationKeys (
78+ 'userProfile.__experimental_billingPage.start.headerTitle__paymentMethods' ,
79+ ) }
80+ />
81+ </ TabsList >
82+ < TabPanels >
83+ < TabPanel sx = { { width : '100%' , flexDirection : 'column' } } >
84+ { subscriptions . data . length > 0 ? (
85+ < >
86+ < SubscriptionsList />
87+ < Button
88+ localizationKey = 'View all plans'
89+ hasArrow
90+ variant = 'ghost'
91+ onClick = { ( ) => navigate ( 'plans' ) }
92+ sx = { t => ( {
93+ width : 'fit-content' ,
94+ marginTop : t . space . $4 ,
95+ } ) }
96+ />
97+ </ >
98+ ) : (
9799 < __experimental_PricingTableContext . Provider value = { { componentName : 'PricingTable' , mode : 'modal' } } >
98100 < __experimental_PricingTable />
99101 </ __experimental_PricingTableContext . Provider >
100- </ TabPanel >
101- < TabPanel sx = { { width : '100%' } } >
102- < InvoicesContextProvider >
103- < InvoicesList / >
104- </ InvoicesContextProvider >
105- </ TabPanel >
106- < TabPanel sx = { { width : '100%' } } >
107- < __experimental_PaymentSources / >
108- </ TabPanel >
109- </ TabPanels >
110- </ Tabs >
111- </ Col >
102+ ) }
103+ </ TabPanel >
104+ < TabPanel sx = { { width : '100%' } } >
105+ < InvoicesContextProvider >
106+ < InvoicesList / >
107+ </ InvoicesContextProvider >
108+ </ TabPanel >
109+ < TabPanel sx = { { width : '100%' } } >
110+ < __experimental_PaymentSources / >
111+ </ TabPanel >
112+ </ TabPanels >
113+ </ Tabs >
112114 </ Col >
113- ) ;
114- } ) ,
115- ) ;
115+ </ Col >
116+ ) ;
117+ } ) ;
116118
117119export const OrganizationBillingPage = ( ) => {
118120 return (
119121 < SubscriberTypeContext . Provider value = 'org' >
120- < OrganizationBillingPageInternal />
122+ < PlansContextProvider >
123+ < OrganizationBillingPageInternal />
124+ </ PlansContextProvider >
121125 </ SubscriberTypeContext . Provider >
122126 ) ;
123127} ;
0 commit comments