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 { collectionService } from '../../../services/services';
10 import { CollectionResource } from '../../../models/collection';
12 export const collectionUpdatorActions = unionize({
13 OPEN_COLLECTION_UPDATOR: ofType<{ ownerUuid: string }>(),
14 CLOSE_COLLECTION_UPDATOR: ofType<{}>(),
15 UPDATE_COLLECTION: ofType<{}>(),
16 UPDATE_COLLECTION_SUCCESS: ofType<{}>(),
22 export const updateCollection = (collection: Partial<CollectionResource>) =>
23 (dispatch: Dispatch, getState: () => RootState) => {
24 const { ownerUuid } = getState().collections.creator;
25 const collectiontData = { ownerUuid, ...collection };
26 dispatch(collectionUpdatorActions.UPDATE_COLLECTION(collectiontData));
27 return collectionService
29 .create(collectiontData)
30 .then(collection => dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS(collection)));
33 export type CollectionUpdatorAction = UnionOf<typeof collectionUpdatorActions>;