saleor-dashboard/src/utils/limits.ts
Dominik Żegleń a3abb9c476
Handle Cloud limits (#1053)
* 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
2021-04-13 11:59:16 +02:00

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];
}