DocSpace-buildtools/packages/common/store/PaymentQuotasStore.js

89 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-09-14 06:55:22 +00:00
import { makeAutoObservable } from "mobx";
import api from "../api";
import { getConvertedSize } from "@docspace/common/utils";
2022-09-15 14:43:02 +00:00
import toastr from "@docspace/components/toast/toastr";
2022-09-14 06:55:22 +00:00
class PaymentQuotasStore {
portalPaymentQuotas = {};
portalPaymentQuotasFeatures = [];
isLoaded = false;
constructor() {
makeAutoObservable(this);
}
setIsLoaded = (isLoaded) => {
this.isLoaded = isLoaded;
};
get planCost() {
if (this.portalPaymentQuotas.price) return this.portalPaymentQuotas.price;
else return { value: 0, currencySymbol: "" };
}
get stepAddingQuotaManagers() {
const result = this.portalPaymentQuotasFeatures.find(
(obj) => obj.id === "manager"
);
return result.value;
}
get stepAddingQuotaTotalSize() {
const result = this.portalPaymentQuotasFeatures.find(
(obj) => obj.id === "total_size"
);
return result.value;
}
get tariffTitle() {
return this.portalPaymentQuotas.title;
}
replaceFeaturesValues = (t) => {
this.replaceTotalSizeValue(t);
};
replaceTotalSizeValue = (t) => {
const totalSizeObj = this.portalPaymentQuotasFeatures.find(
(el) => el.id === "total_size"
);
const replacedValue = totalSizeObj.title.replace(
"{0}",
getConvertedSize(t, totalSizeObj.value)
);
totalSizeObj.title = replacedValue;
};
get usedTotalStorageSizeTitle() {
const result = this.portalPaymentQuotasFeatures.find(
(obj) => obj.id === "total_size"
);
return result.priceTitle;
}
get addedManagersCountTitle() {
const result = this.portalPaymentQuotasFeatures.find(
2022-09-15 12:07:26 +00:00
(obj) => obj.id === "manager"
);
return result.priceTitle;
}
setPortalPaymentQuotas = async (t) => {
2022-09-14 06:55:22 +00:00
if (this.isLoaded) return;
try {
const res = await api.portal.getPortalPaymentQuotas();
if (!res) return;
this.portalPaymentQuotas = res[0];
this.portalPaymentQuotasFeatures = res[0].features;
this.setIsLoaded(true);
} catch (e) {
toastr.error(e);
}
};
}
export default PaymentQuotasStore;