Merge branch '15856-illegal-chars-warning'
[arvados-workbench2.git] / src / store / collections / collection-create-actions.ts
index f4375688141cdc5eb3873321eaac01c22c895024..e077b2a5b33c47b717630baf51c2f83b7bb600a7 100644 (file)
@@ -3,8 +3,9 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { Dispatch } from "redux";
-import { reset, startSubmit, stopSubmit, initialize } from 'redux-form';
+import { reset, startSubmit, stopSubmit, initialize, FormErrors } from 'redux-form';
 import { RootState } from '~/store/store';
+import { getUserUuid } from "~/common/getuser";
 import { dialogActions } from "~/store/dialog/dialog-actions";
 import { ServiceRepository } from '~/services/services';
 import { getCommonResourceServiceError, CommonResourceServiceError } from "~/services/common-service/common-resource-service";
@@ -28,7 +29,8 @@ export const openCollectionCreateDialog = (ownerUuid: string) =>
         const router = getState();
         const properties = getState().properties;
         if (isItemNotInProject(properties) || !isProjectOrRunProcessRoute(router)) {
-            const userUuid = getState().auth.user!.uuid;
+            const userUuid = getUserUuid(getState());
+            if (!userUuid) { return; }
             dispatch(initialize(COLLECTION_CREATE_FORM_NAME, { userUuid }));
         } else {
             dispatch(initialize(COLLECTION_CREATE_FORM_NAME, { ownerUuid }));
@@ -40,7 +42,7 @@ export const openCollectionCreateDialog = (ownerUuid: string) =>
 export const createCollection = (data: CollectionCreateFormDialogData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(startSubmit(COLLECTION_CREATE_FORM_NAME));
-        let newCollection: CollectionResource | null = null;
+        let newCollection: CollectionResource;
         try {
             dispatch(progressIndicatorActions.START_WORKING(COLLECTION_CREATE_FORM_NAME));
             newCollection = await services.collectionService.create(data);
@@ -51,8 +53,8 @@ export const createCollection = (data: CollectionCreateFormDialogData) =>
             return newCollection;
         } catch (e) {
             const error = getCommonResourceServiceError(e);
-            if (error === CommonResourceServiceError.UNIQUE_VIOLATION) {
-                dispatch(stopSubmit(COLLECTION_CREATE_FORM_NAME, { name: 'Collection with the same name already exists.' }));
+            if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) {
+                dispatch(stopSubmit(COLLECTION_CREATE_FORM_NAME, { name: 'Collection with the same name already exists.' } as FormErrors));
             } else if (error === CommonResourceServiceError.NONE) {
                 dispatch(stopSubmit(COLLECTION_CREATE_FORM_NAME));
                 dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_CREATE_FORM_NAME }));