Treat IELTS and Duolingo subscription plans as one-time lifetime access.
Hide duration editing for those categories, show never-expires in user subscriptions, and disable extend for lifetime plans. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
827e20b4f1
commit
2180d64b06
|
|
@ -14,6 +14,27 @@ export const SUBSCRIPTION_PLAN_CATEGORIES: {
|
||||||
{ value: "DUOLINGO", label: "Duolingo" },
|
{ value: "DUOLINGO", label: "Duolingo" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const LIFETIME_SUBSCRIPTION_CATEGORIES: SubscriptionPlanCategory[] = ["IELTS", "DUOLINGO"]
|
||||||
|
|
||||||
|
export const LIFETIME_DURATION_DEFAULT = {
|
||||||
|
duration_value: 1,
|
||||||
|
duration_unit: "YEAR" as SubscriptionPlanDurationUnit,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isLifetimePlanCategory(category: string | null | undefined): boolean {
|
||||||
|
if (!category) return false
|
||||||
|
const normalized = category.trim().toUpperCase()
|
||||||
|
return LIFETIME_SUBSCRIPTION_CATEGORIES.includes(normalized as SubscriptionPlanCategory)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True when expires_at is the far-future lifetime sentinel (year >= 9000). */
|
||||||
|
export function isLifetimeExpiry(expiresAt: string | null | undefined): boolean {
|
||||||
|
if (!expiresAt?.trim()) return false
|
||||||
|
const d = new Date(expiresAt)
|
||||||
|
if (Number.isNaN(d.getTime())) return false
|
||||||
|
return d.getUTCFullYear() >= 9000
|
||||||
|
}
|
||||||
|
|
||||||
export const SUBSCRIPTION_DURATION_UNITS: {
|
export const SUBSCRIPTION_DURATION_UNITS: {
|
||||||
value: SubscriptionPlanDurationUnit
|
value: SubscriptionPlanDurationUnit
|
||||||
label: string
|
label: string
|
||||||
|
|
@ -26,7 +47,10 @@ export const SUBSCRIPTION_DURATION_UNITS: {
|
||||||
|
|
||||||
export const SUBSCRIPTION_CURRENCIES = ["ETB", "USD"] as const
|
export const SUBSCRIPTION_CURRENCIES = ["ETB", "USD"] as const
|
||||||
|
|
||||||
export function formatPlanDuration(plan: Pick<SubscriptionPlan, "duration_value" | "duration_unit">): string {
|
export function formatPlanDuration(
|
||||||
|
plan: Pick<SubscriptionPlan, "duration_value" | "duration_unit"> & { category?: string },
|
||||||
|
): string {
|
||||||
|
if (plan.category && isLifetimePlanCategory(plan.category)) return "One-time"
|
||||||
const v = plan.duration_value
|
const v = plan.duration_value
|
||||||
const u = String(plan.duration_unit).toUpperCase()
|
const u = String(plan.duration_unit).toUpperCase()
|
||||||
const word =
|
const word =
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ import { Select } from "../../../components/ui/select"
|
||||||
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
||||||
import { Textarea } from "../../../components/ui/textarea"
|
import { Textarea } from "../../../components/ui/textarea"
|
||||||
import { ToggleSwitch } from "../../../components/ui/toggle-switch"
|
import { ToggleSwitch } from "../../../components/ui/toggle-switch"
|
||||||
import { cn } from "../../../lib/utils"
|
|
||||||
import {
|
import {
|
||||||
|
isLifetimePlanCategory,
|
||||||
|
LIFETIME_DURATION_DEFAULT,
|
||||||
SUBSCRIPTION_CURRENCIES,
|
SUBSCRIPTION_CURRENCIES,
|
||||||
SUBSCRIPTION_DURATION_UNITS,
|
SUBSCRIPTION_DURATION_UNITS,
|
||||||
SUBSCRIPTION_PLAN_CATEGORIES,
|
SUBSCRIPTION_PLAN_CATEGORIES,
|
||||||
|
|
@ -55,8 +56,12 @@ export const EMPTY_SUBSCRIPTION_PLAN_DRAFT: CreateSubscriptionPlanDraft = {
|
||||||
function draftToPayload(draft: CreateSubscriptionPlanDraft): CreateSubscriptionPlanPayload | null {
|
function draftToPayload(draft: CreateSubscriptionPlanDraft): CreateSubscriptionPlanPayload | null {
|
||||||
const name = draft.name.trim()
|
const name = draft.name.trim()
|
||||||
const description = draft.description.trim()
|
const description = draft.description.trim()
|
||||||
const duration_value = Number(draft.duration_value)
|
|
||||||
const price = Number(draft.price)
|
const price = Number(draft.price)
|
||||||
|
const isLifetime = isLifetimePlanCategory(draft.category)
|
||||||
|
const duration_value = isLifetime
|
||||||
|
? LIFETIME_DURATION_DEFAULT.duration_value
|
||||||
|
: Number(draft.duration_value)
|
||||||
|
const duration_unit = isLifetime ? LIFETIME_DURATION_DEFAULT.duration_unit : draft.duration_unit
|
||||||
|
|
||||||
if (!name) return null
|
if (!name) return null
|
||||||
if (!description) return null
|
if (!description) return null
|
||||||
|
|
@ -68,7 +73,7 @@ function draftToPayload(draft: CreateSubscriptionPlanDraft): CreateSubscriptionP
|
||||||
description,
|
description,
|
||||||
category: draft.category,
|
category: draft.category,
|
||||||
duration_value,
|
duration_value,
|
||||||
duration_unit: draft.duration_unit,
|
duration_unit,
|
||||||
price,
|
price,
|
||||||
currency: draft.currency,
|
currency: draft.currency,
|
||||||
is_active: draft.is_active,
|
is_active: draft.is_active,
|
||||||
|
|
@ -96,6 +101,8 @@ export function CreateSubscriptionPlanDialog({
|
||||||
}
|
}
|
||||||
}, [open])
|
}, [open])
|
||||||
|
|
||||||
|
const isLifetime = isLifetimePlanCategory(draft.category)
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const payload = draftToPayload(draft)
|
const payload = draftToPayload(draft)
|
||||||
|
|
@ -167,9 +174,19 @@ export function CreateSubscriptionPlanDialog({
|
||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={draft.category}
|
value={draft.category}
|
||||||
onChange={(e) =>
|
onChange={(e) => {
|
||||||
setDraft((d) => ({ ...d, category: e.target.value as SubscriptionPlanCategory }))
|
const category = e.target.value as SubscriptionPlanCategory
|
||||||
}
|
setDraft((d) => ({
|
||||||
|
...d,
|
||||||
|
category,
|
||||||
|
...(isLifetimePlanCategory(category)
|
||||||
|
? {
|
||||||
|
duration_value: String(LIFETIME_DURATION_DEFAULT.duration_value),
|
||||||
|
duration_unit: LIFETIME_DURATION_DEFAULT.duration_unit,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
}))
|
||||||
|
}}
|
||||||
className="rounded-[6px]"
|
className="rounded-[6px]"
|
||||||
>
|
>
|
||||||
{SUBSCRIPTION_PLAN_CATEGORIES.map((opt) => (
|
{SUBSCRIPTION_PLAN_CATEGORIES.map((opt) => (
|
||||||
|
|
@ -180,43 +197,55 @@ export function CreateSubscriptionPlanDialog({
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
{isLifetime ? (
|
||||||
<div className="space-y-1.5">
|
<div className="rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
||||||
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
<p className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
Duration <span className="text-destructive">*</span>
|
Duration
|
||||||
</label>
|
</p>
|
||||||
<Input
|
<p className="mt-1 text-sm font-medium text-grayScale-800">One-time · Never expires</p>
|
||||||
type="number"
|
<p className="mt-0.5 text-xs text-grayScale-500">
|
||||||
min={1}
|
IELTS and Duolingo packages are one-time purchases with lifetime access.
|
||||||
step={1}
|
</p>
|
||||||
value={draft.duration_value}
|
|
||||||
onChange={(e) => setDraft((d) => ({ ...d, duration_value: e.target.value }))}
|
|
||||||
className="rounded-[6px]"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1.5">
|
) : (
|
||||||
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
Duration unit
|
<div className="space-y-1.5">
|
||||||
</label>
|
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
<Select
|
Duration <span className="text-destructive">*</span>
|
||||||
value={draft.duration_unit}
|
</label>
|
||||||
onChange={(e) =>
|
<Input
|
||||||
setDraft((d) => ({
|
type="number"
|
||||||
...d,
|
min={1}
|
||||||
duration_unit: e.target.value as SubscriptionPlanDurationUnit,
|
step={1}
|
||||||
}))
|
value={draft.duration_value}
|
||||||
}
|
onChange={(e) => setDraft((d) => ({ ...d, duration_value: e.target.value }))}
|
||||||
className="rounded-[6px]"
|
className="rounded-[6px]"
|
||||||
>
|
required
|
||||||
{SUBSCRIPTION_DURATION_UNITS.map((opt) => (
|
/>
|
||||||
<option key={opt.value} value={opt.value}>
|
</div>
|
||||||
{opt.label}
|
<div className="space-y-1.5">
|
||||||
</option>
|
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
))}
|
Duration unit
|
||||||
</Select>
|
</label>
|
||||||
|
<Select
|
||||||
|
value={draft.duration_unit}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft((d) => ({
|
||||||
|
...d,
|
||||||
|
duration_unit: e.target.value as SubscriptionPlanDurationUnit,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
className="rounded-[6px]"
|
||||||
|
>
|
||||||
|
{SUBSCRIPTION_DURATION_UNITS.map((opt) => (
|
||||||
|
<option key={opt.value} value={opt.value}>
|
||||||
|
{opt.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,10 @@ import { Select } from "../../../components/ui/select"
|
||||||
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../../components/ui/spinner-icon"
|
||||||
import { Textarea } from "../../../components/ui/textarea"
|
import { Textarea } from "../../../components/ui/textarea"
|
||||||
import { ToggleSwitch } from "../../../components/ui/toggle-switch"
|
import { ToggleSwitch } from "../../../components/ui/toggle-switch"
|
||||||
import { cn } from "../../../lib/utils"
|
|
||||||
import {
|
import {
|
||||||
formatPlanCategory,
|
formatPlanCategory,
|
||||||
|
isLifetimePlanCategory,
|
||||||
|
LIFETIME_DURATION_DEFAULT,
|
||||||
SUBSCRIPTION_CURRENCIES,
|
SUBSCRIPTION_CURRENCIES,
|
||||||
SUBSCRIPTION_DURATION_UNITS,
|
SUBSCRIPTION_DURATION_UNITS,
|
||||||
} from "../../../lib/subscriptionPlans"
|
} from "../../../lib/subscriptionPlans"
|
||||||
|
|
@ -52,11 +53,18 @@ function planToDraft(plan: SubscriptionPlan): EditDraft {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function draftToPayload(draft: EditDraft): UpdateSubscriptionPlanPayload | null {
|
function draftToPayload(
|
||||||
|
draft: EditDraft,
|
||||||
|
category: string,
|
||||||
|
): UpdateSubscriptionPlanPayload | null {
|
||||||
const name = draft.name.trim()
|
const name = draft.name.trim()
|
||||||
const description = draft.description.trim()
|
const description = draft.description.trim()
|
||||||
const duration_value = Number(draft.duration_value)
|
|
||||||
const price = Number(draft.price)
|
const price = Number(draft.price)
|
||||||
|
const isLifetime = isLifetimePlanCategory(category)
|
||||||
|
const duration_value = isLifetime
|
||||||
|
? LIFETIME_DURATION_DEFAULT.duration_value
|
||||||
|
: Number(draft.duration_value)
|
||||||
|
const duration_unit = isLifetime ? LIFETIME_DURATION_DEFAULT.duration_unit : draft.duration_unit
|
||||||
|
|
||||||
if (!name) return null
|
if (!name) return null
|
||||||
if (!description) return null
|
if (!description) return null
|
||||||
|
|
@ -67,7 +75,7 @@ function draftToPayload(draft: EditDraft): UpdateSubscriptionPlanPayload | null
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
duration_value,
|
duration_value,
|
||||||
duration_unit: draft.duration_unit,
|
duration_unit,
|
||||||
price,
|
price,
|
||||||
currency: draft.currency,
|
currency: draft.currency,
|
||||||
is_active: draft.is_active,
|
is_active: draft.is_active,
|
||||||
|
|
@ -112,7 +120,7 @@ export function EditSubscriptionPlanDialog({
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!plan || !draft) return
|
if (!plan || !draft) return
|
||||||
|
|
||||||
const payload = draftToPayload(draft)
|
const payload = draftToPayload(draft, plan.category)
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
toast.error("Please fill in all required fields with valid values.")
|
toast.error("Please fill in all required fields with valid values.")
|
||||||
return
|
return
|
||||||
|
|
@ -187,49 +195,63 @@ export function EditSubscriptionPlanDialog({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
{isLifetimePlanCategory(plan.category) ? (
|
||||||
<div className="space-y-1.5">
|
<div className="rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
||||||
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
<p className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
Duration <span className="text-destructive">*</span>
|
Duration
|
||||||
</label>
|
</p>
|
||||||
<Input
|
<p className="mt-1 text-sm font-medium text-grayScale-800">
|
||||||
type="number"
|
One-time · Never expires
|
||||||
min={1}
|
</p>
|
||||||
step={1}
|
<p className="mt-0.5 text-xs text-grayScale-500">
|
||||||
value={draft.duration_value}
|
IELTS and Duolingo packages are one-time purchases with lifetime access.
|
||||||
onChange={(e) =>
|
</p>
|
||||||
setDraft((d) => d && { ...d, duration_value: e.target.value })
|
|
||||||
}
|
|
||||||
className="rounded-[6px]"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1.5">
|
) : (
|
||||||
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
Duration unit
|
<div className="space-y-1.5">
|
||||||
</label>
|
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
<Select
|
Duration <span className="text-destructive">*</span>
|
||||||
value={draft.duration_unit}
|
</label>
|
||||||
onChange={(e) =>
|
<Input
|
||||||
setDraft((d) =>
|
type="number"
|
||||||
d
|
min={1}
|
||||||
? {
|
step={1}
|
||||||
...d,
|
value={draft.duration_value}
|
||||||
duration_unit: e.target.value as SubscriptionPlanDurationUnit,
|
onChange={(e) =>
|
||||||
}
|
setDraft((d) => d && { ...d, duration_value: e.target.value })
|
||||||
: d,
|
}
|
||||||
)
|
className="rounded-[6px]"
|
||||||
}
|
required
|
||||||
className="rounded-[6px]"
|
/>
|
||||||
>
|
</div>
|
||||||
{SUBSCRIPTION_DURATION_UNITS.map((opt) => (
|
<div className="space-y-1.5">
|
||||||
<option key={opt.value} value={opt.value}>
|
<label className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
{opt.label}
|
Duration unit
|
||||||
</option>
|
</label>
|
||||||
))}
|
<Select
|
||||||
</Select>
|
value={draft.duration_unit}
|
||||||
|
onChange={(e) =>
|
||||||
|
setDraft((d) =>
|
||||||
|
d
|
||||||
|
? {
|
||||||
|
...d,
|
||||||
|
duration_unit: e.target.value as SubscriptionPlanDurationUnit,
|
||||||
|
}
|
||||||
|
: d,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
className="rounded-[6px]"
|
||||||
|
>
|
||||||
|
{SUBSCRIPTION_DURATION_UNITS.map((opt) => (
|
||||||
|
<option key={opt.value} value={opt.value}>
|
||||||
|
{opt.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import {
|
||||||
isLearnerRole,
|
isLearnerRole,
|
||||||
SUBSCRIPTION_ADMIN_PERMISSIONS,
|
SUBSCRIPTION_ADMIN_PERMISSIONS,
|
||||||
} from "../../../lib/subscriptionAdminPermissions"
|
} from "../../../lib/subscriptionAdminPermissions"
|
||||||
import { formatPlanCategory } from "../../../lib/subscriptionPlans"
|
import { formatPlanCategory, isLifetimeExpiry, isLifetimePlanCategory } from "../../../lib/subscriptionPlans"
|
||||||
import { cn } from "../../../lib/utils"
|
import { cn } from "../../../lib/utils"
|
||||||
import type { UserSubscriptionRecord, UserSubscriptionsData } from "../../../types/userAdmin.types"
|
import type { UserSubscriptionRecord, UserSubscriptionsData } from "../../../types/userAdmin.types"
|
||||||
import { CancelSubscriptionDialog } from "./CancelSubscriptionDialog"
|
import { CancelSubscriptionDialog } from "./CancelSubscriptionDialog"
|
||||||
|
|
@ -29,6 +29,7 @@ import { GrantSubscriptionDialog } from "./GrantSubscriptionDialog"
|
||||||
function formatPlanTitle(subscription: UserSubscriptionRecord): string {
|
function formatPlanTitle(subscription: UserSubscriptionRecord): string {
|
||||||
const name = subscription.plan_name?.trim()
|
const name = subscription.plan_name?.trim()
|
||||||
if (name) return name
|
if (name) return name
|
||||||
|
if (isLifetimePlanCategory(subscription.plan_category)) return "One-time"
|
||||||
if (subscription.duration_value && subscription.duration_unit) {
|
if (subscription.duration_value && subscription.duration_unit) {
|
||||||
const unit = subscription.duration_unit.toLowerCase().replace(/s$/, "")
|
const unit = subscription.duration_unit.toLowerCase().replace(/s$/, "")
|
||||||
const plural = subscription.duration_value === 1 ? unit : `${unit}s`
|
const plural = subscription.duration_value === 1 ? unit : `${unit}s`
|
||||||
|
|
@ -37,7 +38,8 @@ function formatPlanTitle(subscription: UserSubscriptionRecord): string {
|
||||||
return NOT_ASSIGNED_LABEL
|
return NOT_ASSIGNED_LABEL
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatExpiryDate(value?: string | null): string {
|
function formatExpiryDate(value?: string | null, category?: string | null): string {
|
||||||
|
if (isLifetimePlanCategory(category) || isLifetimeExpiry(value)) return "Never expires"
|
||||||
if (!value?.trim()) return NOT_ASSIGNED_LABEL
|
if (!value?.trim()) return NOT_ASSIGNED_LABEL
|
||||||
const parsed = new Date(value)
|
const parsed = new Date(value)
|
||||||
if (Number.isNaN(parsed.getTime())) return NOT_ASSIGNED_LABEL
|
if (Number.isNaN(parsed.getTime())) return NOT_ASSIGNED_LABEL
|
||||||
|
|
@ -61,7 +63,8 @@ function formatDateTime(value?: string | null): string {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDaysLeft(expiresAt?: string | null): number | null {
|
function getDaysLeft(expiresAt?: string | null, category?: string | null): number | null {
|
||||||
|
if (isLifetimePlanCategory(category) || isLifetimeExpiry(expiresAt)) return null
|
||||||
if (!expiresAt?.trim()) return null
|
if (!expiresAt?.trim()) return null
|
||||||
const expires = new Date(expiresAt)
|
const expires = new Date(expiresAt)
|
||||||
if (Number.isNaN(expires.getTime())) return null
|
if (Number.isNaN(expires.getTime())) return null
|
||||||
|
|
@ -69,6 +72,10 @@ function getDaysLeft(expiresAt?: string | null): number | null {
|
||||||
return Math.ceil(ms / 86_400_000)
|
return Math.ceil(ms / 86_400_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canExtendSubscription(subscription: UserSubscriptionRecord): boolean {
|
||||||
|
return !isLifetimePlanCategory(subscription.plan_category) && !isLifetimeExpiry(subscription.expires_at)
|
||||||
|
}
|
||||||
|
|
||||||
function formatDaysLeftLabel(daysLeft: number): string {
|
function formatDaysLeftLabel(daysLeft: number): string {
|
||||||
if (daysLeft <= 0) return "Expired"
|
if (daysLeft <= 0) return "Expired"
|
||||||
if (daysLeft === 1) return "1 day left"
|
if (daysLeft === 1) return "1 day left"
|
||||||
|
|
@ -138,11 +145,12 @@ function SubscriptionManageCard({
|
||||||
onGrant: () => void
|
onGrant: () => void
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
}) {
|
}) {
|
||||||
const daysLeft = getDaysLeft(subscription.expires_at)
|
const daysLeft = getDaysLeft(subscription.expires_at, subscription.plan_category)
|
||||||
const statusUpper = subscription.status.toUpperCase()
|
const statusUpper = subscription.status.toUpperCase()
|
||||||
const isActive = subscription.is_currently_active || statusUpper === "ACTIVE"
|
const isActive = subscription.is_currently_active || statusUpper === "ACTIVE"
|
||||||
const statusTone = isActive ? "active" : statusUpper === "PENDING" ? "pending" : "inactive"
|
const statusTone = isActive ? "active" : statusUpper === "PENDING" ? "pending" : "inactive"
|
||||||
const extendEnabled = canExtend && hasActiveSubscription && isActive
|
const isLifetime = !canExtendSubscription(subscription)
|
||||||
|
const extendEnabled = canExtend && hasActiveSubscription && isActive && !isLifetime
|
||||||
const cancelEnabled = canCancel && hasActiveSubscription && isActive && statusUpper !== "CANCELLED"
|
const cancelEnabled = canCancel && hasActiveSubscription && isActive && statusUpper !== "CANCELLED"
|
||||||
const markAsPaidEnabled = canGrant && !hasActiveSubscription
|
const markAsPaidEnabled = canGrant && !hasActiveSubscription
|
||||||
|
|
||||||
|
|
@ -168,7 +176,7 @@ function SubscriptionManageCard({
|
||||||
<p className="text-xs font-medium text-grayScale-400">Expires On</p>
|
<p className="text-xs font-medium text-grayScale-400">Expires On</p>
|
||||||
<div className="mt-1 flex flex-wrap items-center gap-2">
|
<div className="mt-1 flex flex-wrap items-center gap-2">
|
||||||
<p className="text-lg font-bold tracking-tight text-grayScale-900">
|
<p className="text-lg font-bold tracking-tight text-grayScale-900">
|
||||||
{formatExpiryDate(subscription.expires_at)}
|
{formatExpiryDate(subscription.expires_at, subscription.plan_category)}
|
||||||
</p>
|
</p>
|
||||||
{daysLeft != null ? (
|
{daysLeft != null ? (
|
||||||
<span
|
<span
|
||||||
|
|
@ -190,7 +198,7 @@ function SubscriptionManageCard({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-6 flex flex-col gap-2">
|
<div className="mt-6 flex flex-col gap-2">
|
||||||
{canExtend ? (
|
{canExtend && !isLifetime ? (
|
||||||
<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"
|
||||||
|
|
@ -469,7 +477,7 @@ export function UserSubscriptionsSection({
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-grayScale-500">
|
<p className="text-xs text-grayScale-500">
|
||||||
{formatPlanCategory(subscription.plan_category)} ·{" "}
|
{formatPlanCategory(subscription.plan_category)} ·{" "}
|
||||||
{formatExpiryDate(subscription.expires_at)}
|
{formatExpiryDate(subscription.expires_at, subscription.plan_category)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
|
@ -481,7 +489,7 @@ export function UserSubscriptionsSection({
|
||||||
: "inactive"
|
: "inactive"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{canExtend ? (
|
{canExtend && canExtendSubscription(subscription) ? (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user