🕹 Manage root users

🕹 Manage root users
This commit is contained in:
Montassar Ghanmy
2023-08-28 09:23:52 +01:00
committed by GitHub
parent 832ab8ac90
commit 84270a31e2
29 changed files with 410 additions and 45 deletions
@@ -6,7 +6,7 @@ import { DriveApiClient } from '../api-client/api-client';
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 Languages from 'features/global/services/languages-service';
/**
* Returns the children of a drive item
@@ -21,7 +21,7 @@ export const useDriveActions = () => {
({ set, snapshot }) =>
async (parentId: string) => {
if (parentId) {
const filter:BrowseFilter = {
const filter: BrowseFilter = {
company_id: companyId,
mime_type: sharedFilter.mimeType.value,
};
@@ -110,5 +110,22 @@ export const useDriveActions = () => {
[refresh],
);
return { create, refresh, download, downloadZip, remove, update };
const updateLevel = useCallback(
async (id: string, userId: string, level: string) => {
try {
const updateBody = {
company_id: companyId,
user_id: userId,
level: level
}
await DriveApiClient.updateLevel(companyId, id, updateBody);
await refresh(id || '');
} catch (e) {
ToasterService.error(Languages.t('hooks.use-drive-actions.unable_update_file'));
}
},
[refresh],
);
return { create, refresh, download, downloadZip, remove, update, updateLevel };
};
@@ -19,7 +19,7 @@ export const useDriveItem = (id: string) => {
const item = useRecoilValue(DriveItemAtom(id));
const children = useRecoilValue(DriveItemChildrenAtom(id));
const [loading, setLoading] = useRecoilState(LoadingStateInitTrue('useDriveItem-' + id));
const { refresh: refreshItem, create, update: _update, remove: _remove } = useDriveActions();
const { refresh: refreshItem, create, update: _update, updateLevel: _updateLevel, remove: _remove } = useDriveActions();
const { uploadVersion: _uploadVersion } = useDriveUpload();
const refresh = useCallback(
@@ -57,6 +57,19 @@ export const useDriveItem = (id: string) => {
[id, setLoading, refresh, item?.item?.parent_id],
);
const updateLevel = useCallback(
async (userId: string, level: string) => {
setLoading(true);
try {
await _updateLevel(id, userId, level);
} catch (e) {
ToasterService.error('Unable to update user access.');
}
setLoading(false);
},
[id, setLoading, refresh, item?.item?.parent_id],
);
const uploadVersion = useCallback(
async (file: File) => {
setLoading(true);
@@ -87,6 +100,7 @@ export const useDriveItem = (id: string) => {
uploadVersion,
create,
update,
updateLevel,
remove,
refresh,
};