5
5
ShieldCheckIcon ,
6
6
XMarkIcon ,
7
7
} from "@heroicons/react/20/solid" ;
8
- import { ArrowDownCircleIcon } from "@heroicons/react/24/outline" ;
8
+ import { ArrowDownCircleIcon , ArrowUpCircleIcon } from "@heroicons/react/24/outline" ;
9
9
import { Form , useLocation , useNavigation } from "@remix-run/react" ;
10
10
import { ActionFunctionArgs } from "@remix-run/server-runtime" ;
11
11
import { uiComponent } from "@team-plain/typescript-sdk" ;
@@ -633,6 +633,11 @@ export function TierPro({
633
633
const navigation = useNavigation ( ) ;
634
634
const formAction = `/resources/orgs/${ organizationSlug } /select-plan` ;
635
635
const isLoading = navigation . formAction === formAction ;
636
+ const [ isDialogOpen , setIsDialogOpen ] = useState ( false ) ;
637
+
638
+ useEffect ( ( ) => {
639
+ setIsDialogOpen ( false ) ;
640
+ } , [ subscription ] ) ;
636
641
637
642
return (
638
643
< TierContainer >
@@ -645,27 +650,67 @@ export function TierPro({
645
650
< input type = "hidden" name = "type" value = "paid" />
646
651
< input type = "hidden" name = "planCode" value = { plan . code } />
647
652
< input type = "hidden" name = "callerPath" value = { location . pathname } />
648
- < Button
649
- variant = "tertiary/large"
650
- fullWidth
651
- form = "subscribe-pro"
652
- className = "text-md font-medium"
653
- disabled = {
654
- isLoading ||
655
- ( subscription ?. plan ?. code === plan . code && subscription . canceledAt === undefined )
656
- }
657
- LeadingIcon = {
658
- isLoading && navigation . formData ?. get ( "planCode" ) === plan . code ? Spinner : undefined
659
- }
660
- >
661
- { subscription ?. plan === undefined
662
- ? "Select plan"
663
- : subscription . plan . type === "free" || subscription . canceledAt !== undefined
664
- ? `Upgrade to ${ plan . title } `
665
- : subscription . plan . code === plan . code
666
- ? "Current plan"
667
- : `Upgrade to ${ plan . title } ` }
668
- </ Button >
653
+ { subscription ?. plan !== undefined &&
654
+ subscription ?. plan ?. type === "paid" &&
655
+ subscription ?. plan ?. code !== plan . code &&
656
+ subscription . canceledAt === undefined ? (
657
+ < Dialog open = { isDialogOpen } onOpenChange = { setIsDialogOpen } key = "upgrade" >
658
+ < DialogTrigger asChild >
659
+ < Button variant = "tertiary/large" fullWidth className = "text-md font-medium" >
660
+ { `Upgrade to ${ plan . title } ` }
661
+ </ Button >
662
+ </ DialogTrigger >
663
+ < DialogContent className = "sm:max-w-md" >
664
+ < DialogHeader > Upgrade plan?</ DialogHeader >
665
+ < div className = "mb-2 mt-4 flex items-start gap-3" >
666
+ < span >
667
+ < ArrowUpCircleIcon className = "size-12 text-primary" />
668
+ </ span >
669
+ < Paragraph variant = "base/bright" className = "text-text-bright" >
670
+ Are you sure you want to upgrade to the Pro plan? You will be charged the new
671
+ plan price for the remainder of this month on a pro rata basis.
672
+ </ Paragraph >
673
+ </ div >
674
+ < DialogFooter >
675
+ < Button variant = "tertiary/medium" onClick = { ( ) => setIsDialogOpen ( false ) } >
676
+ Cancel
677
+ </ Button >
678
+ < Button
679
+ variant = "primary/medium"
680
+ disabled = { isLoading }
681
+ LeadingIcon = { isLoading ? ( ) => < Spinner color = "dark" /> : undefined }
682
+ form = "subscribe-pro"
683
+ >
684
+ { `Upgrade to ${ plan . title } ` }
685
+ </ Button >
686
+ </ DialogFooter >
687
+ </ DialogContent >
688
+ </ Dialog >
689
+ ) : (
690
+ < Button
691
+ variant = "tertiary/large"
692
+ fullWidth
693
+ form = "subscribe-pro"
694
+ className = "text-md font-medium"
695
+ disabled = {
696
+ isLoading ||
697
+ ( subscription ?. plan ?. code === plan . code && subscription . canceledAt === undefined )
698
+ }
699
+ LeadingIcon = {
700
+ isLoading && navigation . formData ?. get ( "planCode" ) === plan . code
701
+ ? Spinner
702
+ : undefined
703
+ }
704
+ >
705
+ { subscription ?. plan === undefined
706
+ ? "Select plan"
707
+ : subscription . plan . type === "free" || subscription . canceledAt !== undefined
708
+ ? `Upgrade to ${ plan . title } `
709
+ : subscription . plan . code === plan . code
710
+ ? "Current plan"
711
+ : `Upgrade to ${ plan . title } ` }
712
+ </ Button >
713
+ ) }
669
714
</ div >
670
715
</ Form >
671
716
< ul className = "flex flex-col gap-2.5" >
0 commit comments