Add multiple files uploading
[arvados-workbench2.git] / src / store / collections / creator / collection-creator-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { default as unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
7
8 import { RootState } from "../../store";
9 import { CollectionResource } from '../../../models/collection';
10 import { ServiceRepository } from "../../../services/services";
11
12 export const collectionCreateActions = unionize({
13     OPEN_COLLECTION_CREATOR: ofType<{ ownerUuid: string }>(),
14     CLOSE_COLLECTION_CREATOR: ofType<{}>(),
15     CREATE_COLLECTION: ofType<{}>(),
16     CREATE_COLLECTION_SUCCESS: ofType<{}>(),
17 }, {
18     tag: 'type',
19     value: 'payload'
20 });
21
22 export const createCollection = (collection: Partial<CollectionResource>) =>
23     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24         const { ownerUuid } = getState().collections.creator;
25         const collectiontData = { ownerUuid, ...collection };
26         dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData));
27         return services.collectionService
28             .create(collectiontData)
29             .then(collection => {
30                 dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection));
31                 return collection;
32             });
33     };
34
35 export type CollectionCreateAction = UnionOf<typeof collectionCreateActions>;