@@ -169,7 +169,6 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
169169 const canManageWorkspaceKeys = userPermissions . canAdmin
170170 const logger = createLogger ( 'Subscription' )
171171
172- // React Query hooks for data fetching
173172 const { data : subscriptionData , isLoading : isSubscriptionLoading } = useSubscriptionData ( )
174173 const { data : usageLimitResponse , isLoading : isUsageLimitLoading } = useUsageLimitData ( )
175174 const { data : workspaceData , isLoading : isWorkspaceLoading } = useWorkspaceSettings ( workspaceId )
@@ -179,18 +178,15 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
179178 const activeOrganization = orgsData ?. activeOrganization
180179 const activeOrgId = activeOrganization ?. id
181180
182- // Fetch organization billing data with React Query
183181 const { data : organizationBillingData , isLoading : isOrgBillingLoading } = useOrganizationBilling (
184182 activeOrgId || ''
185183 )
186184
187185 const [ upgradeError , setUpgradeError ] = useState < 'pro' | 'team' | null > ( null )
188186 const usageLimitRef = useRef < UsageLimitRef | null > ( null )
189187
190- // Combine all loading states
191188 const isLoading = isSubscriptionLoading || isUsageLimitLoading || isWorkspaceLoading
192189
193- // Extract subscription status from subscriptionData.data
194190 const subscription = {
195191 isFree : subscriptionData ?. data ?. plan === 'free' || ! subscriptionData ?. data ?. plan ,
196192 isPro : subscriptionData ?. data ?. plan === 'pro' ,
@@ -205,28 +201,23 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
205201 seats : subscriptionData ?. data ?. seats || 1 ,
206202 }
207203
208- // Extract usage data from subscriptionData.data.usage (same source as panel usage indicator)
209204 const usage = {
210205 current : subscriptionData ?. data ?. usage ?. current || 0 ,
211206 limit : subscriptionData ?. data ?. usage ?. limit || 0 ,
212207 percentUsed : subscriptionData ?. data ?. usage ?. percentUsed || 0 ,
213208 }
214209
215- // Extract usage limit metadata from usageLimitResponse.data
216210 const usageLimitData = {
217211 currentLimit : usageLimitResponse ?. data ?. currentLimit || 0 ,
218212 minimumLimit : usageLimitResponse ?. data ?. minimumLimit || ( subscription . isPro ? 20 : 40 ) ,
219213 }
220214
221- // Extract billing status
222215 const billingStatus = subscriptionData ?. data ?. billingBlocked ? 'blocked' : 'ok'
223216
224- // Extract workspace settings
225217 const billedAccountUserId = workspaceData ?. settings ?. workspace ?. billedAccountUserId ?? null
226218 const workspaceAdmins =
227219 workspaceData ?. permissions ?. users ?. filter ( ( user : any ) => user . permissionType === 'admin' ) || [ ]
228220
229- // Update workspace settings handler
230221 const updateWorkspaceSettings = async ( updates : { billedAccountUserId ?: string } ) => {
231222 if ( ! workspaceId ) return
232223 try {
@@ -240,7 +231,6 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
240231 }
241232 }
242233
243- // Auto-clear upgrade error
244234 useEffect ( ( ) => {
245235 if ( upgradeError ) {
246236 const timer = setTimeout ( ( ) => {
@@ -250,11 +240,9 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
250240 }
251241 } , [ upgradeError ] )
252242
253- // User role and permissions
254243 const userRole = getUserRole ( activeOrganization , session ?. user ?. email )
255244 const isTeamAdmin = [ 'owner' , 'admin' ] . includes ( userRole )
256245
257- // Get permissions based on subscription state and user role
258246 const permissions = getSubscriptionPermissions (
259247 {
260248 isFree : subscription . isFree ,
@@ -271,7 +259,6 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
271259 }
272260 )
273261
274- // Get visible plans based on current subscription
275262 const visiblePlans = getVisiblePlans (
276263 {
277264 isFree : subscription . isFree ,
@@ -459,8 +446,8 @@ export function Subscription({ onOpenChange }: SubscriptionProps) {
459446 }
460447 context = { subscription . isTeam && isTeamAdmin ? 'organization' : 'user' }
461448 organizationId = { subscription . isTeam && isTeamAdmin ? activeOrgId : undefined }
462- onLimitUpdated = { async ( ) => {
463- // React Query will automatically refetch when the mutation completes
449+ onLimitUpdated = { ( ) => {
450+ logger . info ( 'Usage limit updated' )
464451 } }
465452 />
466453 ) : undefined
0 commit comments