-export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean) =>
- async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
- let errorMessage = '';
- let successMessage = '';
- try {
- if (isTrashed) {
- errorMessage = "Could not restore project from trash";
- successMessage = "Restored from trash";
- await services.groupsService.untrash(uuid);
- dispatch<any>(navigateTo(uuid));
- dispatch<any>(activateSidePanelTreeItem(uuid));
- } else {
- errorMessage = "Could not move project to trash";
- successMessage = "Added to trash";
- await services.groupsService.trash(uuid);
- dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
- dispatch<any>(navigateTo(ownerUuid));
+export const toggleProjectTrashed =
+ (uuid: string, ownerUuid: string, isTrashed: boolean, isMulti: boolean) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
+ let errorMessage = "";
+ let successMessage = "";
+ let untrashedResource;
+ try {
+ if (isTrashed) {
+ errorMessage = "Could not restore project from trash";
+ successMessage = "Restored project from trash";
+ untrashedResource = await services.groupsService.untrash(uuid);
+ dispatch<any>(isMulti || !untrashedResource ? navigateToTrash : navigateTo(uuid));
+ dispatch<any>(activateSidePanelTreeItem(uuid));
+ } else {
+ errorMessage = "Could not move project to trash";
+ successMessage = "Added project to trash";
+ await services.groupsService.trash(uuid);
+ dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
+
+ const { location } = getState().router;
+ if (matchSharedWithMeRoute(location ? location.pathname : "")) {
+ dispatch(sharedWithMePanelActions.REQUEST_ITEMS());
+ }
+ else {
+ dispatch<any>(navigateTo(ownerUuid));
+ }
+ }
+ if (untrashedResource) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: successMessage,
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ })
+ );
+ }
+ } catch (e) {
+ if (e.status === 422) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Could not restore project from trash: Duplicate name at destination",
+ kind: SnackbarKind.ERROR,
+ })
+ );
+ } else {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: errorMessage,
+ kind: SnackbarKind.ERROR,
+ })
+ );
+ }