Web: Fixed work with changing quota in lists.

This commit is contained in:
Tatiana Lopaeva 2023-11-29 16:53:57 +03:00
parent 315c0392e2
commit 94bffa1364
7 changed files with 47 additions and 40 deletions

View File

@ -19,7 +19,6 @@ const ChangeQuotaEvent = (props) => {
successCallback,
abortCallback,
initialSize,
filter,
} = props;
const { t } = useTranslation("Common");
const [isLoading, setIsLoading] = useState(false);
@ -32,7 +31,7 @@ const ChangeQuotaEvent = (props) => {
const updateFunction = (size) => {
return type === "user"
? updateUserQuota(size, ids, filter)
? updateUserQuota(size, ids)
: updateRoomQuota(size, ids);
};
const onSaveClick = async () => {
@ -88,14 +87,13 @@ const ChangeQuotaEvent = (props) => {
};
export default inject(({ peopleStore, filesStore, auth }, { type }) => {
const { usersStore, filterStore } = peopleStore;
const { usersStore } = peopleStore;
const { updateUserQuota } = usersStore;
const { updateRoomQuota } = filesStore;
const { currentQuotaStore } = auth;
const { defaultUsersQuota, defaultRoomsQuota } = currentQuotaStore;
const initialSize = type === "user" ? defaultUsersQuota : defaultRoomsQuota;
const filter = type === "user" ? filterStore.filter : null;
return { initialSize, updateUserQuota, updateRoomQuota, filter };
return { initialSize, updateUserQuota, updateRoomQuota };
})(observer(ChangeQuotaEvent));

View File

@ -9,17 +9,6 @@ import toastr from "@docspace/components/toast/toastr";
import { StyledBody, StyledText } from "./StyledComponent";
const getSelectedOption = (options, action) => {
const option = options.find((elem) => elem.action === action);
if (option.key === "no-quota") {
option.label = "Unlimited";
return option;
}
return option;
};
const SpaceQuota = (props) => {
const {
hideColumns,
@ -31,23 +20,21 @@ const SpaceQuota = (props) => {
onSuccess,
disableQuota,
resetQuota,
defaultSize,
} = props;
const [action, setAction] = useState(
item?.quotaLimit === -1 ? "no-quota" : "current-size"
);
const [isLoading, setIsLoading] = useState(false);
const { t } = useTranslation(["Common"]);
const usedQuota = getConvertedQuota(t, item?.usedSpace);
const spaceLimited = getConvertedQuota(t, item?.quotaLimit);
const defaultQuotaSize = getConvertedQuota(t, defaultSize);
const options = [
{
id: "info-account-quota_edit",
key: "change-quota",
label: "Change quota",
label: t("Common:ChangeQuota"),
action: "change",
},
{
@ -59,7 +46,10 @@ const SpaceQuota = (props) => {
{
id: "info-account-quota_no-quota",
key: "no-quota",
label: "Disable quota",
label:
item?.quotaLimit === -1
? t("Common:Unlimited")
: t("Common:DisableQuota"),
action: "no-quota",
},
];
@ -68,7 +58,7 @@ const SpaceQuota = (props) => {
options?.splice(1, 0, {
id: "info-account-quota_no-quota",
key: "default-quota",
label: "Set to default",
label: t("Common:SetToDefault"),
action: "default",
});
@ -87,12 +77,14 @@ const SpaceQuota = (props) => {
changeQuota([item], successCallback, abortCallback);
setAction("current-size");
return;
}
if (action === "no-quota") {
options.map((item) => {
if (item.key === "no-quota") item.label = t("Common:Unlimited");
});
try {
await disableQuota(-1, [item.id]);
toastr.success(t("Common:StorageQuotaDisabled"));
@ -100,11 +92,13 @@ const SpaceQuota = (props) => {
toastr.error(e);
}
setAction("no-quota");
return;
}
options.map((item) => {
if (item.key === "default-quota") item.label = defaultQuotaSize;
});
try {
await resetQuota([item.id]);
toastr.success(t("Common:StorageQuotaReset"));
@ -113,7 +107,9 @@ const SpaceQuota = (props) => {
}
};
const selectedOption = getSelectedOption(options, action);
const action = item?.quotaLimit === -1 ? "no-quota" : "current-size";
const selectedOption = options.find((elem) => elem.action === action);
if (withoutLimitQuota) {
return <StyledText fontWeight={600}>{usedQuota}</StyledText>;
@ -153,8 +149,12 @@ export default inject(
const { changeRoomQuota } = filesActionsStore;
const { updateRoomQuota } = filesStore;
const { currentQuotaStore } = auth;
const { isDefaultUsersQuotaSet, isDefaultRoomsQuotaSet } =
currentQuotaStore;
const {
isDefaultUsersQuotaSet,
isDefaultRoomsQuotaSet,
defaultUsersQuota,
defaultRoomsQuota,
} = currentQuotaStore;
const changeQuota = type === "user" ? changeUserQuota : changeRoomQuota;
const disableQuota = type === "user" ? updateUserQuota : updateRoomQuota;
@ -164,11 +164,14 @@ export default inject(
const withoutLimitQuota =
type === "user" ? !isDefaultUsersQuotaSet : !isDefaultRoomsQuotaSet;
const defaultSize = type === "user" ? defaultUsersQuota : defaultRoomsQuota;
return {
withoutLimitQuota,
changeQuota,
disableQuota,
resetQuota,
defaultSize,
};
}
)(observer(SpaceQuota));

View File

@ -1905,7 +1905,7 @@ class FilesActionStore {
return {
id: "menu-change-quota",
key: "change-quota",
label: "Change quota",
label: t("Common:ChangeQuota"),
iconUrl: ChangQuotaReactSvgUrl,
onClick: () => this.changeRoomQuota(selection),
disabled: false,
@ -1927,7 +1927,7 @@ class FilesActionStore {
return {
id: "menu-disable-quota",
key: "disable-quota",
label: "Disable quota",
label: t("Common:DisableQuota"),
iconUrl: DisableQuotaReactSvgUrl,
onClick: () => this.disableRoomQuota(selection, t),
disabled: false,

View File

@ -335,7 +335,7 @@ class PeopleStore {
{
id: "menu-change-quota",
key: "change-quota",
label: "Change quota",
label: t("Common:ChangeQuota"),
disabled: !hasUsersToChangeQuota,
iconUrl: ChangQuotaReactSvgUrl,
onClick: () => this.changeUserQuota(selection),
@ -343,7 +343,7 @@ class PeopleStore {
{
id: "menu-default-quota",
key: "default-quota",
label: "Set to default",
label: t("Common:SetToDefault"),
disabled: !hasUsersToResetQuota,
iconUrl: DefaultQuotaReactSvgUrl,
onClick: () => this.resetUserQuota(selection, t),
@ -351,7 +351,7 @@ class PeopleStore {
{
id: "menu-disable-quota",
key: "disable-quota",
label: "Disable quota",
label: t("Common:DisableQuota"),
disabled: !hasUsersToDisableQuota,
iconUrl: DisableQuotaReactSvgUrl,
onClick: () => this.disableUserQuota(selection, t),

View File

@ -149,18 +149,20 @@ class UsersStore {
return users;
};
updateUserQuota = async (quotaSize, userIds, filter) => {
updateUserQuota = async (quotaSize, userIds) => {
const filter = this.peopleStore.filterStore.filter;
const users = await api.people.setCustomUserQuota(userIds, quotaSize);
await this.getUsersList(filter);
await this.getUsersList(filter, true);
return users;
};
resetUserQuota = async (userIds, filter) => {
resetUserQuota = async (userIds) => {
const filter = this.peopleStore.filterStore.filter;
const users = await api.people.resetUserQuota(userIds);
await this.getUsersList(filter);
await this.getUsersList(filter, true);
return users;
};

View File

@ -560,7 +560,7 @@ export const getConvertedSize = (t, bytes) => {
};
export const getConvertedQuota = (t, bytes) => {
if (bytes === -1) return "Unlimited";
if (bytes === -1) return t("Common:Unlimited");
return getConvertedSize(t, bytes);
};

View File

@ -34,6 +34,7 @@
"CustomQuota": "Custom quota",
"CancelButton": "Cancel",
"ChangeButton": "Change",
"ChangeQuota": "Change quota",
"ChangesSavedSuccessfully": "Changes saved successfully",
"ClearAll": "Clear all",
"ClearFilter": "Clear filter",
@ -104,6 +105,7 @@
"DropzoneTitleLink": "Select new image",
"DropzoneTitleSecondary": "or drop file here",
"Duplicate": "Duplicate",
"DisableQuota": "Disable quota",
"EditButton": "Edit",
"Email": "Email",
"EmptyEmail": "No email address parsed",
@ -284,6 +286,7 @@
"Settings": "Settings",
"SettingsGeneral": "General",
"SettingsPersonal": "Personal",
"SetToDefault": "Set to default",
"ShowMore": "Show more",
"SignInWithApple": "Sign in with Apple",
"Storage": "Storage",
@ -343,6 +346,7 @@
"User": "User",
"UsersInvited": "Users invited",
"UTC": "UTC",
"Unlimited": "Unlimited",
"Version": "Version",
"Video": "Video",
"View": "View",