This repository was archived by the owner on Dec 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontainer.js
80 lines (68 loc) · 2.2 KB
/
container.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* External dependencies
*/
import { connect } from 'react-redux';
import { compose, bindActionCreators } from 'redux';
/**
* Internal dependencies
*/
import EventVenue from './template';
import { toVenue } from 'elements';
import { withStore, withSaveData, withDetails, withForm } from 'editor/hoc';
import { actions, selectors } from 'data/blocks/venue';
import { VENUE } from 'editor/post-types';
const setVenue = ( dispatch ) => ( id ) => {
const { setVenue, setShowMap, setShowMapLink } = actions;
dispatch( setVenue( id ) );
dispatch( setShowMap( true ) );
dispatch( setShowMapLink( true ) );
};
const onFormComplete = ( dispatch, ownProps ) => ( body ) => {
const { setDetails } = ownProps;
const { id } = body;
setDetails( id, body );
setVenue( dispatch )( id );
};
const onFormSubmit = ( dispatch, ownProps ) => ( fields ) => (
ownProps.sendForm( toVenue( fields ), onFormComplete( dispatch, ownProps ) )
);
const onItemSelect = ( dispatch ) => setVenue( dispatch );
const onCreateNew = ( ownProps ) => ( title ) => ownProps.createDraft( {
title: {
rendered: title,
},
} );
// TODO: need to remove the use of "maybe" functions as they hold logic they
// ultimately should not.
const removeVenue = ( dispatch, ownProps ) => () => {
const { volatile, maybeRemoveEntry, details } = ownProps;
dispatch( actions.removeVenue() );
if ( volatile ) {
maybeRemoveEntry( details );
}
};
const editVenue = ( ownProps ) => () => {
const { details, editEntry } = ownProps;
editEntry( details );
};
const mapStateToProps = ( state ) => ( {
venue: selectors.getVenue( state ),
showMapLink: selectors.getshowMapLink( state ),
showMap: selectors.getshowMap( state ),
} );
const mapDispatchToProps = ( dispatch, ownProps ) => ( {
...bindActionCreators( actions, dispatch ),
onFormSubmit: onFormSubmit( dispatch, ownProps ),
onItemSelect: onItemSelect( dispatch ),
onCreateNew: onCreateNew( ownProps ),
removeVenue: removeVenue( dispatch, ownProps ),
editVenue: editVenue( ownProps ),
} );
export default compose(
withStore( { postType: VENUE } ),
connect( mapStateToProps ),
withDetails( 'venue' ),
withForm( ( props ) => props.name ),
connect( null, mapDispatchToProps ),
withSaveData(),
)( EventVenue );