2022-12-30 08:54:39 +00:00
|
|
|
import { makeAutoObservable, runInAction } from "mobx";
|
2022-09-14 06:55:22 +00:00
|
|
|
import api from "../api";
|
2022-09-14 13:01:40 +00:00
|
|
|
import { getConvertedSize } from "@docspace/common/utils";
|
2022-09-15 14:43:02 +00:00
|
|
|
import toastr from "@docspace/components/toast/toastr";
|
2022-09-20 15:15:38 +00:00
|
|
|
|
|
|
|
const MANAGER = "manager";
|
|
|
|
const TOTAL_SIZE = "total_size";
|
|
|
|
|
2022-09-14 06:55:22 +00:00
|
|
|
class PaymentQuotasStore {
|
2022-11-25 10:24:27 +00:00
|
|
|
portalPaymentQuotas = {};
|
2022-09-14 06:55:22 +00:00
|
|
|
portalPaymentQuotasFeatures = [];
|
|
|
|
isLoaded = false;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
makeAutoObservable(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
setIsLoaded = (isLoaded) => {
|
|
|
|
this.isLoaded = isLoaded;
|
|
|
|
};
|
|
|
|
|
|
|
|
get planCost() {
|
2022-11-25 10:24:27 +00:00
|
|
|
if (this.portalPaymentQuotas.price) return this.portalPaymentQuotas.price;
|
2022-09-14 06:55:22 +00:00
|
|
|
else return { value: 0, currencySymbol: "" };
|
|
|
|
}
|
|
|
|
|
|
|
|
get stepAddingQuotaManagers() {
|
|
|
|
const result = this.portalPaymentQuotasFeatures.find(
|
2022-09-20 15:15:38 +00:00
|
|
|
(obj) => obj.id === MANAGER
|
2022-09-14 06:55:22 +00:00
|
|
|
);
|
|
|
|
return result.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get stepAddingQuotaTotalSize() {
|
|
|
|
const result = this.portalPaymentQuotasFeatures.find(
|
2022-09-20 15:15:38 +00:00
|
|
|
(obj) => obj.id === TOTAL_SIZE
|
2022-09-14 06:55:22 +00:00
|
|
|
);
|
|
|
|
return result.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get tariffTitle() {
|
2022-11-25 09:31:18 +00:00
|
|
|
return this.portalPaymentQuotas?.title;
|
2022-09-14 06:55:22 +00:00
|
|
|
}
|
2022-09-14 13:01:40 +00:00
|
|
|
|
2022-11-25 09:32:43 +00:00
|
|
|
setReplacingValuesInTranslation = (t) => {
|
2022-09-14 13:01:40 +00:00
|
|
|
this.replaceTotalSizeValue(t);
|
|
|
|
};
|
|
|
|
|
|
|
|
replaceTotalSizeValue = (t) => {
|
|
|
|
const totalSizeObj = this.portalPaymentQuotasFeatures.find(
|
2022-09-20 15:15:38 +00:00
|
|
|
(el) => el.id === TOTAL_SIZE
|
2022-09-14 13:01:40 +00:00
|
|
|
);
|
|
|
|
const replacedValue = totalSizeObj.title.replace(
|
|
|
|
"{0}",
|
|
|
|
getConvertedSize(t, totalSizeObj.value)
|
|
|
|
);
|
|
|
|
|
|
|
|
totalSizeObj.title = replacedValue;
|
|
|
|
};
|
2022-09-15 11:59:55 +00:00
|
|
|
|
|
|
|
get usedTotalStorageSizeTitle() {
|
|
|
|
const result = this.portalPaymentQuotasFeatures.find(
|
2022-09-20 15:15:38 +00:00
|
|
|
(obj) => obj.id === TOTAL_SIZE
|
2022-09-15 11:59:55 +00:00
|
|
|
);
|
|
|
|
return result.priceTitle;
|
|
|
|
}
|
|
|
|
get addedManagersCountTitle() {
|
|
|
|
const result = this.portalPaymentQuotasFeatures.find(
|
2022-09-20 15:15:38 +00:00
|
|
|
(obj) => obj.id === MANAGER
|
2022-09-15 11:59:55 +00:00
|
|
|
);
|
|
|
|
return result.priceTitle;
|
|
|
|
}
|
2022-09-21 09:42:08 +00:00
|
|
|
|
|
|
|
get tariffPlanTitle() {
|
2022-11-25 10:24:27 +00:00
|
|
|
return this.portalPaymentQuotas.title;
|
2022-09-21 09:42:08 +00:00
|
|
|
}
|
2022-09-14 13:01:40 +00:00
|
|
|
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;
|
|
|
|
|
2022-12-30 08:54:39 +00:00
|
|
|
runInAction(() => {
|
|
|
|
this.portalPaymentQuotas = res[0];
|
2022-09-14 06:55:22 +00:00
|
|
|
|
2022-12-30 08:54:39 +00:00
|
|
|
this.portalPaymentQuotasFeatures = res[0].features;
|
|
|
|
});
|
2022-09-14 06:55:22 +00:00
|
|
|
|
|
|
|
this.setIsLoaded(true);
|
|
|
|
} catch (e) {
|
|
|
|
toastr.error(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PaymentQuotasStore;
|