diff --git a/packages/client/src/store/PaymentStore.ts b/packages/client/src/store/PaymentStore.ts index 8ff02209b1..cef7ca0a64 100644 --- a/packages/client/src/store/PaymentStore.ts +++ b/packages/client/src/store/PaymentStore.ts @@ -127,12 +127,12 @@ class PaymentStore { basicSettings = async () => { if (!this.currentTariffStatusStore || !this.currentQuotaStore) return; - const { setPortalTariff, setPayerInfo } = this.currentTariffStatusStore; + const { fetchPortalTariff, setPayerInfo } = this.currentTariffStatusStore; const { addedManagersCount } = this.currentQuotaStore; this.setIsUpdatingBasicSettings(true); - const requests = [setPortalTariff()]; + const requests = [fetchPortalTariff()]; if (this.isAlreadyPaid) requests.push(this.setPaymentAccount()); else requests.push(this.getBasicPaymentLink(addedManagersCount)); diff --git a/packages/client/src/store/StorageManagement.js b/packages/client/src/store/StorageManagement.js index 2754b05403..e1eeaf75ac 100644 --- a/packages/client/src/store/StorageManagement.js +++ b/packages/client/src/store/StorageManagement.js @@ -145,7 +145,7 @@ class StorageManagement { }; updateQuotaInfo = async (type) => { - const { getTenantExtra } = this.authStore; + const { fetchPortalQuota } = this.currentQuotaStore; const { getFilesListItems } = this.filesStore; const { usersStore } = this.peopleStore; const { getPeopleListItem } = usersStore; @@ -156,7 +156,7 @@ class StorageManagement { const roomFilterData = RoomsFilter.getDefault(); roomFilterData.pageCount = FILTER_COUNT; - const requests = [getTenantExtra()]; + const requests = [fetchPortalQuota()]; type === "user" ? requests.push(getUserList(userFilterData)) diff --git a/packages/shared/store/AuthStore.ts b/packages/shared/store/AuthStore.ts index f5fda214ed..d1fe28516f 100644 --- a/packages/shared/store/AuthStore.ts +++ b/packages/shared/store/AuthStore.ts @@ -226,25 +226,37 @@ class AuthStore { return this.tenantExtra?.opensource; } + fetchTenantExtra = (refresh: boolean) => { + return getPortalTenantExtra(refresh).then((result) => { + if (!result) return; + + const { tariff, quota, ...tenantExtra } = result; + + this.tenantExtra = tenantExtra; + }); + }; + getTenantExtra = async () => { let refresh = false; + if (window.location.search === "?complete=true") { window.history.replaceState({}, document.title, window.location.pathname); refresh = true; } + const user = this.userStore?.user?.isVisitor; - const result = await getPortalTenantExtra(refresh); + const request = []; - if (!result) return; + request.push(this.currentTariffStatusStore?.fetchPortalTariff(refresh)); - const { tariff, quota, ...tenantExtra } = result; + if (!user) { + request.push( + this.currentQuotaStore?.fetchPortalQuota(refresh), + this.fetchTenantExtra(refresh), + ); + } - runInAction(() => { - this.tenantExtra = { ...tenantExtra }; - }); - - this.currentQuotaStore?.setPortalQuotaValue(quota); - this.currentTariffStatusStore?.setPortalTariffValue(tariff); + await Promise.all(request); }; setLanguage() { diff --git a/packages/shared/store/CurrentQuotaStore.ts b/packages/shared/store/CurrentQuotaStore.ts index 9d242a51df..2e3597efd1 100644 --- a/packages/shared/store/CurrentQuotaStore.ts +++ b/packages/shared/store/CurrentQuotaStore.ts @@ -338,18 +338,12 @@ class CurrentQuotasStore { }); }; - setPortalQuota = async () => { - try { - const res = await api.portal.getPortalQuota(); - - if (!res) return; - + fetchPortalQuota = async (refresh: boolean) => { + return api.portal.getPortalQuota(refresh).then((res) => { this.setPortalQuotaValue(res); this.setIsLoaded(true); - } catch (e) { - toastr.error(e as TData); - } + }); }; setUserQuota = async (quota: string | number, t: (key: string) => string) => { diff --git a/packages/shared/store/CurrentTariffStatusStore.ts b/packages/shared/store/CurrentTariffStatusStore.ts index 424d065ad4..cc85b0ad87 100644 --- a/packages/shared/store/CurrentTariffStatusStore.ts +++ b/packages/shared/store/CurrentTariffStatusStore.ts @@ -163,19 +163,10 @@ class CurrentTariffStatusStore { return getDaysLeft(this.dueDate); } - setPortalTariffValue = async (res: TPortalTariff) => { - this.portalTariffStatus = res; - - this.setIsLoaded(true); - }; - - setPortalTariff = async () => { - const res = await api.portal.getPortalTariff(); - - if (!res) return; - - runInAction(() => { + fetchPortalTariff = async (refresh?: boolean) => { + return api.portal.getPortalTariff(refresh).then((res) => { this.portalTariffStatus = res; + this.setIsLoaded(true); }); }; }