Make the subscriptions card expandable and collapsible.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9720daea05
commit
c886802cd6
|
|
@ -155,27 +155,42 @@ 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>
|
||||||
|
<div className="flex shrink-0 items-center gap-2">
|
||||||
<ActiveStatusBadge
|
<ActiveStatusBadge
|
||||||
label={anyActive ? "Active" : formatStatusLabel(subscriptions[0]?.status || "Inactive")}
|
label={anyActive ? "Active" : formatStatusLabel(subscriptions[0]?.status || "Inactive")}
|
||||||
tone={anyActive ? "active" : "inactive"}
|
tone={anyActive ? "active" : "inactive"}
|
||||||
/>
|
/>
|
||||||
|
{expanded ? (
|
||||||
|
<ChevronDown className="h-4 w-4 text-grayScale-400" />
|
||||||
|
) : (
|
||||||
|
<ChevronRight className="h-4 w-4 text-grayScale-400" />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</button>
|
||||||
|
|
||||||
<div className="mt-4 space-y-3 border-t border-grayScale-100 pt-4">
|
{expanded ? (
|
||||||
|
<div className="space-y-6 border-t border-grayScale-100 px-5 pb-5 pt-4 sm:px-6 sm:pb-6">
|
||||||
|
<div className="space-y-3">
|
||||||
{subscriptions.map((subscription) => {
|
{subscriptions.map((subscription) => {
|
||||||
const daysLeft = getDaysLeft(subscription)
|
const daysLeft = getDaysLeft(subscription)
|
||||||
const statusUpper = subscription.status.toUpperCase()
|
const statusUpper = subscription.status.toUpperCase()
|
||||||
|
|
@ -235,7 +250,7 @@ function ActiveSubscriptionsCard({
|
||||||
})}
|
})}
|
||||||
</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"
|
||||||
|
|
@ -270,6 +285,8 @@ function ActiveSubscriptionsCard({
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,23 +305,37 @@ 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>
|
||||||
|
<div className="flex shrink-0 items-center gap-2">
|
||||||
<ActiveStatusBadge
|
<ActiveStatusBadge
|
||||||
label={formatStatusLabel(displayStatus || "Unsubscribed")}
|
label={formatStatusLabel(displayStatus || "Unsubscribed")}
|
||||||
tone={tone}
|
tone={tone}
|
||||||
/>
|
/>
|
||||||
|
{expanded ? (
|
||||||
|
<ChevronDown className="h-4 w-4 text-grayScale-400" />
|
||||||
|
) : (
|
||||||
|
<ChevronRight className="h-4 w-4 text-grayScale-400" />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4 border-t border-grayScale-100 pt-4">
|
</button>
|
||||||
|
|
||||||
|
{expanded ? (
|
||||||
|
<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>
|
<p className="text-sm text-grayScale-500">No active subscription for this learner.</p>
|
||||||
</div>
|
<div className="flex flex-col gap-2">
|
||||||
<div className="mt-6 flex flex-col gap-2">
|
|
||||||
{canExtend ? (
|
{canExtend ? (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -348,6 +379,8 @@ function EmptySubscriptionCard({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user