// UnitUpsellModal — shown when a learner clicks a locked standalone Unit. // Unlocks two ways: the unit's own subscription tier (with an optional direct // "Buy" listing, same PayPal flow as Courses) and/or any course it's attached // to (a unit may sit under several courses at different tiers — no single // "Buy" in that case, just links to view/buy the course itself). // Shared by UnitsList, UnitDetails, and Dashboard. import { useNavigate } from "react-router-dom"; import { LockIcon, BookOpen, ShoppingCart } from "lucide-react"; import ResponsiveModal from "@/components/generic/ResponsiveModal"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { useDateFormat } from "@/hooks/useDateFormat"; import { resolveTierBadge } from "@/utils/tierBadge.util"; export default function UnitUpsellModal({ open, onOpenChange, unit, tierMap = {} }) { const navigate = useNavigate(); const { fmtCurrency } = useDateFormat(); const courses = unit?.courses ?? []; const ownTier = unit?.subscription ? resolveTierBadge(unit.subscription, tierMap) : null; const canBuy = unit?.product?.is_active && !unit?.has_purchased; return ( {canBuy && ( )} } >
{ownTier && (

Requires

{ownTier.label}
)} {courses.length === 0 && !ownTier ? (

Upgrade your plan to access this content.

) : ( courses.map((course) => { const { label, cls } = resolveTierBadge(course.subscription, tierMap); return (

{course.title}

{label}
); }) )}
); }