mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: unit functions
This commit is contained in:
1 parent
502cb3fcbd
commit
8686628ea2
2 files changed
+13
-6
No files matched your search
+10
-3
@@ -44,11 +44,18 @@ export function createValueUnitPair<T = string>(initialValue = 0, units: Unit<T>
|
||||
|
||||
unit.subscribe((newValue, prev) => {
|
||||
value.update((v) => {
|
||||
const unitInBase = v * units.find((u) => u.name === prev).value;
|
||||
return unitInBase / units.find((u) => u.name === newValue).value;
|
||||
const prevUnit = units.find((u) => u.name === prev);
|
||||
const newUnit = units.find((u) => u.name === newValue);
|
||||
|
||||
// If either unit is not found, just return the current value
|
||||
if (!prevUnit || !newUnit) {
|
||||
return v;
|
||||
}
|
||||
|
||||
const unitInBase = v * prevUnit.value;
|
||||
return unitInBase / newUnit.value;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
value,
|
||||
unit,
|
||||
|
||||
@@ -70,9 +70,9 @@ export type PlanServices =
|
||||
export function getServiceLimit(serviceId: PlanServices, tier: Tier = null): number {
|
||||
if (!isCloud) return 0;
|
||||
if (!serviceId) return 0;
|
||||
const plan = get(plansInfo).plans.find(
|
||||
(p) => p.$id === (tier ?? get(organization)?.billingPlan)
|
||||
);
|
||||
const info = get(plansInfo);
|
||||
if (!info?.plans) return 0;
|
||||
const plan = info.plans.find((p) => p.$id === (tier ?? get(organization)?.billingPlan));
|
||||
return plan?.[serviceId];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user