Improve the frontend modals
This commit is contained in:
@@ -187,21 +187,48 @@ export class SubscriptionService {
|
||||
/**
|
||||
* Check if tenant can perform an action within quota limits
|
||||
*/
|
||||
async checkQuotaLimit(
|
||||
async checkQuotaLimit(
|
||||
tenantId: string,
|
||||
quotaType: string,
|
||||
requestedAmount?: number
|
||||
): Promise<QuotaCheckResponse> {
|
||||
const queryParams = new URLSearchParams();
|
||||
if (requestedAmount !== undefined) {
|
||||
queryParams.append('requested_amount', requestedAmount.toString());
|
||||
// Map quotaType to the existing endpoints in tenant_operations.py
|
||||
let endpoint: string;
|
||||
switch (quotaType) {
|
||||
case 'inventory_items':
|
||||
endpoint = 'can-add-product';
|
||||
break;
|
||||
case 'users':
|
||||
endpoint = 'can-add-user';
|
||||
break;
|
||||
case 'locations':
|
||||
endpoint = 'can-add-location';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported quota type: ${quotaType}`);
|
||||
}
|
||||
|
||||
const url = queryParams.toString()
|
||||
? `${this.baseUrl}/subscriptions/${tenantId}/quotas/${quotaType}/check?${queryParams.toString()}`
|
||||
: `${this.baseUrl}/subscriptions/${tenantId}/quotas/${quotaType}/check`;
|
||||
|
||||
return apiClient.get<QuotaCheckResponse>(url);
|
||||
const url = `${this.baseUrl}/subscriptions/${tenantId}/${endpoint}`;
|
||||
|
||||
// Get the response from the endpoint (returns different format than expected)
|
||||
const response = await apiClient.get<{
|
||||
can_add: boolean;
|
||||
current_count?: number;
|
||||
max_allowed?: number;
|
||||
reason?: string;
|
||||
message?: string;
|
||||
}>(url);
|
||||
|
||||
// Map the response to QuotaCheckResponse format
|
||||
return {
|
||||
allowed: response.can_add,
|
||||
current: response.current_count || 0,
|
||||
limit: response.max_allowed || null,
|
||||
remaining: response.max_allowed !== undefined && response.current_count !== undefined
|
||||
? response.max_allowed - response.current_count
|
||||
: null,
|
||||
message: response.reason || response.message || ''
|
||||
};
|
||||
}
|
||||
|
||||
async validatePlanUpgrade(tenantId: string, planKey: string): Promise<PlanUpgradeValidation> {
|
||||
@@ -348,4 +375,4 @@ export class SubscriptionService {
|
||||
}
|
||||
}
|
||||
|
||||
export const subscriptionService = new SubscriptionService();
|
||||
export const subscriptionService = new SubscriptionService();
|
||||
|
||||
Reference in New Issue
Block a user