✨ Handling quota limit error (#437)
This commit is contained in:
@@ -235,6 +235,9 @@
|
||||
"compenents.VersionModalContent_donwload":"Download",
|
||||
"hooks.use-drive-actions.unable_load_file":"Unable to load your files.",
|
||||
"hooks.use-drive-actions.unable_create_file":"Unable to create a new file.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_title":"You're out of storage",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_message":"You have reached the limit of your storage. Please, delete some files to vacate more space and have access to all features of Twake Drive.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_plans": "Our solution is now free for all users, but additional plans are coming soon.",
|
||||
"hooks.use-drive-actions.unable_download_file":"Unable to download this files.",
|
||||
"hooks.use-drive-actions.unable_remove_file":"Unable to remove this file.",
|
||||
"hooks.use-drive-actions.unable_restore_file":"Unable to restore this item.",
|
||||
|
||||
@@ -218,6 +218,9 @@
|
||||
"compenents.VersionModalContent_donwload": "Télécharger",
|
||||
"hooks.use-drive-actions.unable_load_file": "Impossible de charger cet élément",
|
||||
"hooks.use-drive-actions.unable_create_file": "Impossible de créer ce fichier",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_title": "Vous avez épuisé votre espace de stockage",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_message": "Vous avez atteint la limite de votre espace de stockage. Veuillez supprimer certains fichiers pour libérer plus d'espace et avoir accès à toutes les fonctionnalités de Twake Drive.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_plans": "Notre solution est désormais gratuite pour tous les utilisateurs, mais des plans supplémentaires seront bientôt disponibles.",
|
||||
"hooks.use-drive-actions.unable_download_file": "Impossible de télécharger ce fichier",
|
||||
"hooks.use-drive-actions.unable_remove_file": "Impossible de supprimer ce fichier",
|
||||
"hooks.use-drive-actions.unable_restore_file": "Impossible de restaurer cet élément.",
|
||||
|
||||
@@ -218,6 +218,9 @@
|
||||
"compenents.VersionModalContent_donwload":"Download",
|
||||
"hooks.use-drive-actions.unable_load_file":"Unable to load your files.",
|
||||
"hooks.use-drive-actions.unable_create_file":"Unable to create a new file.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_title": "У вас закончилось место для хранения",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_message": "Вы достигли предела вашего места для хранения. Пожалуйста, удалите некоторые файлы, чтобы освободить больше места и получить доступ ко всем функциям Twake Drive.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_plans": "Наше решение теперь бесплатно для всех пользователей, но скоро будут доступны дополнительные планы.",
|
||||
"hooks.use-drive-actions.unable_download_file":"Unable to download this files.",
|
||||
"hooks.use-drive-actions.unable_remove_file":"Unable to remove this file.",
|
||||
"hooks.use-drive-actions.unable_restore_file":"Unable to restore this item.",
|
||||
|
||||
@@ -234,6 +234,9 @@
|
||||
"compenents.VersionModalContent_donwload": "Tải xuống",
|
||||
"hooks.use-drive-actions.unable_load_file": "Không thể tải tệp của bạn.",
|
||||
"hooks.use-drive-actions.unable_create_file": "Không thể tạo tệp mới.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_title": "Bạn đã hết dung lượng lưu trữ",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_message": "Bạn đã đạt đến giới hạn dung lượng lưu trữ của mình. Vui lòng xóa một số tệp để giải phóng thêm không gian và truy cập vào tất cả các tính năng của Twake Drive.",
|
||||
"hooks.use-drive-actions.quota_limit_exceeded_plans": "Giải pháp của chúng tôi hiện đã miễn phí cho tất cả người dùng, nhưng các gói bổ sung sẽ sớm có mặt.",
|
||||
"hooks.use-drive-actions.unable_download_file": "Không thể tải xuống các tệp này.",
|
||||
"hooks.use-drive-actions.unable_remove_file": "Không thể xóa tệp này.",
|
||||
"hooks.use-drive-actions.unable_restore_file": "Không thể khôi phục mục này.",
|
||||
|
||||
@@ -102,13 +102,23 @@ export class DriveApiClient {
|
||||
data: { item: Partial<DriveItem>; version?: Partial<DriveItemVersion> },
|
||||
) {
|
||||
if (!data.version) data.version = {} as Partial<DriveItemVersion>;
|
||||
return await Api.post<
|
||||
{ item: Partial<DriveItem>; version: Partial<DriveItemVersion> },
|
||||
DriveItem
|
||||
>(
|
||||
`/internal/services/documents/v1/companies/${companyId}/item${appendTdriveToken()}`,
|
||||
data as { item: Partial<DriveItem>; version: Partial<DriveItemVersion> },
|
||||
);
|
||||
|
||||
return new Promise<DriveItem>((resolve, reject) => {
|
||||
Api.post<
|
||||
{ item: Partial<DriveItem>; version: Partial<DriveItemVersion> },
|
||||
DriveItem
|
||||
>(
|
||||
`/internal/services/documents/v1/companies/${companyId}/item${appendTdriveToken()}`,
|
||||
data as { item: Partial<DriveItem>; version: Partial<DriveItemVersion> },
|
||||
(res) => {
|
||||
if ((res as any)?.statusCode || (res as any)?.error) {
|
||||
reject(res);
|
||||
}
|
||||
|
||||
resolve(res);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
static async createVersion(companyId: string, id: string, version: Partial<DriveItemVersion>) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { DriveItemAtom, DriveItemChildrenAtom } from '../state/store';
|
||||
import { BrowseFilter, DriveItem, DriveItemVersion } from '../types';
|
||||
import { SharedWithMeFilterState } from '../state/shared-with-me-filter';
|
||||
import Languages from 'features/global/services/languages-service';
|
||||
import { useUserQuota } from "features/users/hooks/use-user-quota";
|
||||
import { useUserQuota } from 'features/users/hooks/use-user-quota';
|
||||
|
||||
/**
|
||||
* Returns the children of a drive item
|
||||
@@ -48,17 +48,30 @@ export const useDriveActions = () => {
|
||||
|
||||
const create = useCallback(
|
||||
async (item: Partial<DriveItem>, version: Partial<DriveItemVersion>) => {
|
||||
if (!item || !version) throw new Error("All ");
|
||||
let driveFile = null;
|
||||
if (!item || !version) throw new Error('All ');
|
||||
if (!item.company_id) item.company_id = companyId;
|
||||
|
||||
try {
|
||||
driveFile = await DriveApiClient.create(companyId, { item, version });
|
||||
await refresh(driveFile.parent_id!);
|
||||
const driveFile = await DriveApiClient.create(companyId, { item, version });
|
||||
|
||||
await refresh(driveFile.parent_id);
|
||||
await getQuota();
|
||||
} catch (e) {
|
||||
ToasterService.error(Languages.t('hooks.use-drive-actions.unable_create_file'));
|
||||
|
||||
return driveFile;
|
||||
} catch (e: any) {
|
||||
if (e.statusCode === 403) {
|
||||
ToasterService.info(
|
||||
<>
|
||||
<p>{Languages.t('hooks.use-drive-actions.quota_limit_exceeded_title')}</p>
|
||||
<p>{Languages.t('hooks.use-drive-actions.quota_limit_exceeded_message')}</p>
|
||||
<p>{Languages.t('hooks.use-drive-actions.quota_limit_exceeded_plans')}</p>
|
||||
</>,
|
||||
);
|
||||
} else {
|
||||
ToasterService.error(Languages.t('hooks.use-drive-actions.unable_create_file'));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return driveFile;
|
||||
},
|
||||
[refresh],
|
||||
);
|
||||
@@ -132,8 +145,8 @@ export const useDriveActions = () => {
|
||||
const updateBody = {
|
||||
company_id: companyId,
|
||||
user_id: userId,
|
||||
level: level
|
||||
}
|
||||
level: level,
|
||||
};
|
||||
await DriveApiClient.updateLevel(companyId, id, updateBody);
|
||||
await refresh(id || '');
|
||||
} catch (e) {
|
||||
|
||||
@@ -151,7 +151,7 @@ export default class Api {
|
||||
requestType?: 'post' | 'get' | 'put' | 'delete';
|
||||
} = {},
|
||||
): Promise<Response> {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
Requests.request(
|
||||
options.requestType ? options.requestType : 'post',
|
||||
new URL(route, Globals.api_root_url).toString(),
|
||||
|
||||
@@ -142,9 +142,9 @@ class UserAPIClientService {
|
||||
});
|
||||
}
|
||||
|
||||
async getQuota(userId: string): Promise<UserQuota> {
|
||||
async getQuota(companyId: string, userId: string): Promise<UserQuota> {
|
||||
return Api.get<UserQuota>(
|
||||
`/internal/services/users/v1/users/${userId}/quota`,
|
||||
`/internal/services/users/v1/users/${userId}/quota?companyId=${companyId}`,
|
||||
undefined,
|
||||
false
|
||||
).then(result => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import UserAPIClient from '@features/users/api/user-api-client';
|
||||
import { useCurrentUser } from "features/users/hooks/use-current-user";
|
||||
import { atom, useRecoilState } from "recoil";
|
||||
import useRouteState from "app/features/router/hooks/use-route-state";
|
||||
import useRouterCompany from "app/features/router/hooks/use-router-company";
|
||||
|
||||
export const QuotaState = atom<UserQuota>({
|
||||
key: 'QuotaState',
|
||||
@@ -22,13 +23,14 @@ export const useUserQuota = () => {
|
||||
}
|
||||
const { appName } = useRouteState();
|
||||
const isPublic = appName === 'drive';
|
||||
const companyId = useRouterCompany();
|
||||
const { user } = isPublic ? { user: null } : useCurrentUser();
|
||||
const [quota, setQuota] = useRecoilState(QuotaState);
|
||||
|
||||
const getQuota = useCallback(async () => {
|
||||
let data: UserQuota = nullQuota;
|
||||
if (user && user?.id) {
|
||||
data = await UserAPIClient.getQuota(user.id);
|
||||
data = await UserAPIClient.getQuota(companyId, user.id);
|
||||
} else {
|
||||
data = nullQuota;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user