1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { default as unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
8 import { RootState } from "../../store";
9 import { CollectionResource } from '../../../models/collection';
10 import { ServiceRepository } from "../../../services/services";
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<{}>(),
22 export const createCollection = (collection: Partial<CollectionResource>) =>
23 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24 const { ownerUuid } = getState().collectionCreation.creator;
25 const collectiontData = { ownerUuid, ...collection };
26 dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData));
27 return services.collectionService
28 .create(collectiontData)
29 .then(collection => dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection)));
32 export type CollectionCreateAction = UnionOf<typeof collectionCreateActions>;