@@ -2,26 +2,12 @@ import { useEffect, useState } from 'react'
22import { AlertCircle } from 'lucide-react'
33import { Alert , AlertDescription , AlertTitle } from '@/components/ui/alert'
44import { Button } from '@/components/ui/button'
5- import {
6- Dialog ,
7- DialogContent ,
8- DialogDescription ,
9- DialogFooter ,
10- DialogHeader ,
11- DialogTitle ,
12- } from '@/components/ui/dialog'
13- import { Label } from '@/components/ui/label'
145import { Progress } from '@/components/ui/progress'
15- import {
16- Select ,
17- SelectContent ,
18- SelectItem ,
19- SelectTrigger ,
20- SelectValue ,
21- } from '@/components/ui/select'
226import { Skeleton } from '@/components/ui/skeleton'
237import { useActiveOrganization , useSession , useSubscription } from '@/lib/auth-client'
8+ import { env } from '@/lib/env'
249import { createLogger } from '@/lib/logs/console-logger'
10+ import { TeamSeatsDialog } from './components/team-seats-dialog'
2511
2612const logger = createLogger ( 'Subscription' )
2713
@@ -332,7 +318,7 @@ export function Subscription({
332318 setIsTeamDialogOpen ( true )
333319 }
334320
335- const confirmTeamUpgrade = async ( ) => {
321+ const confirmTeamUpgrade = async ( selectedSeats ?: number ) => {
336322 if ( ! session ?. user ) {
337323 setError ( 'You need to be logged in to upgrade your team subscription' )
338324 return
@@ -341,10 +327,12 @@ export function Subscription({
341327 setIsUpgradingTeam ( true )
342328 setError ( null )
343329
330+ const seatsToUse = selectedSeats || seats
331+
344332 try {
345333 const result = await subscription . upgrade ( {
346334 plan : 'team' ,
347- seats,
335+ seats : seatsToUse ,
348336 successUrl : window . location . href ,
349337 cancelUrl : window . location . href ,
350338 } )
@@ -816,54 +804,19 @@ export function Subscription({
816804 </ div >
817805 ) }
818806
819- < Dialog open = { isTeamDialogOpen } onOpenChange = { setIsTeamDialogOpen } >
820- < DialogContent >
821- < DialogHeader >
822- < DialogTitle > Team Subscription</ DialogTitle >
823- < DialogDescription >
824- Set up a team workspace with collaborative features. Each seat costs $40/month and
825- gets $40 of inference credits.
826- </ DialogDescription >
827- </ DialogHeader >
828-
829- < div className = 'py-4' >
830- < Label htmlFor = 'seats' > Number of seats</ Label >
831- < Select
832- value = { seats . toString ( ) }
833- onValueChange = { ( value ) => setSeats ( Number . parseInt ( value ) ) }
834- >
835- < SelectTrigger id = 'seats' >
836- < SelectValue placeholder = 'Select number of seats' />
837- </ SelectTrigger >
838- < SelectContent >
839- { [ 1 , 2 , 3 , 4 , 5 , 10 , 15 , 20 , 25 , 30 , 40 , 50 ] . map ( ( num ) => (
840- < SelectItem key = { num } value = { num . toString ( ) } >
841- { num } { num === 1 ? 'seat' : 'seats' } (${ num * 40 } /month)
842- </ SelectItem >
843- ) ) }
844- </ SelectContent >
845- </ Select >
846-
847- < p className = 'mt-2 text-muted-foreground text-sm' >
848- Your team will have { seats } { seats === 1 ? 'seat' : 'seats' } with a total of $
849- { seats * 40 } inference credits per month.
850- </ p >
851- </ div >
852-
853- < DialogFooter >
854- < Button
855- variant = 'outline'
856- onClick = { ( ) => setIsTeamDialogOpen ( false ) }
857- disabled = { isUpgradingTeam }
858- >
859- Cancel
860- </ Button >
861- < Button onClick = { confirmTeamUpgrade } disabled = { isUpgradingTeam } >
862- { isUpgradingTeam ? < ButtonSkeleton /> : < span > Upgrade to Team Plan</ span > }
863- </ Button >
864- </ DialogFooter >
865- </ DialogContent >
866- </ Dialog >
807+ < TeamSeatsDialog
808+ open = { isTeamDialogOpen }
809+ onOpenChange = { setIsTeamDialogOpen }
810+ title = 'Team Subscription'
811+ description = { `Set up a team workspace with collaborative features. Each seat costs $${ env . TEAM_TIER_COST_LIMIT } /month and gets $${ env . TEAM_TIER_COST_LIMIT } of inference credits.` }
812+ initialSeats = { seats }
813+ isLoading = { isUpgradingTeam }
814+ onConfirm = { async ( selectedSeats : number ) => {
815+ setSeats ( selectedSeats )
816+ await confirmTeamUpgrade ( selectedSeats )
817+ } }
818+ confirmButtonText = 'Upgrade to Team Plan'
819+ />
867820 </ >
868821 ) }
869822 </ div >
0 commit comments