saleor-dashboard/src/utils/limits.ts
Michał Droń 931467a73a
Fix strict null checks in warehouses (#2945)
* Fix strict nulls in warehouse details

* Fix strict null check in warehouse list

* Fix stcit null checks in warehouse create view

* Fix overlapping label in textfields

* Improve labels in warehouse details

* Improve function description
2023-01-18 10:23:24 +01:00

33 lines
810 B
TypeScript

import { LimitInfoFragment, RefreshLimitsQuery } from "@dashboard/graphql";
export function hasLimits(
limits: RefreshLimitsQuery["shop"]["limits"] | undefined,
key: keyof LimitInfoFragment,
): boolean {
if (limits === undefined) {
return false;
}
return limits.allowedUsage[key] !== null;
}
/**
* Returns whether or not limit has been reached.
* If limits are undefined, returns false.
* */
export function isLimitReached(
limits: RefreshLimitsQuery["shop"]["limits"] | undefined,
key: keyof LimitInfoFragment,
): boolean {
if (!hasLimits(limits, key)) {
return false;
}
const currentUsage = limits?.currentUsage[key];
const allowedUsage = limits?.allowedUsage[key];
if (!currentUsage || !allowedUsage) {
return false;
}
return currentUsage >= allowedUsage!;
}