
* Handle limit reached error * Update changelog * Move notifications to higher layer * Handle limits top-level * Remove unused imports * Add alert component * Fetch limits from API * Display limits in staff list * Fix disabled text button color * Display limits in products pages * Display limits in channel list * Display limits in warehouse list * Display limits in order list * Add stories for limits * Move alert to corresponding section * Update schema * Update changelog * Fetch only needed limitations * Fix types * Fix story * Display limits in variant creator * Improve type consistency * Update snapshots * Update limit counter after object deletion * Fix copy * Improve code readability * Lint files * Fix dark mode alerts * Improve contrast * Fix sku limit in product variant list * Update stories * Update messages * Extract messages
24 lines
611 B
TypeScript
24 lines
611 B
TypeScript
import { RefreshLimits_shop_limits } from "@saleor/components/Shop/types/RefreshLimits";
|
|
import { LimitInfoFragment } from "@saleor/fragments/types/LimitInfoFragment";
|
|
|
|
export function hasLimits(
|
|
limits: RefreshLimits_shop_limits,
|
|
key: keyof LimitInfoFragment
|
|
): boolean {
|
|
if (limits === undefined) {
|
|
return false;
|
|
}
|
|
|
|
return limits.allowedUsage[key] !== null;
|
|
}
|
|
|
|
export function isLimitReached(
|
|
limits: RefreshLimits_shop_limits,
|
|
key: keyof LimitInfoFragment
|
|
): boolean {
|
|
if (!hasLimits(limits, key)) {
|
|
return false;
|
|
}
|
|
|
|
return limits.currentUsage[key] >= limits.allowedUsage[key];
|
|
}
|