Make the subscriptions card expandable and collapsible.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-08-10 14:05:28 +03:00
parent 9720daea05
commit c886802cd6

View File

@ -155,120 +155,137 @@ function ActiveSubscriptionsCard({
onGrant: () => void onGrant: () => void
onCancel: (subscription: UserSubscriptionRecord) => void onCancel: (subscription: UserSubscriptionRecord) => void
}) { }) {
const [expanded, setExpanded] = useState(true)
const anyActive = subscriptions.some( const anyActive = subscriptions.some(
(subscription) => (subscription) =>
subscription.is_currently_active || subscription.status.toUpperCase() === "ACTIVE", subscription.is_currently_active || subscription.status.toUpperCase() === "ACTIVE",
) )
return ( return (
<div className="rounded-2xl border border-grayScale-200 bg-white p-5 shadow-sm sm:p-6"> <div className="rounded-2xl border border-grayScale-200 bg-white shadow-sm">
<div className="flex items-start justify-between gap-3"> <button
<div> type="button"
className="flex w-full items-start justify-between gap-3 px-5 py-4 text-left sm:px-6 sm:py-5"
onClick={() => setExpanded((value) => !value)}
aria-expanded={expanded}
>
<div className="min-w-0 flex-1">
<h3 className="text-base font-bold text-grayScale-900">Subscriptions</h3> <h3 className="text-base font-bold text-grayScale-900">Subscriptions</h3>
<p className="mt-0.5 text-xs text-grayScale-500"> <p className="mt-0.5 text-xs text-grayScale-500">
{subscriptions.length} active plan{subscriptions.length === 1 ? "" : "s"} {subscriptions.length} active plan{subscriptions.length === 1 ? "" : "s"}
</p> </p>
</div> </div>
<ActiveStatusBadge <div className="flex shrink-0 items-center gap-2">
label={anyActive ? "Active" : formatStatusLabel(subscriptions[0]?.status || "Inactive")} <ActiveStatusBadge
tone={anyActive ? "active" : "inactive"} label={anyActive ? "Active" : formatStatusLabel(subscriptions[0]?.status || "Inactive")}
/> tone={anyActive ? "active" : "inactive"}
</div> />
{expanded ? (
<ChevronDown className="h-4 w-4 text-grayScale-400" />
) : (
<ChevronRight className="h-4 w-4 text-grayScale-400" />
)}
</div>
</button>
<div className="mt-4 space-y-3 border-t border-grayScale-100 pt-4"> {expanded ? (
{subscriptions.map((subscription) => { <div className="space-y-6 border-t border-grayScale-100 px-5 pb-5 pt-4 sm:px-6 sm:pb-6">
const daysLeft = getDaysLeft(subscription) <div className="space-y-3">
const statusUpper = subscription.status.toUpperCase() {subscriptions.map((subscription) => {
const isActive = const daysLeft = getDaysLeft(subscription)
subscription.is_currently_active || statusUpper === "ACTIVE" const statusUpper = subscription.status.toUpperCase()
const cancelEnabled = const isActive =
canCancel && isActive && statusUpper !== "CANCELLED" subscription.is_currently_active || statusUpper === "ACTIVE"
const cancelEnabled =
canCancel && isActive && statusUpper !== "CANCELLED"
return ( return (
<div <div
key={subscription.id} key={subscription.id}
className="rounded-xl border border-grayScale-100 bg-grayScale-50/70 px-4 py-3" className="rounded-xl border border-grayScale-100 bg-grayScale-50/70 px-4 py-3"
> >
<div className="flex flex-wrap items-start justify-between gap-3"> <div className="flex flex-wrap items-start justify-between gap-3">
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="text-sm font-bold text-grayScale-900"> <p className="text-sm font-bold text-grayScale-900">
{formatPlanTitle(subscription)} {formatPlanTitle(subscription)}
</p> </p>
<p className="mt-0.5 text-xs text-grayScale-500"> <p className="mt-0.5 text-xs text-grayScale-500">
{formatPlanCategory(subscription.plan_category)} · Expires{" "} {formatPlanCategory(subscription.plan_category)} · Expires{" "}
{formatExpiryDate(subscription)} {formatExpiryDate(subscription)}
{daysLeft != null ? ` · ${formatDaysLeftLabel(daysLeft)}` : ""} {daysLeft != null ? ` · ${formatDaysLeftLabel(daysLeft)}` : ""}
</p> </p>
</div>
<div className="flex flex-wrap items-center gap-2">
<ActiveStatusBadge
label={formatStatusLabel(subscription.status)}
tone={
isActive
? "active"
: statusUpper === "PENDING"
? "pending"
: "inactive"
}
/>
{canCancel ? (
<Button
type="button"
variant="outline"
size="sm"
className="h-8 rounded-lg text-xs text-destructive disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled={!cancelEnabled}
title={
!cancelEnabled
? "Cancel is only available when this subscription is active."
: undefined
}
onClick={() => onCancel(subscription)}
>
Cancel
</Button>
) : null}
</div>
</div>
</div> </div>
<div className="flex flex-wrap items-center gap-2"> )
<ActiveStatusBadge })}
label={formatStatusLabel(subscription.status)} </div>
tone={
isActive
? "active"
: statusUpper === "PENDING"
? "pending"
: "inactive"
}
/>
{canCancel ? (
<Button
type="button"
variant="outline"
size="sm"
className="h-8 rounded-lg text-xs text-destructive disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled={!cancelEnabled}
title={
!cancelEnabled
? "Cancel is only available when this subscription is active."
: undefined
}
onClick={() => onCancel(subscription)}
>
Cancel
</Button>
) : null}
</div>
</div>
</div>
)
})}
</div>
<div className="mt-6 flex flex-col gap-2"> <div className="flex flex-col gap-2">
{canExtend ? ( {canExtend ? (
<Button <Button
type="button" type="button"
className="h-10 w-full rounded-xl bg-brand-500 text-sm font-semibold text-white hover:bg-brand-600 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50" className="h-10 w-full rounded-xl bg-brand-500 text-sm font-semibold text-white hover:bg-brand-600 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled={!extendEnabled} disabled={!extendEnabled}
title={ title={
!extendEnabled !extendEnabled
? "Extend is only available when this learner has an active, non-lifetime subscription." ? "Extend is only available when this learner has an active, non-lifetime subscription."
: undefined : undefined
} }
onClick={onExtend} onClick={onExtend}
> >
<RefreshCw className="mr-2 h-4 w-4" /> <RefreshCw className="mr-2 h-4 w-4" />
Extend Subscription Extend Subscription
</Button> </Button>
) : null} ) : null}
{canGrant ? ( {canGrant ? (
<Button <Button
type="button" type="button"
className="h-10 w-full rounded-xl bg-grayScale-100 text-sm font-semibold text-grayScale-700 hover:bg-grayScale-200 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50" className="h-10 w-full rounded-xl bg-grayScale-100 text-sm font-semibold text-grayScale-700 hover:bg-grayScale-200 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled={!grantEnabled} disabled={!grantEnabled}
title={ title={
!grantEnabled !grantEnabled
? "Grant is unavailable because every plan category already has an active subscription." ? "Grant is unavailable because every plan category already has an active subscription."
: undefined : undefined
} }
onClick={onGrant} onClick={onGrant}
> >
Grant Subscription Grant Subscription
</Button> </Button>
) : null} ) : null}
</div> </div>
</div>
) : null}
</div> </div>
) )
} }
@ -288,65 +305,81 @@ function EmptySubscriptionCard({
grantEnabled: boolean grantEnabled: boolean
onGrant: () => void onGrant: () => void
}) { }) {
const [expanded, setExpanded] = useState(true)
const upper = displayStatus.toUpperCase() const upper = displayStatus.toUpperCase()
const tone = const tone =
upper === "ACTIVE" ? "active" : upper === "PENDING" ? "pending" : "inactive" upper === "ACTIVE" ? "active" : upper === "PENDING" ? "pending" : "inactive"
return ( return (
<div className="rounded-2xl border border-grayScale-200 bg-white p-5 shadow-sm sm:p-6"> <div className="rounded-2xl border border-grayScale-200 bg-white shadow-sm">
<div className="flex items-start justify-between gap-3"> <button
type="button"
className="flex w-full items-start justify-between gap-3 px-5 py-4 text-left sm:px-6 sm:py-5"
onClick={() => setExpanded((value) => !value)}
aria-expanded={expanded}
>
<h3 className="text-base font-bold text-grayScale-900">Subscriptions</h3> <h3 className="text-base font-bold text-grayScale-900">Subscriptions</h3>
<ActiveStatusBadge <div className="flex shrink-0 items-center gap-2">
label={formatStatusLabel(displayStatus || "Unsubscribed")} <ActiveStatusBadge
tone={tone} label={formatStatusLabel(displayStatus || "Unsubscribed")}
/> tone={tone}
</div> />
<div className="mt-4 border-t border-grayScale-100 pt-4"> {expanded ? (
<p className="text-sm text-grayScale-500">No active subscription for this learner.</p> <ChevronDown className="h-4 w-4 text-grayScale-400" />
</div> ) : (
<div className="mt-6 flex flex-col gap-2"> <ChevronRight className="h-4 w-4 text-grayScale-400" />
{canExtend ? ( )}
<Button </div>
type="button" </button>
className="h-10 w-full rounded-xl bg-brand-500 text-sm font-semibold text-white hover:bg-brand-600 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled {expanded ? (
title="Extend is only available when this learner has an active subscription." <div className="space-y-6 border-t border-grayScale-100 px-5 pb-5 pt-4 sm:px-6 sm:pb-6">
> <p className="text-sm text-grayScale-500">No active subscription for this learner.</p>
<RefreshCw className="mr-2 h-4 w-4" /> <div className="flex flex-col gap-2">
Extend Subscription {canExtend ? (
</Button>
) : null}
{(canGrant || canCancel) && (
<div className="flex flex-wrap gap-2">
{canGrant ? (
<Button <Button
type="button" type="button"
className="h-10 min-w-0 flex-1 rounded-xl bg-brand-500 text-sm font-semibold text-white hover:bg-brand-600 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50" className="h-10 w-full rounded-xl bg-brand-500 text-sm font-semibold text-white hover:bg-brand-600 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled={!grantEnabled}
title={
!grantEnabled
? "No active subscription plans are available to grant."
: undefined
}
onClick={onGrant}
>
Grant Subscription
</Button>
) : null}
{canCancel ? (
<Button
type="button"
variant="outline"
className="h-10 min-w-0 flex-1 rounded-xl border-grayScale-200 bg-white text-sm font-semibold text-grayScale-700 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled disabled
title="Cancel is only available when this learner has an active subscription." title="Extend is only available when this learner has an active subscription."
> >
Cancel <RefreshCw className="mr-2 h-4 w-4" />
Extend Subscription
</Button> </Button>
) : null} ) : null}
{(canGrant || canCancel) && (
<div className="flex flex-wrap gap-2">
{canGrant ? (
<Button
type="button"
className="h-10 min-w-0 flex-1 rounded-xl bg-brand-500 text-sm font-semibold text-white hover:bg-brand-600 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled={!grantEnabled}
title={
!grantEnabled
? "No active subscription plans are available to grant."
: undefined
}
onClick={onGrant}
>
Grant Subscription
</Button>
) : null}
{canCancel ? (
<Button
type="button"
variant="outline"
className="h-10 min-w-0 flex-1 rounded-xl border-grayScale-200 bg-white text-sm font-semibold text-grayScale-700 disabled:pointer-events-auto disabled:cursor-not-allowed disabled:opacity-50"
disabled
title="Cancel is only available when this learner has an active subscription."
>
Cancel
</Button>
) : null}
</div>
)}
</div> </div>
)} </div>
</div> ) : null}
</div> </div>
) )
} }