import { ApiActions } from "services/api/api-actions";
export class TrashableResourceService<T extends TrashableResource> extends CommonResourceService<T> {
-
constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions, readOnlyFields: string[] = []) {
super(serverApi, resourceType, actions, readOnlyFields);
}
trash(uuid: string): Promise<T> {
- return CommonResourceService.defaultResponse(
- this.serverApi
- .post(this.resourceType + `/${uuid}/trash`),
- this.actions
- );
+ return CommonResourceService.defaultResponse(this.serverApi.post(this.resourceType + `/${uuid}/trash`), this.actions);
}
untrash(uuid: string): Promise<T> {
const params = {
- ensure_unique_name: true
+ ensure_unique_name: true,
};
return CommonResourceService.defaultResponse(
- this.serverApi
- .post(this.resourceType + `/${uuid}/untrash`, {
- params: CommonResourceService.mapKeys(snakeCase)(params)
- }),
- this.actions
+ this.serverApi.post(this.resourceType + `/${uuid}/untrash`, {
+ params: CommonResourceService.mapKeys(snakeCase)(params),
+ }),
+ this.actions,
+ undefined,
+ false
);
}
}
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";
- await services.groupsService.untrash(uuid);
- dispatch<any>(isMulti ? navigateToTrash : navigateTo(uuid));
+ 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";
dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
dispatch<any>(navigateTo(ownerUuid));
}
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: successMessage,
- hideDuration: 2000,
- kind: SnackbarKind.SUCCESS,
- })
- );
+ if (untrashedResource) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: successMessage,
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ })
+ );
+ }
} catch (e) {
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: errorMessage,
- kind: SnackbarKind.ERROR,
- })
- );
+ 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,
+ })
+ );
+ }
}
};
})
);
} catch (e) {
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: errorMessage,
- kind: SnackbarKind.ERROR,
- })
- );
+ if (e.status === 422) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Could not restore collection from trash: Duplicate name at destination",
+ kind: SnackbarKind.ERROR,
+ })
+ );
+ } else {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: errorMessage,
+ kind: SnackbarKind.ERROR,
+ })
+ );
+ }
}
};