From 89f31b87015235bf6d2fa54c5edde535ef60eac2 Mon Sep 17 00:00:00 2001 From: Tatiana Lopaeva Date: Tue, 28 May 2024 17:43:46 +0300 Subject: [PATCH] Shared/Client: Store: Added separation of methods for standalone payment page. --- packages/client/src/store/PaymentStore.ts | 27 ++++++++++++++----- packages/shared/store/CurrentQuotaStore.ts | 2 +- .../shared/store/CurrentTariffStatusStore.ts | 2 ++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/client/src/store/PaymentStore.ts b/packages/client/src/store/PaymentStore.ts index cef7ca0a64..c336731b97 100644 --- a/packages/client/src/store/PaymentStore.ts +++ b/packages/client/src/store/PaymentStore.ts @@ -231,12 +231,15 @@ class PaymentStore { }; standaloneBasicSettings = async (t: TTranslation) => { - const { getTenantExtra } = authStore; + if (!this.currentTariffStatusStore || !this.currentQuotaStore) return; + + const { fetchPortalQuota } = this.currentQuotaStore; + const { fetchPortalTariff } = this.currentTariffStatusStore; this.setIsUpdatingBasicSettings(true); try { - await getTenantExtra(); + await Promise.all([fetchPortalTariff(), fetchPortalQuota()]); } catch (e) { toastr.error(t("Common:UnexpectedError")); @@ -247,7 +250,10 @@ class PaymentStore { }; standaloneInit = async (t: TTranslation) => { - const { getTenantExtra } = authStore; + if (!this.currentTariffStatusStore || !this.currentQuotaStore) return; + + const { fetchPortalTariff } = this.currentTariffStatusStore; + const { fetchPortalQuota } = this.currentQuotaStore; if (this.isInitPaymentPage) { this.standaloneBasicSettings(t); @@ -256,7 +262,11 @@ class PaymentStore { } try { - await Promise.all([this.getSettingsPayment(), getTenantExtra()]); + await Promise.all([ + this.getSettingsPayment(), + fetchPortalTariff(), + fetchPortalQuota(), + ]); } catch (error) { toastr.error(t("Common:UnexpectedError")); console.error(error); @@ -317,14 +327,17 @@ class PaymentStore { acceptPaymentsLicense = async (t: TTranslation) => { try { - const { getTenantExtra } = authStore; - await acceptLicense(); toastr.success(t("ActivateLicenseActivated")); localStorage.removeItem("enterpriseAlertClose"); - await getTenantExtra(); + if (!this.currentTariffStatusStore || !this.currentQuotaStore) return; + + const { fetchPortalTariff } = this.currentTariffStatusStore; + const { fetchPortalQuota } = this.currentQuotaStore; + + await Promise.all([fetchPortalTariff(), fetchPortalQuota()]); } catch (e) { toastr.error(e as TData); } diff --git a/packages/shared/store/CurrentQuotaStore.ts b/packages/shared/store/CurrentQuotaStore.ts index 2e3597efd1..8fb7dd5e56 100644 --- a/packages/shared/store/CurrentQuotaStore.ts +++ b/packages/shared/store/CurrentQuotaStore.ts @@ -338,7 +338,7 @@ class CurrentQuotasStore { }); }; - fetchPortalQuota = async (refresh: boolean) => { + fetchPortalQuota = async (refresh?: boolean) => { return api.portal.getPortalQuota(refresh).then((res) => { this.setPortalQuotaValue(res); diff --git a/packages/shared/store/CurrentTariffStatusStore.ts b/packages/shared/store/CurrentTariffStatusStore.ts index cc85b0ad87..287f5abc96 100644 --- a/packages/shared/store/CurrentTariffStatusStore.ts +++ b/packages/shared/store/CurrentTariffStatusStore.ts @@ -165,6 +165,8 @@ class CurrentTariffStatusStore { fetchPortalTariff = async (refresh?: boolean) => { return api.portal.getPortalTariff(refresh).then((res) => { + if (!res) return; + this.portalTariffStatus = res; this.setIsLoaded(true); });