4
4
ShieldCheckIcon ,
5
5
XMarkIcon ,
6
6
} from "@heroicons/react/20/solid" ;
7
- import { XCircleIcon } from "@heroicons/react/24/outline" ;
7
+ import { ArrowDownCircleIcon , XCircleIcon } from "@heroicons/react/24/outline" ;
8
8
import { Form , useFetcher , useLocation , useNavigation } from "@remix-run/react" ;
9
9
import { ActionFunctionArgs } from "@remix-run/server-runtime" ;
10
10
import { PlainClient , uiComponent } from "@team-plain/typescript-sdk" ;
@@ -44,6 +44,7 @@ import { logger } from "~/services/logger.server";
44
44
import { setPlan } from "~/services/platform.v3.server" ;
45
45
import { requireUser } from "~/services/session.server" ;
46
46
import { cn } from "~/utils/cn" ;
47
+ import React from "react" ;
47
48
48
49
const Params = z . object ( {
49
50
organizationSlug : z . string ( ) ,
@@ -302,6 +303,7 @@ export function TierFree({
302
303
const formAction = `/resources/orgs/${ organizationSlug } /select-plan` ;
303
304
const isLoading = navigation . formAction === formAction ;
304
305
const [ isDialogOpen , setIsDialogOpen ] = useState ( false ) ;
306
+ const [ isLackingFeaturesChecked , setIsLackingFeaturesChecked ] = useState ( false ) ;
305
307
306
308
const status = subscription ?. freeTierStatus ?? "requires_connect" ;
307
309
@@ -418,7 +420,7 @@ export function TierFree({
418
420
{ `Downgrade to ${ plan . title } ` }
419
421
</ Button >
420
422
</ DialogTrigger >
421
- < DialogContent className = "max-w-md" >
423
+ < DialogContent className = "sm: max-w-md" >
422
424
< DialogHeader > Downgrade plan</ DialogHeader >
423
425
< div className = "mb-2 mt-4 flex items-start gap-3" >
424
426
< span >
@@ -451,13 +453,22 @@ export function TierFree({
451
453
variant = "simple"
452
454
label = { label }
453
455
labelClassName = "text-text-dimmed"
456
+ onChange = { ( isChecked : boolean ) => {
457
+ if ( label === "Lacking features I need" ) {
458
+ setIsLackingFeaturesChecked ( isChecked ) ;
459
+ }
460
+ } }
454
461
/>
455
462
</ li >
456
463
) ) }
457
464
</ ul >
458
465
</ div >
459
466
< div >
460
- < Header2 className = "mb-1" > What can we do to improve?</ Header2 >
467
+ < Header2 className = "mb-1" >
468
+ { isLackingFeaturesChecked
469
+ ? "What features do you need? Or how can we improve?"
470
+ : "What can we do to improve?" }
471
+ </ Header2 >
461
472
< TextArea id = "improvement-suggestions" name = "message" />
462
473
</ div >
463
474
</ div >
@@ -467,12 +478,11 @@ export function TierFree({
467
478
</ Button >
468
479
< Button
469
480
variant = "danger/medium"
470
- type = "submit"
471
- form = "subscribe"
472
481
disabled = { isLoading }
473
482
LeadingIcon = {
474
483
isLoading && "submitting" ? ( ) => < Spinner color = "white" /> : undefined
475
484
}
485
+ form = "subscribe"
476
486
>
477
487
Downgrade plan
478
488
</ Button >
@@ -543,6 +553,7 @@ export function TierHobby({
543
553
const navigation = useNavigation ( ) ;
544
554
const formAction = `/resources/orgs/${ organizationSlug } /select-plan` ;
545
555
const isLoading = navigation . formAction === formAction ;
556
+ const [ isDialogOpen , setIsDialogOpen ] = useState ( false ) ;
546
557
547
558
return (
548
559
< TierContainer isHighlighted = { isHighlighted } >
@@ -555,26 +566,68 @@ export function TierHobby({
555
566
< input type = "hidden" name = "type" value = "paid" />
556
567
< input type = "hidden" name = "planCode" value = { plan . code } />
557
568
< input type = "hidden" name = "callerPath" value = { location . pathname } />
558
- < Button
559
- variant = { isHighlighted ? "primary/large" : "tertiary/large" }
560
- fullWidth
561
- className = "text-md font-medium"
562
- disabled = {
563
- isLoading ||
564
- ( subscription ?. plan ?. code === plan . code && subscription . canceledAt === undefined )
565
- }
566
- LeadingIcon = {
567
- isLoading && navigation . formData ?. get ( "planCode" ) === plan . code ? Spinner : undefined
568
- }
569
- >
570
- { subscription ?. plan === undefined
571
- ? "Select plan"
572
- : subscription . plan . type === "free" || subscription . canceledAt !== undefined
573
- ? `Upgrade to ${ plan . title } `
574
- : subscription . plan . code === plan . code
575
- ? "Current plan"
576
- : `Downgrade to ${ plan . title } ` }
577
- </ Button >
569
+ { subscription ?. plan !== undefined &&
570
+ subscription . plan . type !== "free" &&
571
+ subscription . canceledAt === undefined &&
572
+ subscription . plan . code !== plan . code ? (
573
+ < Dialog open = { isDialogOpen } onOpenChange = { setIsDialogOpen } >
574
+ < DialogTrigger asChild >
575
+ < Button variant = "tertiary/large" fullWidth className = "text-md font-medium" >
576
+ { `Downgrade to ${ plan . title } ` }
577
+ </ Button >
578
+ </ DialogTrigger >
579
+ < DialogContent className = "sm:max-w-md" >
580
+ < DialogHeader > Downgrade plan</ DialogHeader >
581
+ < div className = "mb-2 mt-4 flex items-start gap-3" >
582
+ < span >
583
+ < ArrowDownCircleIcon className = "size-12 text-blue-500" />
584
+ </ span >
585
+ < Paragraph variant = "base/bright" className = "text-text-bright" >
586
+ By downgrading you will lose access to your current plan’s features and your
587
+ included credits will be reduced.
588
+ </ Paragraph >
589
+ </ div >
590
+ < DialogFooter >
591
+ < Button variant = "tertiary/medium" onClick = { ( ) => setIsDialogOpen ( false ) } >
592
+ Dismiss
593
+ </ Button >
594
+ < Button
595
+ variant = "tertiary/medium"
596
+ disabled = { isLoading }
597
+ LeadingIcon = {
598
+ isLoading && "submitting" ? ( ) => < Spinner color = "white" /> : undefined
599
+ }
600
+ form = "subscribe"
601
+ >
602
+ { `Downgrade to ${ plan . title } ` }
603
+ </ Button >
604
+ </ DialogFooter >
605
+ </ DialogContent >
606
+ </ Dialog >
607
+ ) : (
608
+ < Button
609
+ variant = { isHighlighted ? "primary/large" : "tertiary/large" }
610
+ fullWidth
611
+ className = "text-md font-medium"
612
+ disabled = {
613
+ isLoading ||
614
+ ( subscription ?. plan ?. code === plan . code && subscription . canceledAt === undefined )
615
+ }
616
+ LeadingIcon = {
617
+ isLoading && navigation . formData ?. get ( "planCode" ) === plan . code
618
+ ? Spinner
619
+ : undefined
620
+ }
621
+ >
622
+ { subscription ?. plan === undefined
623
+ ? "Select plan"
624
+ : subscription . plan . type === "free" || subscription . canceledAt !== undefined
625
+ ? `Upgrade to ${ plan . title } `
626
+ : subscription . plan . code === plan . code
627
+ ? "Current plan"
628
+ : `Upgrade to ${ plan . title } ` }
629
+ </ Button >
630
+ ) }
578
631
</ div >
579
632
</ Form >
580
633
< ul className = "flex flex-col gap-2.5" >
0 commit comments