feat: routines module; super admin subscription badge, 7-day trial and lifetime plan

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-06 19:54:38 +03:30
co-authored by Cursor
parent 3de2d0fa67
commit b3784818fc
58 changed files with 13018 additions and 18 deletions
+6 -2
View File
@@ -1,6 +1,10 @@
<script setup lang="ts">
import type { BillingAccountDto, BillingPlanCode } from '@mento/shared';
import { BILLING_PLAN_CODES, BILLING_PLAN_LABELS } from '@mento/shared';
import {
BILLING_PLAN_CODES,
BILLING_PLAN_LABELS,
isPermanentBillingPlan,
} from '@mento/shared';
import { toFaDigits } from '@/lib/jalali';
defineProps<{
@@ -20,7 +24,7 @@ const emit = defineEmits<{
<p v-if="billing" class="muted">
{{ BILLING_PLAN_LABELS[billing.planCode] }}
· {{ billing.status }}
· {{ toFaDigits(billing.daysRemaining) }} روز
· {{ isPermanentBillingPlan(billing.planCode) ? 'بدون انقضا' : `${toFaDigits(billing.daysRemaining)} روز` }}
· سقف محیط {{ toFaDigits(billing.maxOrganizations) }}
</p>
<p v-else class="muted">هنوز پلن ندارد — یکی از پلن‌ها را اعمال کنید.</p>
@@ -20,6 +20,7 @@ import {
USER_ROLE_LABELS,
USER_ROLES,
isBusinessField,
isPermanentBillingPlan,
} from '@mento/shared';
import { platformApi } from '@/lib/platform-api';
import { BUSINESS_FIELDS, BUSINESS_FIELD_LABELS } from '@/lib/business-fields';
@@ -89,6 +90,27 @@ function resetCreateForm() {
createForm.ownerMobile = '';
}
function subscriptionBadge(org: PlatformOrganizationDto): {
label: string;
tone: 'ok' | 'warn' | 'expired' | 'none';
} {
const sub = org.subscription;
if (!sub) return { label: 'بدون اشتراک', tone: 'none' };
const plan = BILLING_PLAN_LABELS[sub.planCode] ?? sub.planCode;
if (sub.status === 'suspended') return { label: `${plan} · معلق`, tone: 'expired' };
if (isPermanentBillingPlan(sub.planCode)) return { label: plan, tone: 'ok' };
if (sub.status === 'expired' || sub.daysRemaining <= 0) {
return {
label: `${plan} · منقضی شده (${formatJalaliNumeric(new Date(sub.expiresAt))})`,
tone: 'expired',
};
}
return {
label: `${plan} · ${toFaDigits(sub.daysRemaining)} روز مانده`,
tone: sub.daysRemaining <= 3 ? 'warn' : 'ok',
};
}
async function load() {
loading.value = true;
error.value = '';
@@ -356,6 +378,11 @@ async function applyPlan(userId: string, planCode: BillingPlanCode) {
);
detail.value = data;
}
const { data: list } = await platformApi.get<PlatformOrganizationDto[]>(
'/platform/organizations',
{ params: query.value.trim() ? { q: query.value.trim() } : undefined },
);
items.value = list;
success.value = `پلن «${BILLING_PLAN_LABELS[planCode]}» اعمال شد`;
} catch (e) {
error.value = apiError(e, 'اعمال پلن ناموفق بود');
@@ -438,6 +465,9 @@ onMounted(() => {
</div>
<div class="meta">
<em :class="org.isActive ? 'on' : 'off'">{{ org.isActive ? 'فعال' : 'غیرفعال' }}</em>
<b class="sub-badge" :class="subscriptionBadge(org).tone">
{{ subscriptionBadge(org).label }}
</b>
<small>
{{ toFaDigits(org.memberCount) }} عضو ·
{{ toFaDigits(org.personCount) }} شخص ·
@@ -779,6 +809,40 @@ label span {
text-align: end;
}
.sub-badge {
display: inline-block;
margin-inline-start: 0.4rem;
padding: 0.12rem 0.5rem;
border-radius: 999px;
font-size: 0.74rem;
font-weight: 700;
border: 1px solid transparent;
}
.sub-badge.ok {
color: var(--success-deep);
background: #ecfdf5;
border-color: #a7f3d0;
}
.sub-badge.warn {
color: #b45309;
background: #fffbeb;
border-color: #fde68a;
}
.sub-badge.expired {
color: var(--danger);
background: #fef2f2;
border-color: #fecaca;
}
.sub-badge.none {
color: var(--muted);
background: #f1f5f9;
border-color: var(--line);
}
.actions {
display: flex;
gap: 0.45rem;