mirror of
https://github.com/vernu/textbee.git
synced 2026-09-03 03:29:58 +03:00
@@ -363,6 +363,7 @@ export class BillingService {
|
||||
const plans = await this.planModel.find()
|
||||
|
||||
const customPlans = plans.filter((plan) => plan.name?.startsWith('custom'))
|
||||
const scalePlan = plans.find((plan) => plan.name === 'scale')
|
||||
const proPlan = plans.find((plan) => plan.name === 'pro')
|
||||
const freePlan = plans.find((plan) => plan.name === 'free')
|
||||
|
||||
@@ -376,6 +377,18 @@ export class BillingService {
|
||||
return customPlanSubscription.populate('plan')
|
||||
}
|
||||
|
||||
if (scalePlan) {
|
||||
const scalePlanSubscription = await this.subscriptionModel.findOne({
|
||||
user: user._id,
|
||||
plan: scalePlan._id,
|
||||
isActive: true,
|
||||
})
|
||||
|
||||
if (scalePlanSubscription) {
|
||||
return scalePlanSubscription.populate('plan')
|
||||
}
|
||||
}
|
||||
|
||||
const proPlanSubscription = await this.subscriptionModel.findOne({
|
||||
user: user._id,
|
||||
plan: proPlan._id,
|
||||
|
||||
@@ -438,15 +438,30 @@ export default function AccountSettings() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='mt-4 flex justify-end gap-2'>
|
||||
{!currentSubscription?.plan?.name ||
|
||||
currentSubscription?.plan?.name?.toLowerCase() === 'free' ? (
|
||||
<div className='mt-4 flex justify-end gap-2 flex-wrap'>
|
||||
{(!currentSubscription?.plan?.name ||
|
||||
currentSubscription?.plan?.name?.toLowerCase() === 'free') ? (
|
||||
<Link
|
||||
href='/checkout/pro'
|
||||
className='text-xs font-medium text-white bg-brand-600 hover:bg-brand-700 px-3 py-1.5 rounded-md transition-colors'
|
||||
>
|
||||
Upgrade to Pro →
|
||||
</Link>
|
||||
) : currentSubscription?.plan?.name?.toLowerCase() === 'pro' ? (
|
||||
<>
|
||||
<Link
|
||||
href='/checkout/scale'
|
||||
className='text-xs font-medium text-white bg-teal-600 hover:bg-teal-700 px-3 py-1.5 rounded-md transition-colors'
|
||||
>
|
||||
Upgrade to Scale →
|
||||
</Link>
|
||||
<Link
|
||||
href={polarCustomerPortalRequestUrl(currentUser?.email)}
|
||||
className='text-xs font-medium bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 px-3 py-1.5 rounded-md transition-colors'
|
||||
>
|
||||
Manage Subscription →
|
||||
</Link>
|
||||
</>
|
||||
) : (
|
||||
<Link
|
||||
href={polarCustomerPortalRequestUrl(currentUser?.email)}
|
||||
|
||||
@@ -252,15 +252,30 @@ export default function SubscriptionInfo() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-end'>
|
||||
{!currentSubscription?.plan?.name ||
|
||||
currentSubscription?.plan?.name?.toLowerCase() === 'free' ? (
|
||||
<div className='flex justify-end gap-2 flex-wrap'>
|
||||
{(!currentSubscription?.plan?.name ||
|
||||
currentSubscription?.plan?.name?.toLowerCase() === 'free') ? (
|
||||
<Link
|
||||
href='/checkout/pro'
|
||||
className='text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 px-4 py-2 rounded-md transition-colors'
|
||||
>
|
||||
Upgrade to Pro →
|
||||
</Link>
|
||||
) : currentSubscription?.plan?.name?.toLowerCase() === 'pro' ? (
|
||||
<>
|
||||
<Link
|
||||
href='/checkout/scale'
|
||||
className='text-sm font-medium text-white bg-teal-600 hover:bg-teal-700 px-4 py-2 rounded-md transition-colors'
|
||||
>
|
||||
Upgrade to Scale →
|
||||
</Link>
|
||||
<Link
|
||||
href={polarCustomerPortalRequestUrl(currentUser?.email)}
|
||||
className='text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 px-4 py-2 rounded-md transition-colors'
|
||||
>
|
||||
Manage Subscription →
|
||||
</Link>
|
||||
</>
|
||||
) : (
|
||||
<Link
|
||||
href={polarCustomerPortalRequestUrl(currentUser?.email)}
|
||||
|
||||
@@ -110,14 +110,70 @@ export default function UpgradeToProAlert() {
|
||||
}
|
||||
}, [monthlyUsagePercentage, monthlyLimit, processedSmsLastMonth])
|
||||
|
||||
const planName = currentSubscription?.plan?.name
|
||||
|
||||
if (isLoadingSubscription || !currentSubscription || subscriptionError) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (currentSubscription?.plan?.name !== 'free') {
|
||||
if (planName === 'scale' || planName?.startsWith('custom')) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (planName === 'pro') {
|
||||
if (monthlyUsagePercentage < 80) return null
|
||||
|
||||
const scaleAlertConfig =
|
||||
monthlyUsagePercentage >= 100
|
||||
? {
|
||||
bgColor: 'bg-gradient-to-r from-red-600 to-red-800',
|
||||
message: '⚠️ Monthly limit exceeded! Upgrade to Scale for 25,000 SMS/mo.',
|
||||
subMessage: `You've used ${processedSmsLastMonth} of ${monthlyLimit} SMS this month.`,
|
||||
buttonText: 'Upgrade to Scale!',
|
||||
buttonColor: 'bg-white text-red-600 hover:bg-red-50 hover:text-red-700 border-red-600',
|
||||
}
|
||||
: {
|
||||
bgColor: 'bg-gradient-to-r from-orange-500 to-red-500',
|
||||
message: '⚠️ Approaching Pro limit! Scale up to 25,000 SMS/mo.',
|
||||
subMessage: `You've used ${monthlyUsagePercentage}% of your monthly SMS limit (${processedSmsLastMonth}/${monthlyLimit}).`,
|
||||
buttonText: 'Upgrade to Scale',
|
||||
buttonColor: 'bg-white text-orange-600 hover:bg-orange-50 hover:text-orange-700 border-orange-600',
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert className={`${scaleAlertConfig.bgColor} text-white`}>
|
||||
<AlertDescription className='flex flex-col sm:flex-row flex-wrap items-center gap-2 md:gap-4'>
|
||||
<span className='w-full sm:flex-1 text-center sm:text-left text-sm md:text-base font-medium'>
|
||||
{scaleAlertConfig.message}
|
||||
</span>
|
||||
<span className='w-full sm:flex-1 text-center sm:text-left text-xs md:text-sm'>
|
||||
{scaleAlertConfig.subMessage}
|
||||
</span>
|
||||
<div className='w-full sm:w-auto mt-2 sm:mt-0 flex justify-center sm:justify-end flex-wrap gap-1 md:gap-2'>
|
||||
<Button
|
||||
variant='outline'
|
||||
size='sm'
|
||||
asChild
|
||||
className={`${scaleAlertConfig.buttonColor} text-xs md:text-sm`}
|
||||
>
|
||||
<Link href={'/checkout/scale'}>
|
||||
{scaleAlertConfig.buttonText}
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
variant='outline'
|
||||
size='sm'
|
||||
asChild
|
||||
className='bg-orange-500 text-white hover:bg-orange-600 text-xs md:text-sm'
|
||||
>
|
||||
<Link href={'/#pricing'}>Learn More</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert className={`${alertConfig.bgColor} text-white`}>
|
||||
<AlertDescription className='flex flex-col sm:flex-row flex-wrap items-center gap-2 md:gap-4'>
|
||||
|
||||
Reference in New Issue
Block a user