NewContainer.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { connect } from 'react-redux';
  2. import { RootState, ClusterId, TopicFormData, TopicName, Action } from 'lib/interfaces';
  3. import New from './New';
  4. import { withRouter, RouteComponentProps } from 'react-router-dom';
  5. import { createTopic } from 'redux/reducers/topics/thunks';
  6. import { getTopicCreated } from 'redux/reducers/topics/selectors';
  7. import { clusterTopicPath } from 'lib/paths';
  8. import { ThunkDispatch } from 'redux-thunk';
  9. interface RouteProps {
  10. clusterId: string;
  11. }
  12. interface OwnProps extends RouteComponentProps<RouteProps> { }
  13. const mapStateToProps = (state: RootState, { match: { params: { clusterId } } }: OwnProps) => ({
  14. clusterId,
  15. isTopicCreated: getTopicCreated(state),
  16. });
  17. const mapDispatchToProps = (dispatch: ThunkDispatch<RootState, undefined, Action>, { history }: OwnProps) => ({
  18. createTopic: (clusterId: ClusterId, form: TopicFormData) => {
  19. dispatch(createTopic(clusterId, form))
  20. },
  21. redirectToTopicPath: (clusterId: ClusterId, topicName: TopicName) => {
  22. history.push(clusterTopicPath(clusterId, topicName));
  23. }
  24. });
  25. export default withRouter(
  26. connect(mapStateToProps, mapDispatchToProps)(New)
  27. );