X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/05d13a8a142ccab6425905bd6706ba77cb5f06dd..540750a7749cb71ea0a8fde4b7a3689eeaa1c3dd:/src/store/collections/creator/collection-creator-action.ts diff --git a/src/store/collections/creator/collection-creator-action.ts b/src/store/collections/creator/collection-creator-action.ts index 2f2b8385..8c35ffa8 100644 --- a/src/store/collections/creator/collection-creator-action.ts +++ b/src/store/collections/creator/collection-creator-action.ts @@ -6,8 +6,10 @@ import { default as unionize, ofType, UnionOf } from "unionize"; import { Dispatch } from "redux"; import { RootState } from "../../store"; -import { CollectionResource } from '../../../models/collection'; -import { ServiceRepository } from "../../../services/services"; +import { CollectionResource } from '~/models/collection'; +import { ServiceRepository } from "~/services/services"; +import { uploadCollectionFiles } from '../uploader/collection-uploader-actions'; +import { reset } from "redux-form"; export const collectionCreateActions = unionize({ OPEN_COLLECTION_CREATOR: ofType<{ ownerUuid: string }>(), @@ -19,14 +21,17 @@ export const collectionCreateActions = unionize({ value: 'payload' }); -export const createCollection = (collection: Partial) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { +export type CollectionCreateAction = UnionOf; + +export const createCollection = (collection: Partial, files: File[]) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const { ownerUuid } = getState().collections.creator; const collectiontData = { ownerUuid, ...collection }; dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData)); - return services.collectionService - .create(collectiontData) - .then(collection => dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection))); + const newCollection = await services.collectionService.create(collectiontData); + await dispatch(uploadCollectionFiles(newCollection.uuid)); + dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection)); + dispatch(reset('collectionCreateDialog')); + return newCollection; }; -export type CollectionCreateAction = UnionOf;