Handling quota limit error (#437)

This commit is contained in:
Montassar Ghanmy
2024-03-26 09:04:36 +01:00
committed by GitHub
parent 389d42fe4f
commit cb5a2ad3b7
14 changed files with 235 additions and 35 deletions
@@ -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) {