Extract file-uploader, resotore file upload to collection creator
[arvados-workbench2.git] / src / store / collections / collection-create-actions.ts
index 1981af0d41ddae3e596e926c15cca15ac291eb9b..5a1246a7b0891b4a387cfb7a92dd538b4c34cc8a 100644 (file)
@@ -5,17 +5,16 @@
 import { Dispatch } from "redux";
 import { reset, startSubmit, stopSubmit, initialize } from 'redux-form';
 import { RootState } from '~/store/store';
-import { uploadCollectionFiles } from '~/store/collections/uploader/collection-uploader-actions';
 import { dialogActions } from "~/store/dialog/dialog-actions";
-import { CollectionResource } from '~/models/collection';
 import { ServiceRepository } from '~/services/services';
 import { getCommonResourceServiceError, CommonResourceServiceError } from "~/common/api/common-resource-service";
+import { uploadCollectionFiles } from './collection-upload-actions';
+import { fileUploaderActions } from '~/store/file-uploader/file-uploader-actions';
 
 export interface CollectionCreateFormDialogData {
     ownerUuid: string;
     name: string;
     description: string;
-    files: File[];
 }
 
 export const COLLECTION_CREATE_FORM_NAME = "collectionCreateFormName";
@@ -23,14 +22,15 @@ export const COLLECTION_CREATE_FORM_NAME = "collectionCreateFormName";
 export const openCollectionCreateDialog = (ownerUuid: string) =>
     (dispatch: Dispatch) => {
         dispatch(initialize(COLLECTION_CREATE_FORM_NAME, { ownerUuid }));
+        dispatch(fileUploaderActions.CLEAR_UPLOAD());
         dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_CREATE_FORM_NAME, data: { ownerUuid } }));
     };
 
-export const createCollection = (collection: Partial<CollectionResource>) =>
+export const createCollection = (data: CollectionCreateFormDialogData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(startSubmit(COLLECTION_CREATE_FORM_NAME));
         try {
-            const newCollection = await services.collectionService.create(collection);
+            const newCollection = await services.collectionService.create(data);
             await dispatch<any>(uploadCollectionFiles(newCollection.uuid));
             dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_CREATE_FORM_NAME }));
             dispatch(reset(COLLECTION_CREATE_FORM_NAME));
@@ -42,4 +42,4 @@ export const createCollection = (collection: Partial<CollectionResource>) =>
             }
             return ;
         }
-    };
\ No newline at end of file
+    };