Skip to content

Commit

Permalink
Merge pull request #1214 from internxt/bugfix/PB-2426-user-cant-uploa…
Browse files Browse the repository at this point in the history
…d-20GB-files-in-workspaces

[PB-2426] bugfix/User can't upload a 20GB file to drive
  • Loading branch information
CandelR authored Jul 30, 2024
2 parents 7a7beb0 + 7fb5958 commit 2317ff2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useAppDispatch, useAppSelector } from 'app/store/hooks';
import BaseDialog from 'app/shared/components/BaseDialog/BaseDialog';
import { uiActions } from 'app/store/slices/ui';
import navigationService from 'app/core/services/navigation.service';
import { AppView } from 'app/core/types';
import { useTranslationContext } from 'app/i18n/provider/TranslationProvider';
import DriveStorageError from '../../../../assets/images/drive-error.svg';
import BaseDialog from 'app/shared/components/BaseDialog/BaseDialog';
import Button from 'app/shared/components/Button/Button';
import { useAppDispatch, useAppSelector } from 'app/store/hooks';
import { uiActions } from 'app/store/slices/ui';
import DriveStorageError from '../../../../assets/images/drive-error.svg';

const ReachedPlanLimitDialog = (): JSX.Element => {
const { translate } = useTranslationContext();
Expand All @@ -26,7 +26,7 @@ const ReachedPlanLimitDialog = (): JSX.Element => {
};

return (
<BaseDialog hideCloseButton isOpen={isOpen} onClose={onClose}>
<BaseDialog hideCloseButton isOpen={isOpen} onClose={onClose} bgColor="bg-surface">
<div className="px-5 pb-5">
<img className="mx-auto mb-5" src={DriveStorageError} />
<div className="mb-2">
Expand Down
25 changes: 20 additions & 5 deletions src/app/store/slices/storage/storage.thunks/uploadItemsThunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ const showEmptyFilesNotification = (zeroLengthFilesNumber: number) => {
}
};

const isUploadAllowed = ({ state, files, dispatch }: { state: RootState; files: File[]; dispatch }): boolean => {
const isUploadAllowed = ({
state,
files,
dispatch,
isWorkspaceSelected,
}: {
state: RootState;
files: File[];
dispatch;
isWorkspaceSelected: boolean;
}): boolean => {
try {
const planLimit = state.plan.planLimit;
const planUsage = state.plan.planUsage;
const planLimit = isWorkspaceSelected ? state.plan.businessPlanLimit : state.plan.planLimit;
const planUsage = isWorkspaceSelected ? state.plan.businessPlanUsage : state.plan.planUsage;
const uploadItemsSize = Object.values(files).reduce((acum, file) => acum + file.size, 0);
const totalItemsSize = uploadItemsSize + planUsage;
const isPlanSizeLimitExceeded = planLimit && totalItemsSize >= planLimit;
Expand Down Expand Up @@ -176,7 +186,12 @@ export const uploadItemsThunk = createAsyncThunk<void, UploadItemsPayload, { sta
};
}

const continueWithUpload = isUploadAllowed({ state: getState(), files, dispatch });
const continueWithUpload = isUploadAllowed({
state: getState(),
files,
dispatch,
isWorkspaceSelected: !!workspaceId,
});
if (!continueWithUpload) return;

const { filesToUpload, zeroLengthFilesNumber } = await prepareFilesToUpload({
Expand Down Expand Up @@ -293,7 +308,7 @@ export const uploadSharedItemsThunk = createAsyncThunk<void, UploadSharedItemsPa
const teamId = selectedWorkspace?.workspace.defaultTeamId;
const options = { ...DEFAULT_OPTIONS, ...payloadOptions };

const continueWithUpload = isUploadAllowed({ state: state, files, dispatch });
const continueWithUpload = isUploadAllowed({ state: state, files, dispatch, isWorkspaceSelected: !!workspaceId });
if (!continueWithUpload) return;

let zeroLengthFilesNumber = 0;
Expand Down

0 comments on commit 2317ff2

Please sign in to comment.