Remove PropTypes errors, fix bug in handling redux action
This commit is contained in:
parent
65cd912ef3
commit
4d7b1ed113
4 changed files with 24 additions and 31 deletions
|
@ -1,4 +1,5 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { browserHistory } from 'react-router';
|
||||||
import * as ActionTypes from '../../../constants';
|
import * as ActionTypes from '../../../constants';
|
||||||
import { startLoader, stopLoader } from './loader';
|
import { startLoader, stopLoader } from './loader';
|
||||||
import { setToastText, showToast } from './toast';
|
import { setToastText, showToast } from './toast';
|
||||||
|
@ -47,20 +48,22 @@ export function createCollection(collection) {
|
||||||
});
|
});
|
||||||
dispatch(stopLoader());
|
dispatch(stopLoader());
|
||||||
|
|
||||||
const collectionName = response.data.name;
|
const newCollection = response.data;
|
||||||
dispatch(setToastText(`Created "${collectionName}"`));
|
dispatch(setToastText(`Created "${newCollection.name}"`));
|
||||||
dispatch(showToast(TOAST_DISPLAY_TIME_MS));
|
dispatch(showToast(TOAST_DISPLAY_TIME_MS));
|
||||||
|
|
||||||
return response.data;
|
const pathname = `/${newCollection.owner.username}/collections/${newCollection.id}`;
|
||||||
|
const location = { pathname, state: { skipSavingPath: true } };
|
||||||
|
|
||||||
|
browserHistory.push(location);
|
||||||
})
|
})
|
||||||
.catch((response) => {
|
.catch((response) => {
|
||||||
|
console.error('Error creating collection', response.data);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionTypes.ERROR,
|
type: ActionTypes.ERROR,
|
||||||
error: response.data
|
error: response.data
|
||||||
});
|
});
|
||||||
dispatch(stopLoader());
|
dispatch(stopLoader());
|
||||||
|
|
||||||
return response.data;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,15 +380,15 @@ Collection.propTypes = {
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
getCollections: PropTypes.func.isRequired,
|
getCollections: PropTypes.func.isRequired,
|
||||||
collection: PropTypes.shape({
|
collection: PropTypes.shape({
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string,
|
||||||
slug: PropTypes.string,
|
slug: PropTypes.string,
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
owner: PropTypes.shape({
|
owner: PropTypes.shape({
|
||||||
username: PropTypes.string.isRequired,
|
username: PropTypes.string,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
items: PropTypes.arrayOf(PropTypes.shape({})),
|
items: PropTypes.arrayOf(PropTypes.shape({})),
|
||||||
}).isRequired,
|
}),
|
||||||
username: PropTypes.string,
|
username: PropTypes.string,
|
||||||
loading: PropTypes.bool.isRequired,
|
loading: PropTypes.bool.isRequired,
|
||||||
toggleDirectionForField: PropTypes.func.isRequired,
|
toggleDirectionForField: PropTypes.func.isRequired,
|
||||||
|
@ -401,7 +401,14 @@ Collection.propTypes = {
|
||||||
};
|
};
|
||||||
|
|
||||||
Collection.defaultProps = {
|
Collection.defaultProps = {
|
||||||
|
username: undefined,
|
||||||
|
collection: {
|
||||||
|
id: undefined,
|
||||||
|
items: [],
|
||||||
|
owner: {
|
||||||
username: undefined
|
username: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state, ownProps) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { browserHistory } from 'react-router';
|
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import * as CollectionsActions from '../../IDE/actions/collections';
|
import * as CollectionsActions from '../../IDE/actions/collections';
|
||||||
|
|
||||||
|
@ -39,19 +38,7 @@ class CollectionCreate extends React.Component {
|
||||||
handleCreateCollection = (event) => {
|
handleCreateCollection = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
this.props.createCollection(this.state.collection)
|
this.props.createCollection(this.state.collection);
|
||||||
.then(({ id, owner }) => {
|
|
||||||
const pathname = `/${owner.username}/collections/${id}`;
|
|
||||||
const location = { pathname, state: { skipSavingPath: true } };
|
|
||||||
|
|
||||||
browserHistory.replace(location);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Error creating collection', error);
|
|
||||||
this.setState({
|
|
||||||
creationError: error,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -107,12 +94,7 @@ CollectionCreate.propTypes = {
|
||||||
username: PropTypes.string,
|
username: PropTypes.string,
|
||||||
authenticated: PropTypes.bool.isRequired
|
authenticated: PropTypes.bool.isRequired
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
createCollection: PropTypes.func.isRequired,
|
createCollection: PropTypes.func.isRequired
|
||||||
collection: PropTypes.shape({}).isRequired, // TODO
|
|
||||||
sorting: PropTypes.shape({
|
|
||||||
field: PropTypes.string.isRequired,
|
|
||||||
direction: PropTypes.string.isRequired
|
|
||||||
}).isRequired
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state, ownProps) {
|
||||||
|
|
|
@ -72,6 +72,7 @@ function mapStateToProps(state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectionView.propTypes = {
|
CollectionView.propTypes = {
|
||||||
|
@ -84,7 +85,7 @@ CollectionView.propTypes = {
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
theme: PropTypes.string.isRequired,
|
theme: PropTypes.string.isRequired,
|
||||||
user: PropTypes.shape({
|
user: PropTypes.shape({
|
||||||
username: PropTypes.string.isRequired,
|
username: PropTypes.string,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue