Make one-time lifetime access a per-plan option in admin.
Add an is_lifetime toggle for all subscription categories and stop hardcoding IELTS/Duolingo as lifetime-only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
31b1ea5a81
commit
c323df9f47
|
|
@ -25,6 +25,7 @@ function normalizeSubscriptionPlan(raw: unknown): SubscriptionPlan | null {
|
||||||
duration_unit: String(raw.duration_unit ?? "MONTH"),
|
duration_unit: String(raw.duration_unit ?? "MONTH"),
|
||||||
price: Number(raw.price ?? 0),
|
price: Number(raw.price ?? 0),
|
||||||
currency: String(raw.currency ?? "ETB"),
|
currency: String(raw.currency ?? "ETB"),
|
||||||
|
is_lifetime: Boolean(raw.is_lifetime ?? false),
|
||||||
is_active: Boolean(raw.is_active ?? true),
|
is_active: Boolean(raw.is_active ?? true),
|
||||||
created_at: String(raw.created_at ?? ""),
|
created_at: String(raw.created_at ?? ""),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -322,6 +322,7 @@ function normalizeUserSubscriptionRecord(raw: unknown): UserSubscriptionRecord |
|
||||||
plan_id: planId,
|
plan_id: planId,
|
||||||
plan_name: String(raw.plan_name ?? ""),
|
plan_name: String(raw.plan_name ?? ""),
|
||||||
plan_category: String(raw.plan_category ?? ""),
|
plan_category: String(raw.plan_category ?? ""),
|
||||||
|
is_lifetime: raw.is_lifetime === true,
|
||||||
starts_at: String(raw.starts_at ?? ""),
|
starts_at: String(raw.starts_at ?? ""),
|
||||||
expires_at: String(raw.expires_at ?? ""),
|
expires_at: String(raw.expires_at ?? ""),
|
||||||
status: String(raw.status ?? ""),
|
status: String(raw.status ?? ""),
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,16 @@ 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 = {
|
export const LIFETIME_DURATION_DEFAULT = {
|
||||||
duration_value: 1,
|
duration_value: 1,
|
||||||
duration_unit: "YEAR" as SubscriptionPlanDurationUnit,
|
duration_unit: "YEAR" as SubscriptionPlanDurationUnit,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLifetimePlanCategory(category: string | null | undefined): boolean {
|
/** True when a plan is configured as one-time (never expires). */
|
||||||
if (!category) return false
|
export function isLifetimePlan(
|
||||||
const normalized = category.trim().toUpperCase()
|
plan: Pick<SubscriptionPlan, "is_lifetime"> | { is_lifetime?: boolean | null } | null | undefined,
|
||||||
return LIFETIME_SUBSCRIPTION_CATEGORIES.includes(normalized as SubscriptionPlanCategory)
|
): boolean {
|
||||||
|
return plan?.is_lifetime === true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** True when expires_at is the far-future lifetime sentinel (year >= 9000). */
|
/** True when expires_at is the far-future lifetime sentinel (year >= 9000). */
|
||||||
|
|
@ -48,9 +47,12 @@ export const SUBSCRIPTION_DURATION_UNITS: {
|
||||||
export const SUBSCRIPTION_CURRENCIES = ["ETB", "USD"] as const
|
export const SUBSCRIPTION_CURRENCIES = ["ETB", "USD"] as const
|
||||||
|
|
||||||
export function formatPlanDuration(
|
export function formatPlanDuration(
|
||||||
plan: Pick<SubscriptionPlan, "duration_value" | "duration_unit"> & { category?: string },
|
plan: Pick<SubscriptionPlan, "duration_value" | "duration_unit"> & {
|
||||||
|
category?: string
|
||||||
|
is_lifetime?: boolean
|
||||||
|
},
|
||||||
): string {
|
): string {
|
||||||
if (plan.category && isLifetimePlanCategory(plan.category)) return "One-time"
|
if (isLifetimePlan(plan)) 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 =
|
||||||
|
|
@ -96,6 +98,7 @@ export function planToUpdatePayload(
|
||||||
duration_unit: plan.duration_unit,
|
duration_unit: plan.duration_unit,
|
||||||
price: plan.price,
|
price: plan.price,
|
||||||
currency: plan.currency,
|
currency: plan.currency,
|
||||||
|
is_lifetime: plan.is_lifetime,
|
||||||
is_active: plan.is_active,
|
is_active: plan.is_active,
|
||||||
...overrides,
|
...overrides,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ 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 {
|
import {
|
||||||
isLifetimePlanCategory,
|
|
||||||
LIFETIME_DURATION_DEFAULT,
|
LIFETIME_DURATION_DEFAULT,
|
||||||
SUBSCRIPTION_CURRENCIES,
|
SUBSCRIPTION_CURRENCIES,
|
||||||
SUBSCRIPTION_DURATION_UNITS,
|
SUBSCRIPTION_DURATION_UNITS,
|
||||||
|
|
@ -39,6 +38,7 @@ export interface CreateSubscriptionPlanDraft {
|
||||||
duration_unit: SubscriptionPlanDurationUnit
|
duration_unit: SubscriptionPlanDurationUnit
|
||||||
price: string
|
price: string
|
||||||
currency: string
|
currency: string
|
||||||
|
is_lifetime: boolean
|
||||||
is_active: boolean
|
is_active: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,6 +50,7 @@ export const EMPTY_SUBSCRIPTION_PLAN_DRAFT: CreateSubscriptionPlanDraft = {
|
||||||
duration_unit: "MONTH",
|
duration_unit: "MONTH",
|
||||||
price: "",
|
price: "",
|
||||||
currency: "ETB",
|
currency: "ETB",
|
||||||
|
is_lifetime: false,
|
||||||
is_active: true,
|
is_active: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,11 +58,12 @@ function draftToPayload(draft: CreateSubscriptionPlanDraft): CreateSubscriptionP
|
||||||
const name = draft.name.trim()
|
const name = draft.name.trim()
|
||||||
const description = draft.description.trim()
|
const description = draft.description.trim()
|
||||||
const price = Number(draft.price)
|
const price = Number(draft.price)
|
||||||
const isLifetime = isLifetimePlanCategory(draft.category)
|
const duration_value = draft.is_lifetime
|
||||||
const duration_value = isLifetime
|
|
||||||
? LIFETIME_DURATION_DEFAULT.duration_value
|
? LIFETIME_DURATION_DEFAULT.duration_value
|
||||||
: Number(draft.duration_value)
|
: Number(draft.duration_value)
|
||||||
const duration_unit = isLifetime ? LIFETIME_DURATION_DEFAULT.duration_unit : draft.duration_unit
|
const duration_unit = draft.is_lifetime
|
||||||
|
? LIFETIME_DURATION_DEFAULT.duration_unit
|
||||||
|
: draft.duration_unit
|
||||||
|
|
||||||
if (!name) return null
|
if (!name) return null
|
||||||
if (!description) return null
|
if (!description) return null
|
||||||
|
|
@ -76,6 +78,7 @@ function draftToPayload(draft: CreateSubscriptionPlanDraft): CreateSubscriptionP
|
||||||
duration_unit,
|
duration_unit,
|
||||||
price,
|
price,
|
||||||
currency: draft.currency,
|
currency: draft.currency,
|
||||||
|
is_lifetime: draft.is_lifetime,
|
||||||
is_active: draft.is_active,
|
is_active: draft.is_active,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,8 +104,6 @@ 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)
|
||||||
|
|
@ -174,19 +175,12 @@ export function CreateSubscriptionPlanDialog({
|
||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={draft.category}
|
value={draft.category}
|
||||||
onChange={(e) => {
|
onChange={(e) =>
|
||||||
const category = e.target.value as SubscriptionPlanCategory
|
|
||||||
setDraft((d) => ({
|
setDraft((d) => ({
|
||||||
...d,
|
...d,
|
||||||
category,
|
category: e.target.value as SubscriptionPlanCategory,
|
||||||
...(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) => (
|
||||||
|
|
@ -197,14 +191,40 @@ export function CreateSubscriptionPlanDialog({
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isLifetime ? (
|
<label className="flex cursor-pointer items-center justify-between gap-4 rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-grayScale-800">One-time purchase</p>
|
||||||
|
<p className="text-xs text-grayScale-500">
|
||||||
|
Lifetime access with no expiration date
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ToggleSwitch
|
||||||
|
variant="plain"
|
||||||
|
checked={draft.is_lifetime}
|
||||||
|
aria-label="One-time purchase"
|
||||||
|
onCheckedChange={() =>
|
||||||
|
setDraft((d) => ({
|
||||||
|
...d,
|
||||||
|
is_lifetime: !d.is_lifetime,
|
||||||
|
...(d.is_lifetime
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
|
duration_value: String(LIFETIME_DURATION_DEFAULT.duration_value),
|
||||||
|
duration_unit: LIFETIME_DURATION_DEFAULT.duration_unit,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{draft.is_lifetime ? (
|
||||||
<div className="rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
<div className="rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
||||||
<p className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
<p className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
Duration
|
Duration
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-1 text-sm font-medium text-grayScale-800">One-time · Never expires</p>
|
<p className="mt-1 text-sm font-medium text-grayScale-800">One-time · Never expires</p>
|
||||||
<p className="mt-0.5 text-xs text-grayScale-500">
|
<p className="mt-0.5 text-xs text-grayScale-500">
|
||||||
IELTS and Duolingo packages are one-time purchases with lifetime access.
|
Related subscriptions stay active permanently after purchase.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import { Textarea } from "../../../components/ui/textarea"
|
||||||
import { ToggleSwitch } from "../../../components/ui/toggle-switch"
|
import { ToggleSwitch } from "../../../components/ui/toggle-switch"
|
||||||
import {
|
import {
|
||||||
formatPlanCategory,
|
formatPlanCategory,
|
||||||
isLifetimePlanCategory,
|
|
||||||
LIFETIME_DURATION_DEFAULT,
|
LIFETIME_DURATION_DEFAULT,
|
||||||
SUBSCRIPTION_CURRENCIES,
|
SUBSCRIPTION_CURRENCIES,
|
||||||
SUBSCRIPTION_DURATION_UNITS,
|
SUBSCRIPTION_DURATION_UNITS,
|
||||||
|
|
@ -38,6 +37,7 @@ interface EditDraft {
|
||||||
duration_unit: SubscriptionPlanDurationUnit
|
duration_unit: SubscriptionPlanDurationUnit
|
||||||
price: string
|
price: string
|
||||||
currency: string
|
currency: string
|
||||||
|
is_lifetime: boolean
|
||||||
is_active: boolean
|
is_active: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,22 +49,21 @@ function planToDraft(plan: SubscriptionPlan): EditDraft {
|
||||||
duration_unit: plan.duration_unit,
|
duration_unit: plan.duration_unit,
|
||||||
price: String(plan.price),
|
price: String(plan.price),
|
||||||
currency: plan.currency,
|
currency: plan.currency,
|
||||||
|
is_lifetime: Boolean(plan.is_lifetime),
|
||||||
is_active: plan.is_active,
|
is_active: plan.is_active,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function draftToPayload(
|
function draftToPayload(draft: EditDraft): UpdateSubscriptionPlanPayload | null {
|
||||||
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 price = Number(draft.price)
|
const price = Number(draft.price)
|
||||||
const isLifetime = isLifetimePlanCategory(category)
|
const duration_value = draft.is_lifetime
|
||||||
const duration_value = isLifetime
|
|
||||||
? LIFETIME_DURATION_DEFAULT.duration_value
|
? LIFETIME_DURATION_DEFAULT.duration_value
|
||||||
: Number(draft.duration_value)
|
: Number(draft.duration_value)
|
||||||
const duration_unit = isLifetime ? LIFETIME_DURATION_DEFAULT.duration_unit : draft.duration_unit
|
const duration_unit = draft.is_lifetime
|
||||||
|
? LIFETIME_DURATION_DEFAULT.duration_unit
|
||||||
|
: draft.duration_unit
|
||||||
|
|
||||||
if (!name) return null
|
if (!name) return null
|
||||||
if (!description) return null
|
if (!description) return null
|
||||||
|
|
@ -78,6 +77,7 @@ function draftToPayload(
|
||||||
duration_unit,
|
duration_unit,
|
||||||
price,
|
price,
|
||||||
currency: draft.currency,
|
currency: draft.currency,
|
||||||
|
is_lifetime: draft.is_lifetime,
|
||||||
is_active: draft.is_active,
|
is_active: draft.is_active,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +120,7 @@ export function EditSubscriptionPlanDialog({
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!plan || !draft) return
|
if (!plan || !draft) return
|
||||||
|
|
||||||
const payload = draftToPayload(draft, plan.category)
|
const payload = draftToPayload(draft)
|
||||||
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
|
||||||
|
|
@ -195,7 +195,37 @@ export function EditSubscriptionPlanDialog({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isLifetimePlanCategory(plan.category) ? (
|
<label className="flex cursor-pointer items-center justify-between gap-4 rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-grayScale-800">One-time purchase</p>
|
||||||
|
<p className="text-xs text-grayScale-500">
|
||||||
|
Lifetime access with no expiration date
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ToggleSwitch
|
||||||
|
variant="plain"
|
||||||
|
checked={draft.is_lifetime}
|
||||||
|
aria-label="One-time purchase"
|
||||||
|
onCheckedChange={() =>
|
||||||
|
setDraft((d) =>
|
||||||
|
d
|
||||||
|
? {
|
||||||
|
...d,
|
||||||
|
is_lifetime: !d.is_lifetime,
|
||||||
|
...(!d.is_lifetime
|
||||||
|
? {
|
||||||
|
duration_value: String(LIFETIME_DURATION_DEFAULT.duration_value),
|
||||||
|
duration_unit: LIFETIME_DURATION_DEFAULT.duration_unit,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
}
|
||||||
|
: d,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{draft.is_lifetime ? (
|
||||||
<div className="rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
<div className="rounded-[8px] border border-grayScale-100 bg-grayScale-50/50 px-4 py-3">
|
||||||
<p className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
<p className="text-[11px] font-bold uppercase tracking-wider text-grayScale-400">
|
||||||
Duration
|
Duration
|
||||||
|
|
@ -204,7 +234,7 @@ export function EditSubscriptionPlanDialog({
|
||||||
One-time · Never expires
|
One-time · Never expires
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-0.5 text-xs text-grayScale-500">
|
<p className="mt-0.5 text-xs text-grayScale-500">
|
||||||
IELTS and Duolingo packages are one-time purchases with lifetime access.
|
Related active subscriptions are kept non-expiring when this is enabled.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,21 @@ import {
|
||||||
isLearnerRole,
|
isLearnerRole,
|
||||||
SUBSCRIPTION_ADMIN_PERMISSIONS,
|
SUBSCRIPTION_ADMIN_PERMISSIONS,
|
||||||
} from "../../../lib/subscriptionAdminPermissions"
|
} from "../../../lib/subscriptionAdminPermissions"
|
||||||
import { formatPlanCategory, isLifetimeExpiry, isLifetimePlanCategory } from "../../../lib/subscriptionPlans"
|
import { formatPlanCategory, isLifetimeExpiry } 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"
|
||||||
import { ExtendSubscriptionDialog } from "./ExtendSubscriptionDialog"
|
import { ExtendSubscriptionDialog } from "./ExtendSubscriptionDialog"
|
||||||
import { GrantSubscriptionDialog } from "./GrantSubscriptionDialog"
|
import { GrantSubscriptionDialog } from "./GrantSubscriptionDialog"
|
||||||
|
|
||||||
|
function isLifetimeSubscription(subscription: UserSubscriptionRecord): boolean {
|
||||||
|
return subscription.is_lifetime === true || isLifetimeExpiry(subscription.expires_at)
|
||||||
|
}
|
||||||
|
|
||||||
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 (isLifetimeSubscription(subscription)) 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`
|
||||||
|
|
@ -38,8 +42,9 @@ function formatPlanTitle(subscription: UserSubscriptionRecord): string {
|
||||||
return NOT_ASSIGNED_LABEL
|
return NOT_ASSIGNED_LABEL
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatExpiryDate(value?: string | null, category?: string | null): string {
|
function formatExpiryDate(subscription: UserSubscriptionRecord): string {
|
||||||
if (isLifetimePlanCategory(category) || isLifetimeExpiry(value)) return "Never expires"
|
if (isLifetimeSubscription(subscription)) return "Never expires"
|
||||||
|
const value = subscription.expires_at
|
||||||
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
|
||||||
|
|
@ -63,8 +68,9 @@ function formatDateTime(value?: string | null): string {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDaysLeft(expiresAt?: string | null, category?: string | null): number | null {
|
function getDaysLeft(subscription: UserSubscriptionRecord): number | null {
|
||||||
if (isLifetimePlanCategory(category) || isLifetimeExpiry(expiresAt)) return null
|
if (isLifetimeSubscription(subscription)) return null
|
||||||
|
const expiresAt = subscription.expires_at
|
||||||
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
|
||||||
|
|
@ -73,7 +79,7 @@ function getDaysLeft(expiresAt?: string | null, category?: string | null): numbe
|
||||||
}
|
}
|
||||||
|
|
||||||
function canExtendSubscription(subscription: UserSubscriptionRecord): boolean {
|
function canExtendSubscription(subscription: UserSubscriptionRecord): boolean {
|
||||||
return !isLifetimePlanCategory(subscription.plan_category) && !isLifetimeExpiry(subscription.expires_at)
|
return !isLifetimeSubscription(subscription)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDaysLeftLabel(daysLeft: number): string {
|
function formatDaysLeftLabel(daysLeft: number): string {
|
||||||
|
|
@ -145,7 +151,7 @@ function SubscriptionManageCard({
|
||||||
onGrant: () => void
|
onGrant: () => void
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
}) {
|
}) {
|
||||||
const daysLeft = getDaysLeft(subscription.expires_at, subscription.plan_category)
|
const daysLeft = getDaysLeft(subscription)
|
||||||
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"
|
||||||
|
|
@ -176,7 +182,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, subscription.plan_category)}
|
{formatExpiryDate(subscription)}
|
||||||
</p>
|
</p>
|
||||||
{daysLeft != null ? (
|
{daysLeft != null ? (
|
||||||
<span
|
<span
|
||||||
|
|
@ -477,7 +483,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, subscription.plan_category)}
|
{formatExpiryDate(subscription)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export interface SubscriptionPlan {
|
||||||
duration_unit: SubscriptionPlanDurationUnit
|
duration_unit: SubscriptionPlanDurationUnit
|
||||||
price: number
|
price: number
|
||||||
currency: string
|
currency: string
|
||||||
|
is_lifetime: boolean
|
||||||
is_active: boolean
|
is_active: boolean
|
||||||
created_at: string
|
created_at: string
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +24,7 @@ export interface CreateSubscriptionPlanPayload {
|
||||||
duration_unit: SubscriptionPlanDurationUnit
|
duration_unit: SubscriptionPlanDurationUnit
|
||||||
price: number
|
price: number
|
||||||
currency: string
|
currency: string
|
||||||
|
is_lifetime: boolean
|
||||||
is_active: boolean
|
is_active: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,6 +35,7 @@ export interface UpdateSubscriptionPlanPayload {
|
||||||
duration_unit: SubscriptionPlanDurationUnit
|
duration_unit: SubscriptionPlanDurationUnit
|
||||||
price: number
|
price: number
|
||||||
currency: string
|
currency: string
|
||||||
|
is_lifetime: boolean
|
||||||
is_active: boolean
|
is_active: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ export interface UserSubscriptionRecord {
|
||||||
plan_id: number
|
plan_id: number
|
||||||
plan_name: string
|
plan_name: string
|
||||||
plan_category: string
|
plan_category: string
|
||||||
|
is_lifetime: boolean
|
||||||
starts_at: string
|
starts_at: string
|
||||||
expires_at: string
|
expires_at: string
|
||||||
status: string
|
status: string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user