feat(billing): migrate frontend templates to feature provider system
Replace hardcoded subscription fields (orders_limit, products_limit,
team_members_limit) across 5 frontend pages with dynamic feature
provider APIs. Add admin convenience endpoint for store subscription
lookup. Remove legacy stubs (StoreSubscription, FeatureCode, Feature,
TIER_LIMITS, FeatureInfo, FeatureUpgradeInfo) and schema aliases.
Pages updated:
- Admin subscriptions: dynamic feature overrides editor
- Admin tiers: correct feature catalog/limits API URLs
- Store billing: usage metrics from /store/billing/usage
- Merchant subscription detail: tier.feature_limits rendering
- Admin store detail: new GET /admin/subscriptions/store/{id} endpoint
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,7 +39,7 @@ function adminSubscriptions() {
|
||||
},
|
||||
|
||||
// Sorting
|
||||
sortBy: 'vendor_name',
|
||||
sortBy: 'store_name',
|
||||
sortOrder: 'asc',
|
||||
|
||||
// Modal state
|
||||
@@ -47,12 +47,14 @@ function adminSubscriptions() {
|
||||
editingSub: null,
|
||||
formData: {
|
||||
tier: '',
|
||||
status: '',
|
||||
custom_orders_limit: null,
|
||||
custom_products_limit: null,
|
||||
custom_team_limit: null
|
||||
status: ''
|
||||
},
|
||||
|
||||
// Feature overrides
|
||||
featureOverrides: [],
|
||||
quantitativeFeatures: [],
|
||||
loadingOverrides: false,
|
||||
|
||||
// Computed: Total pages
|
||||
get totalPages() {
|
||||
return this.pagination.pages;
|
||||
@@ -203,16 +205,18 @@ function adminSubscriptions() {
|
||||
}
|
||||
},
|
||||
|
||||
openEditModal(sub) {
|
||||
async openEditModal(sub) {
|
||||
this.editingSub = sub;
|
||||
this.formData = {
|
||||
tier: sub.tier,
|
||||
status: sub.status,
|
||||
custom_orders_limit: sub.custom_orders_limit,
|
||||
custom_products_limit: sub.custom_products_limit,
|
||||
custom_team_limit: sub.custom_team_limit
|
||||
status: sub.status
|
||||
};
|
||||
this.featureOverrides = [];
|
||||
this.quantitativeFeatures = [];
|
||||
this.showModal = true;
|
||||
|
||||
// Load feature catalog and merchant overrides
|
||||
await this.loadFeatureOverrides(sub.merchant_id);
|
||||
},
|
||||
|
||||
closeModal() {
|
||||
@@ -220,6 +224,77 @@ function adminSubscriptions() {
|
||||
this.editingSub = null;
|
||||
},
|
||||
|
||||
async loadFeatureOverrides(merchantId) {
|
||||
this.loadingOverrides = true;
|
||||
try {
|
||||
const [catalogData, overridesData] = await Promise.all([
|
||||
apiClient.get('/admin/subscriptions/features/catalog'),
|
||||
apiClient.get(`/admin/subscriptions/features/merchants/${merchantId}/overrides`),
|
||||
]);
|
||||
|
||||
// Extract quantitative features from catalog
|
||||
const allFeatures = [];
|
||||
for (const [, features] of Object.entries(catalogData.features || {})) {
|
||||
for (const f of features) {
|
||||
if (f.feature_type === 'quantitative') {
|
||||
allFeatures.push(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.quantitativeFeatures = allFeatures;
|
||||
|
||||
// Map overrides by feature_code
|
||||
this.featureOverrides = (overridesData || []).map(o => ({
|
||||
feature_code: o.feature_code,
|
||||
limit_value: o.limit_value,
|
||||
is_enabled: o.is_enabled
|
||||
}));
|
||||
|
||||
subsLog.info(`Loaded ${allFeatures.length} quantitative features and ${this.featureOverrides.length} overrides`);
|
||||
} catch (error) {
|
||||
subsLog.error('Failed to load feature overrides:', error);
|
||||
} finally {
|
||||
this.loadingOverrides = false;
|
||||
}
|
||||
},
|
||||
|
||||
getOverrideValue(featureCode) {
|
||||
const override = this.featureOverrides.find(o => o.feature_code === featureCode);
|
||||
return override?.limit_value ?? '';
|
||||
},
|
||||
|
||||
setOverrideValue(featureCode, value) {
|
||||
const numValue = value === '' ? null : parseInt(value, 10);
|
||||
const existing = this.featureOverrides.find(o => o.feature_code === featureCode);
|
||||
if (existing) {
|
||||
existing.limit_value = numValue;
|
||||
} else if (numValue !== null) {
|
||||
this.featureOverrides.push({
|
||||
feature_code: featureCode,
|
||||
limit_value: numValue,
|
||||
is_enabled: true
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async saveFeatureOverrides(merchantId) {
|
||||
// Only send overrides that have a limit_value set
|
||||
const entries = this.featureOverrides
|
||||
.filter(o => o.limit_value !== null && o.limit_value !== undefined)
|
||||
.map(o => ({
|
||||
feature_code: o.feature_code,
|
||||
limit_value: o.limit_value,
|
||||
is_enabled: true
|
||||
}));
|
||||
|
||||
if (entries.length > 0) {
|
||||
await apiClient.put(
|
||||
`/admin/subscriptions/features/merchants/${merchantId}/overrides`,
|
||||
entries
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
async saveSubscription() {
|
||||
if (!this.editingSub) return;
|
||||
|
||||
@@ -227,14 +302,17 @@ function adminSubscriptions() {
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
// Clean up null values for empty strings
|
||||
const payload = { ...this.formData };
|
||||
if (payload.custom_orders_limit === '') payload.custom_orders_limit = null;
|
||||
if (payload.custom_products_limit === '') payload.custom_products_limit = null;
|
||||
if (payload.custom_team_limit === '') payload.custom_team_limit = null;
|
||||
|
||||
await apiClient.patch(`/admin/subscriptions/${this.editingSub.vendor_id}`, payload);
|
||||
this.successMessage = `Subscription for "${this.editingSub.vendor_name}" updated`;
|
||||
await apiClient.patch(
|
||||
`/admin/subscriptions/merchants/${this.editingSub.merchant_id}/platforms/${this.editingSub.platform_id}`,
|
||||
payload
|
||||
);
|
||||
|
||||
// Save feature overrides
|
||||
await this.saveFeatureOverrides(this.editingSub.merchant_id);
|
||||
|
||||
this.successMessage = `Subscription for "${this.editingSub.store_name || this.editingSub.merchant_name}" updated`;
|
||||
|
||||
this.closeModal();
|
||||
await this.loadSubscriptions();
|
||||
|
||||
Reference in New Issue
Block a user