feat(subscriptions): migrate subscription management to merchant level and seed tiers
Move subscription create/edit from store detail (broken endpoint) to merchant detail page with proper modal UI. Seed 4 subscription tiers (Essential, Professional, Business, Enterprise) in init_production.py. Also includes cross-module dependency declarations, store domain platform_id migration, platform context middleware, CMS route fixes, and migration backups. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,7 @@ cart_module = ModuleDefinition(
|
||||
description="Session-based shopping cart for storefronts",
|
||||
version="1.0.0",
|
||||
is_self_contained=True,
|
||||
requires=["inventory"], # Checks inventory availability
|
||||
requires=["inventory", "catalog"], # Checks inventory availability and references Product model
|
||||
migrations_path="migrations",
|
||||
features=[
|
||||
"cart_management", # Basic cart CRUD operations
|
||||
|
||||
@@ -34,6 +34,25 @@ store_content_pages_router = APIRouter(prefix="/content-pages")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _resolve_platform_id(db: Session, store_id: int) -> int | None:
|
||||
"""Resolve platform_id from store's primary StorePlatform. Returns None if not found."""
|
||||
from app.modules.tenancy.models import StorePlatform
|
||||
primary_sp = (
|
||||
db.query(StorePlatform)
|
||||
.filter(StorePlatform.store_id == store_id, StorePlatform.is_primary.is_(True))
|
||||
.first()
|
||||
)
|
||||
if primary_sp:
|
||||
return primary_sp.platform_id
|
||||
# Fallback: any active store_platform
|
||||
any_sp = (
|
||||
db.query(StorePlatform)
|
||||
.filter(StorePlatform.store_id == store_id, StorePlatform.is_active.is_(True))
|
||||
.first()
|
||||
)
|
||||
return any_sp.platform_id if any_sp else None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# STORE CONTENT PAGES
|
||||
# ============================================================================
|
||||
@@ -50,8 +69,9 @@ def list_store_pages(
|
||||
|
||||
Returns store-specific overrides + platform defaults (store overrides take precedence).
|
||||
"""
|
||||
platform_id = _resolve_platform_id(db, current_user.token_store_id)
|
||||
pages = content_page_service.list_pages_for_store(
|
||||
db, store_id=current_user.token_store_id, include_unpublished=include_unpublished
|
||||
db, platform_id=platform_id, store_id=current_user.token_store_id, include_unpublished=include_unpublished
|
||||
)
|
||||
|
||||
return [page.to_dict() for page in pages]
|
||||
@@ -148,11 +168,10 @@ def get_platform_default(
|
||||
Useful for stores to view the original before/after overriding.
|
||||
"""
|
||||
# Get store's platform
|
||||
store = store_service.get_store_by_id_optional(db, current_user.token_store_id)
|
||||
platform_id = 1 # Default to OMS
|
||||
|
||||
if store and store.platforms:
|
||||
platform_id = store.platforms[0].id
|
||||
platform_id = _resolve_platform_id(db, current_user.token_store_id)
|
||||
if platform_id is None:
|
||||
from fastapi import HTTPException
|
||||
raise HTTPException(status_code=400, detail="Store is not subscribed to any platform")
|
||||
|
||||
# Get platform default (store_id=None)
|
||||
page = content_page_service.get_store_default_page(
|
||||
@@ -177,8 +196,10 @@ def get_page(
|
||||
|
||||
Returns store override if exists, otherwise platform default.
|
||||
"""
|
||||
platform_id = _resolve_platform_id(db, current_user.token_store_id)
|
||||
page = content_page_service.get_page_for_store_or_raise(
|
||||
db,
|
||||
platform_id=platform_id,
|
||||
slug=slug,
|
||||
store_id=current_user.token_store_id,
|
||||
include_unpublished=include_unpublished,
|
||||
|
||||
@@ -36,11 +36,13 @@ def get_navigation_pages(request: Request, db: Session = Depends(get_db)):
|
||||
Returns store overrides + platform defaults.
|
||||
"""
|
||||
store = getattr(request.state, "store", None)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
store_id = store.id if store else None
|
||||
platform_id = platform.id if platform else 1
|
||||
|
||||
# Get all published pages for this store
|
||||
pages = content_page_service.list_pages_for_store(
|
||||
db, store_id=store_id, include_unpublished=False
|
||||
db, platform_id=platform_id, store_id=store_id, include_unpublished=False
|
||||
)
|
||||
|
||||
return [
|
||||
@@ -64,10 +66,13 @@ def get_content_page(slug: str, request: Request, db: Session = Depends(get_db))
|
||||
Returns store override if exists, otherwise platform default.
|
||||
"""
|
||||
store = getattr(request.state, "store", None)
|
||||
platform = getattr(request.state, "platform", None)
|
||||
store_id = store.id if store else None
|
||||
platform_id = platform.id if platform else 1
|
||||
|
||||
page = content_page_service.get_page_for_store_or_raise(
|
||||
db,
|
||||
platform_id=platform_id,
|
||||
slug=slug,
|
||||
store_id=store_id,
|
||||
include_unpublished=False, # Only show published pages
|
||||
|
||||
@@ -52,6 +52,7 @@ inventory_module = ModuleDefinition(
|
||||
"transaction history, and bulk imports."
|
||||
),
|
||||
version="1.0.0",
|
||||
requires=["catalog"], # Depends on catalog module for Product model
|
||||
# Module-driven permissions
|
||||
permissions=[
|
||||
PermissionDefinition(
|
||||
|
||||
@@ -56,7 +56,7 @@ marketplace_module = ModuleDefinition(
|
||||
"and catalog synchronization."
|
||||
),
|
||||
version="1.0.0",
|
||||
requires=["inventory"], # Depends on inventory module
|
||||
requires=["inventory", "catalog", "orders"], # Depends on inventory, catalog, and orders modules
|
||||
features=[
|
||||
"letzshop_sync", # Sync products with Letzshop
|
||||
"marketplace_import", # Import products from marketplace
|
||||
|
||||
@@ -52,7 +52,7 @@ orders_module = ModuleDefinition(
|
||||
"invoicing, and bulk order operations. Uses the payments module for checkout."
|
||||
),
|
||||
version="1.0.0",
|
||||
requires=["payments"], # Depends on payments module for checkout
|
||||
requires=["payments", "catalog", "inventory"], # Depends on payments, catalog, and inventory modules
|
||||
# Module-driven permissions
|
||||
permissions=[
|
||||
PermissionDefinition(
|
||||
|
||||
@@ -52,14 +52,25 @@ class StoreDomain(Base, TimestampMixin):
|
||||
is_verified = Column(Boolean, default=False, nullable=False)
|
||||
verified_at = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
# Platform association (for platform context resolution from custom domains)
|
||||
platform_id = Column(
|
||||
Integer,
|
||||
ForeignKey("platforms.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
index=True,
|
||||
comment="Platform this domain is associated with (for platform context resolution)",
|
||||
)
|
||||
|
||||
# Relationships
|
||||
store = relationship("Store", back_populates="domains")
|
||||
platform = relationship("Platform")
|
||||
|
||||
# Constraints
|
||||
__table_args__ = (
|
||||
UniqueConstraint("store_id", "domain", name="uq_store_domain"),
|
||||
Index("idx_domain_active", "domain", "is_active"),
|
||||
Index("idx_store_domain_primary", "store_id", "is_primary"),
|
||||
Index("idx_store_domain_platform", "platform_id"),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -78,6 +78,7 @@ def add_store_domain(
|
||||
is_active=domain.is_active,
|
||||
is_verified=domain.is_verified,
|
||||
ssl_status=domain.ssl_status,
|
||||
platform_id=domain.platform_id,
|
||||
verification_token=domain.verification_token,
|
||||
verified_at=domain.verified_at,
|
||||
ssl_verified_at=domain.ssl_verified_at,
|
||||
@@ -117,6 +118,7 @@ def list_store_domains(
|
||||
is_active=d.is_active,
|
||||
is_verified=d.is_verified,
|
||||
ssl_status=d.ssl_status,
|
||||
platform_id=d.platform_id,
|
||||
verification_token=d.verification_token if not d.is_verified else None,
|
||||
verified_at=d.verified_at,
|
||||
ssl_verified_at=d.ssl_verified_at,
|
||||
@@ -151,6 +153,7 @@ def get_domain_details(
|
||||
is_active=domain.is_active,
|
||||
is_verified=domain.is_verified,
|
||||
ssl_status=domain.ssl_status,
|
||||
platform_id=domain.platform_id,
|
||||
verification_token=(
|
||||
domain.verification_token if not domain.is_verified else None
|
||||
),
|
||||
@@ -197,6 +200,7 @@ def update_store_domain(
|
||||
is_active=domain.is_active,
|
||||
is_verified=domain.is_verified,
|
||||
ssl_status=domain.ssl_status,
|
||||
platform_id=domain.platform_id,
|
||||
verification_token=None, # Don't expose token after updates
|
||||
verified_at=domain.verified_at,
|
||||
ssl_verified_at=domain.ssl_verified_at,
|
||||
|
||||
@@ -28,6 +28,7 @@ class StoreDomainCreate(BaseModel):
|
||||
is_primary: bool = Field(
|
||||
default=False, description="Set as primary domain for the store"
|
||||
)
|
||||
platform_id: int | None = Field(None, description="Platform this domain belongs to")
|
||||
|
||||
@field_validator("domain")
|
||||
@classmethod
|
||||
@@ -86,6 +87,7 @@ class StoreDomainResponse(BaseModel):
|
||||
is_active: bool
|
||||
is_verified: bool
|
||||
ssl_status: str
|
||||
platform_id: int | None = None
|
||||
verification_token: str | None = None
|
||||
verified_at: datetime | None = None
|
||||
ssl_verified_at: datetime | None = None
|
||||
|
||||
@@ -101,11 +101,23 @@ class StoreDomainService:
|
||||
if domain_data.is_primary:
|
||||
self._unset_primary_domains(db, store_id)
|
||||
|
||||
# Resolve platform_id: use provided value, or auto-resolve from primary StorePlatform
|
||||
platform_id = domain_data.platform_id
|
||||
if not platform_id:
|
||||
from app.modules.tenancy.models import StorePlatform
|
||||
primary_sp = (
|
||||
db.query(StorePlatform)
|
||||
.filter(StorePlatform.store_id == store_id, StorePlatform.is_primary.is_(True))
|
||||
.first()
|
||||
)
|
||||
platform_id = primary_sp.platform_id if primary_sp else None
|
||||
|
||||
# Create domain record
|
||||
new_domain = StoreDomain(
|
||||
store_id=store_id,
|
||||
domain=normalized_domain,
|
||||
is_primary=domain_data.is_primary,
|
||||
platform_id=platform_id,
|
||||
verification_token=secrets.token_urlsafe(32),
|
||||
is_verified=False, # Requires DNS verification
|
||||
is_active=False, # Cannot be active until verified
|
||||
|
||||
@@ -16,6 +16,16 @@ function adminMerchantDetail() {
|
||||
error: null,
|
||||
merchantId: null,
|
||||
|
||||
// Subscription state
|
||||
subscription: null,
|
||||
subscriptionTier: null,
|
||||
usageMetrics: [],
|
||||
tiers: [],
|
||||
platformId: null,
|
||||
showCreateSubscriptionModal: false,
|
||||
createForm: { tier_code: 'essential', status: 'trial', trial_days: 14, is_annual: false },
|
||||
creatingSubscription: false,
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
// Load i18n translations
|
||||
@@ -38,6 +48,10 @@ function adminMerchantDetail() {
|
||||
this.merchantId = match[1];
|
||||
merchantDetailLog.info('Viewing merchant:', this.merchantId);
|
||||
await this.loadMerchant();
|
||||
await this.loadPlatforms();
|
||||
if (this.platformId) {
|
||||
await this.loadSubscription();
|
||||
}
|
||||
} else {
|
||||
merchantDetailLog.error('No merchant ID in URL');
|
||||
this.error = 'Invalid merchant URL';
|
||||
@@ -84,6 +98,128 @@ function adminMerchantDetail() {
|
||||
}
|
||||
},
|
||||
|
||||
// Load platforms and find OMS platform ID
|
||||
async loadPlatforms() {
|
||||
try {
|
||||
const response = await apiClient.get('/admin/platforms');
|
||||
const platforms = response.items || response;
|
||||
const oms = platforms.find(p => p.code === 'oms');
|
||||
if (oms) {
|
||||
this.platformId = oms.id;
|
||||
merchantDetailLog.info('OMS platform resolved:', this.platformId);
|
||||
} else {
|
||||
merchantDetailLog.warn('OMS platform not found');
|
||||
}
|
||||
} catch (error) {
|
||||
merchantDetailLog.warn('Failed to load platforms:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
// Load subscription for this merchant
|
||||
async loadSubscription() {
|
||||
if (!this.merchantId || !this.platformId) return;
|
||||
|
||||
merchantDetailLog.info('Loading subscription for merchant:', this.merchantId);
|
||||
|
||||
try {
|
||||
const url = `/admin/subscriptions/merchants/${this.merchantId}/platforms/${this.platformId}`;
|
||||
window.LogConfig.logApiCall('GET', url, null, 'request');
|
||||
|
||||
const response = await apiClient.get(url);
|
||||
window.LogConfig.logApiCall('GET', url, response, 'response');
|
||||
|
||||
this.subscription = response.subscription || response;
|
||||
this.subscriptionTier = response.tier || null;
|
||||
this.usageMetrics = response.features || [];
|
||||
|
||||
merchantDetailLog.info('Subscription loaded:', {
|
||||
tier: this.subscription?.tier,
|
||||
status: this.subscription?.status,
|
||||
features_count: this.usageMetrics.length
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
merchantDetailLog.info('No subscription found for merchant');
|
||||
this.subscription = null;
|
||||
this.usageMetrics = [];
|
||||
} else {
|
||||
merchantDetailLog.warn('Failed to load subscription:', error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Load available subscription tiers
|
||||
async loadTiers() {
|
||||
if (this.tiers.length > 0) return;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get('/admin/subscriptions/tiers');
|
||||
this.tiers = response.items || response;
|
||||
merchantDetailLog.info('Loaded tiers:', this.tiers.length);
|
||||
} catch (error) {
|
||||
merchantDetailLog.warn('Failed to load tiers:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
// Open create subscription modal
|
||||
async openCreateSubscriptionModal() {
|
||||
await this.loadTiers();
|
||||
this.createForm = { tier_code: 'essential', status: 'trial', trial_days: 14, is_annual: false };
|
||||
this.showCreateSubscriptionModal = true;
|
||||
},
|
||||
|
||||
// Create subscription for this merchant
|
||||
async createSubscription() {
|
||||
if (!this.merchantId || !this.platformId) return;
|
||||
|
||||
this.creatingSubscription = true;
|
||||
merchantDetailLog.info('Creating subscription for merchant:', this.merchantId);
|
||||
|
||||
try {
|
||||
const url = `/admin/subscriptions/merchants/${this.merchantId}/platforms/${this.platformId}`;
|
||||
const payload = {
|
||||
merchant_id: parseInt(this.merchantId),
|
||||
platform_id: this.platformId,
|
||||
tier_code: this.createForm.tier_code,
|
||||
status: this.createForm.status,
|
||||
trial_days: this.createForm.status === 'trial' ? parseInt(this.createForm.trial_days) : 0,
|
||||
is_annual: this.createForm.is_annual
|
||||
};
|
||||
|
||||
window.LogConfig.logApiCall('POST', url, payload, 'request');
|
||||
const response = await apiClient.post(url, payload);
|
||||
window.LogConfig.logApiCall('POST', url, response, 'response');
|
||||
|
||||
this.showCreateSubscriptionModal = false;
|
||||
Utils.showToast('Subscription created successfully', 'success');
|
||||
merchantDetailLog.info('Subscription created');
|
||||
|
||||
await this.loadSubscription();
|
||||
|
||||
} catch (error) {
|
||||
window.LogConfig.logError(error, 'Create Subscription');
|
||||
Utils.showToast(error.message || 'Failed to create subscription', 'error');
|
||||
} finally {
|
||||
this.creatingSubscription = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Get usage bar color based on percentage
|
||||
getUsageBarColor(current, limit) {
|
||||
if (!limit || limit === 0) return 'bg-blue-500';
|
||||
const percent = (current / limit) * 100;
|
||||
if (percent >= 90) return 'bg-red-500';
|
||||
if (percent >= 75) return 'bg-yellow-500';
|
||||
return 'bg-green-500';
|
||||
},
|
||||
|
||||
// Format tier price for display
|
||||
formatTierPrice(tier) {
|
||||
if (!tier.price_monthly_cents) return 'Custom';
|
||||
return `€${(tier.price_monthly_cents / 100).toFixed(2)}/mo`;
|
||||
},
|
||||
|
||||
// Format date (matches dashboard pattern)
|
||||
formatDate(dateString) {
|
||||
if (!dateString) {
|
||||
@@ -140,6 +276,9 @@ function adminMerchantDetail() {
|
||||
async refresh() {
|
||||
merchantDetailLog.info('=== MERCHANT REFRESH TRIGGERED ===');
|
||||
await this.loadMerchant();
|
||||
if (this.platformId) {
|
||||
await this.loadSubscription();
|
||||
}
|
||||
Utils.showToast(I18n.t('tenancy.messages.merchant_details_refreshed'), 'success');
|
||||
merchantDetailLog.info('=== MERCHANT REFRESH COMPLETE ===');
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ function adminStoreDetail() {
|
||||
loading: false,
|
||||
error: null,
|
||||
storeCode: null,
|
||||
showSubscriptionModal: false,
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
@@ -150,39 +149,6 @@ function adminStoreDetail() {
|
||||
return 'bg-green-500';
|
||||
},
|
||||
|
||||
// Create a new subscription for this store
|
||||
async createSubscription() {
|
||||
if (!this.store?.id) {
|
||||
Utils.showToast(I18n.t('tenancy.messages.no_store_loaded'), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
detailLog.info('Creating subscription for store:', this.store.id);
|
||||
|
||||
try {
|
||||
// Create a trial subscription with default tier
|
||||
const url = `/admin/subscriptions/${this.store.id}`;
|
||||
const data = {
|
||||
tier: 'essential',
|
||||
status: 'trial',
|
||||
trial_days: 14,
|
||||
is_annual: false
|
||||
};
|
||||
|
||||
window.LogConfig.logApiCall('POST', url, data, 'request');
|
||||
const response = await apiClient.post(url, data);
|
||||
window.LogConfig.logApiCall('POST', url, response, 'response');
|
||||
|
||||
this.subscription = response;
|
||||
Utils.showToast(I18n.t('tenancy.messages.subscription_created_successfully'), 'success');
|
||||
detailLog.info('Subscription created:', this.subscription);
|
||||
|
||||
} catch (error) {
|
||||
window.LogConfig.logError(error, 'Create Subscription');
|
||||
Utils.showToast(error.message || 'Failed to create subscription', 'error');
|
||||
}
|
||||
},
|
||||
|
||||
// Delete store
|
||||
async deleteStore() {
|
||||
detailLog.info('Delete store requested:', this.storeCode);
|
||||
|
||||
@@ -194,6 +194,167 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Subscription Card -->
|
||||
<div class="px-4 py-3 mb-6 bg-white rounded-lg shadow-md dark:bg-gray-800" x-show="subscription">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">
|
||||
Subscription
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<!-- Tier and Status -->
|
||||
<div class="flex flex-wrap items-center gap-4 mb-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400">Tier:</span>
|
||||
<span class="px-2.5 py-0.5 text-sm font-medium rounded-full"
|
||||
:class="{
|
||||
'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300': subscription?.tier === 'essential',
|
||||
'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300': subscription?.tier === 'professional',
|
||||
'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300': subscription?.tier === 'business',
|
||||
'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300': subscription?.tier === 'enterprise'
|
||||
}"
|
||||
x-text="subscription?.tier ? subscription.tier.charAt(0).toUpperCase() + subscription.tier.slice(1) : '-'">
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400">Status:</span>
|
||||
<span class="px-2.5 py-0.5 text-sm font-medium rounded-full"
|
||||
:class="{
|
||||
'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300': subscription?.status === 'active',
|
||||
'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300': subscription?.status === 'trial',
|
||||
'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300': subscription?.status === 'past_due',
|
||||
'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300': subscription?.status === 'cancelled' || subscription?.status === 'expired'
|
||||
}"
|
||||
x-text="subscription?.status ? subscription.status.replace('_', ' ').charAt(0).toUpperCase() + subscription.status.slice(1) : '-'">
|
||||
</span>
|
||||
</div>
|
||||
<template x-if="subscription?.is_annual">
|
||||
<span class="px-2.5 py-0.5 text-xs font-medium text-purple-800 bg-purple-100 rounded-full dark:bg-purple-900 dark:text-purple-300">
|
||||
Annual
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Period Info -->
|
||||
<div class="flex flex-wrap gap-4 mb-4 text-sm">
|
||||
<div>
|
||||
<span class="text-gray-600 dark:text-gray-400">Period:</span>
|
||||
<span class="ml-1 text-gray-700 dark:text-gray-300" x-text="formatDate(subscription?.period_start)"></span>
|
||||
<span class="text-gray-400">→</span>
|
||||
<span class="text-gray-700 dark:text-gray-300" x-text="formatDate(subscription?.period_end)"></span>
|
||||
</div>
|
||||
<template x-if="subscription?.trial_ends_at">
|
||||
<div>
|
||||
<span class="text-gray-600 dark:text-gray-400">Trial ends:</span>
|
||||
<span class="ml-1 text-gray-700 dark:text-gray-300" x-text="formatDate(subscription?.trial_ends_at)"></span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Usage Meters -->
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
<template x-for="metric in usageMetrics" :key="metric.name">
|
||||
<div class="p-3 bg-gray-50 rounded-lg dark:bg-gray-700">
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<span class="text-xs font-medium text-gray-600 dark:text-gray-400 uppercase" x-text="metric.name"></span>
|
||||
</div>
|
||||
<div class="flex items-baseline gap-1">
|
||||
<span class="text-xl font-bold text-gray-700 dark:text-gray-200" x-text="metric.current"></span>
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">
|
||||
/ <span x-text="metric.is_unlimited ? '∞' : metric.limit"></span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 h-1.5 bg-gray-200 rounded-full dark:bg-gray-600" x-show="!metric.is_unlimited">
|
||||
<div class="h-1.5 rounded-full transition-all"
|
||||
:class="getUsageBarColor(metric.current, metric.limit)"
|
||||
:style="`width: ${Math.min(100, metric.percentage || 0)}%`">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template x-if="usageMetrics.length === 0">
|
||||
<div class="p-3 bg-gray-50 rounded-lg dark:bg-gray-700 md:col-span-3">
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400 text-center">No usage data available</p>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- No Subscription Notice -->
|
||||
<div class="px-4 py-3 mb-6 bg-yellow-50 border border-yellow-200 rounded-lg dark:bg-yellow-900/20 dark:border-yellow-800" x-show="!subscription && !loading && platformId">
|
||||
<div class="flex items-center gap-3">
|
||||
<span x-html="$icon('exclamation', 'w-5 h-5 text-yellow-600 dark:text-yellow-400')"></span>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-yellow-800 dark:text-yellow-200">No Subscription Found</p>
|
||||
<p class="text-sm text-yellow-700 dark:text-yellow-300">This merchant doesn't have a subscription yet.</p>
|
||||
</div>
|
||||
<button
|
||||
@click="openCreateSubscriptionModal()"
|
||||
class="ml-auto px-3 py-1.5 text-sm font-medium text-white bg-yellow-600 rounded-lg hover:bg-yellow-700">
|
||||
Create Subscription
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Create Subscription Modal -->
|
||||
<div x-show="showCreateSubscriptionModal" class="fixed inset-0 z-50 flex items-center justify-center" x-cloak>
|
||||
<div class="fixed inset-0 bg-black bg-opacity-50" @click="showCreateSubscriptionModal = false"></div>
|
||||
<div class="relative z-10 w-full max-w-md p-6 bg-white rounded-lg shadow-xl dark:bg-gray-800">
|
||||
<h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200">Create Subscription</h3>
|
||||
|
||||
<!-- Tier Selector -->
|
||||
<div class="mb-4">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Subscription Tier</label>
|
||||
<select x-model="createForm.tier_code"
|
||||
class="w-full px-3 py-2 text-sm border border-gray-300 rounded-lg dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500">
|
||||
<template x-for="tier in tiers" :key="tier.code">
|
||||
<option :value="tier.code" x-text="tier.name + ' — ' + formatTierPrice(tier)"></option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Status -->
|
||||
<div class="mb-4">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Status</label>
|
||||
<select x-model="createForm.status"
|
||||
class="w-full px-3 py-2 text-sm border border-gray-300 rounded-lg dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500">
|
||||
<option value="trial">Trial</option>
|
||||
<option value="active">Active</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Trial Days (shown only when status=trial) -->
|
||||
<div class="mb-4" x-show="createForm.status === 'trial'">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Trial Days</label>
|
||||
<input type="number" x-model="createForm.trial_days" min="1" max="90"
|
||||
class="w-full px-3 py-2 text-sm border border-gray-300 rounded-lg dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500">
|
||||
</div>
|
||||
|
||||
<!-- Annual Billing -->
|
||||
<div class="mb-6">
|
||||
<label class="flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300">
|
||||
<input type="checkbox" x-model="createForm.is_annual"
|
||||
class="rounded border-gray-300 text-purple-600 focus:ring-purple-500 dark:border-gray-600 dark:bg-gray-700">
|
||||
Annual billing
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="flex justify-end gap-3">
|
||||
<button @click="showCreateSubscriptionModal = false"
|
||||
class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600">
|
||||
Cancel
|
||||
</button>
|
||||
<button @click="createSubscription()"
|
||||
:disabled="creatingSubscription"
|
||||
class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
<span x-show="!creatingSubscription">Create</span>
|
||||
<span x-show="creatingSubscription">Creating...</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stores Section -->
|
||||
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800" x-show="merchant?.stores && merchant?.stores.length > 0">
|
||||
<h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200">
|
||||
|
||||
@@ -112,12 +112,12 @@
|
||||
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">
|
||||
Subscription
|
||||
</h3>
|
||||
<button
|
||||
@click="showSubscriptionModal = true"
|
||||
<a
|
||||
:href="'/admin/merchants/' + store?.merchant_id"
|
||||
class="flex items-center px-3 py-1.5 text-sm font-medium text-purple-600 hover:text-purple-700 dark:text-purple-400 dark:hover:text-purple-300">
|
||||
<span x-html="$icon('edit', 'w-4 h-4 mr-1')"></span>
|
||||
Edit
|
||||
</button>
|
||||
<span x-html="$icon('external-link', 'w-4 h-4 mr-1')"></span>
|
||||
Manage on Merchant Page
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Tier and Status -->
|
||||
@@ -206,11 +206,11 @@
|
||||
<p class="text-sm font-medium text-yellow-800 dark:text-yellow-200">No Subscription Found</p>
|
||||
<p class="text-sm text-yellow-700 dark:text-yellow-300">This store doesn't have a subscription yet.</p>
|
||||
</div>
|
||||
<button
|
||||
@click="createSubscription()"
|
||||
<a
|
||||
:href="'/admin/merchants/' + store?.merchant_id"
|
||||
class="ml-auto px-3 py-1.5 text-sm font-medium text-white bg-yellow-600 rounded-lg hover:bg-yellow-700">
|
||||
Create Subscription
|
||||
</button>
|
||||
Manage on Merchant Page
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user