import React from 'react'; import { connect } from 'react-redux'; // import cn from 'classnames'; import { SlideModal, Popup, Button, Icon, SplitButton } from 'UI'; import OutsideClickDetectingDiv from 'Shared/OutsideClickDetectingDiv'; import IssuesModal from './IssuesModal'; // import { fetchIssue } from 'Duck/issues'; import { fetchProjects, fetchAssignments, fetchMeta, fetchAssigment } from 'Duck/assignments'; import SessionIssuesPanel from './SessionIssuesPanel'; import IssueDetails from './IssueDetails'; import withToggle from 'HOCs/withToggle'; // import { withRequest } from 'HOCs'; import stl from './issues.css'; @connect(state => ({ issues: state.getIn(['assignments', 'list']), metaLoading: state.getIn(['assignments', 'fetchMeta', 'loading']), projects: state.getIn(['assignments', 'projects']), projectsFetched: state.getIn(['assignments', 'projectsFetched']), activeIssue: state.getIn(['assignments', 'activeIssue']), fetchIssueLoading: state.getIn(['assignments', 'fetchAssignment', 'loading']), fetchIssuesLoading: state.getIn(['assignments', 'fetchAssignments', 'loading']), projectsLoading: state.getIn(['assignments', 'fetchProjects', 'loading']), issuesIntegration: state.getIn([ 'issues', 'list']).first() || {}, }), { fetchAssigment, fetchAssignments, fetchMeta, fetchProjects }) @withToggle('isModalDisplayed', 'toggleModal') class Issues extends React.Component { state = {showModal: false }; constructor(props) { super(props); this.state = { showModal: false }; if (!props.projectsFetched) { // cache projects fetch this.props.fetchProjects().then(function() { const { projects } = this.props; if (projects && projects.first()) { this.props.fetchMeta(projects.first().id) } }.bind(this)) } this.props.fetchAssignments(this.props.sessionId) } closeModal = () => { if (!this.props.isModalDisplayed) return; this.props.toggleModal(); } onIssueClick = (issue) => { const { sessionId } = this.props; this.setState({ showModal: true }); this.props.fetchAssigment(sessionId, issue.id); if (this.props.isModalDisplayed) this.props.toggleModal(); } showIssuesList = (e) => { e.preventDefault(); e.stopPropagation(); this.setState({ showModal: true }); } render() { const { sessionId, activeIssue, isModalDisplayed, projectsLoading, fetchIssueLoading, issues, metaLoading, fetchIssuesLoading, issuesIntegration } = this.props; const { showModal } = this.state; const provider = issuesIntegration.provider return (