import React, { Fragment } from 'react'; import { Page } from '../Page'; import { connect, DispatchProp } from 'react-redux'; import Board, { addColumn } from '@lourenci/react-kanban'; import { fetchBoards } from '../../store/actions/boards'; import { createIssue, fetchIssues } from '../../store/actions/issues'; import { buildKanboard, moveCard } from '../../store/actions/kanboards'; import { Loader } from '../Loader'; import { IssueCard } from './IssueCard'; import { Modal } from '../Modal'; import { fetchProjectsMilestones } from '../../store/actions/projects'; export interface BoardPageProps extends DispatchProp { board: any kanboard: any milestones: any } export class BoardPage extends React.Component { state = { newCardModalActive: false, newCardLaneID: 0, newCard: { title: "", body: "", project: "" }, compactMode: true, hasError: false, selectedMilestone: "", } onNewCardTitleChange: (evt: any) => void; onNewCardBodyChange: (evt: any) => void; onNewCardProjectChange: (evt: any) => void; constructor(props: BoardPageProps) { super(props); this.renderLaneHeader = this.renderLaneHeader.bind(this); this.onNewCardClick = this.onNewCardClick.bind(this); this.onNewCardCloseClick = this.onNewCardCloseClick.bind(this); this.onNewCardTitleChange = this.onNewCardAttrChange.bind(this, 'title'); this.onNewCardBodyChange = this.onNewCardAttrChange.bind(this, 'body'); this.onNewCardProjectChange = this.onNewCardAttrChange.bind(this, 'project'); this.onNewCardSaveClick = this.onNewCardSaveClick.bind(this); } componentDidCatch(error, errorInfo) { // You can also log the error to an error reporting service console.error(error, errorInfo); } handleMilestonesChange(e: any) { let m = (e.target as HTMLInputElement).value; this.setState(state => ({ ...state, selectedMilestone: m }), this.requestBuildKanboard); //this.requestBuildKanboard(); } render() { const { board } = this.props; return ( {this.renderBoard()} ); } renderBoard() { const { kanboard, board, milestones } = this.props; const { selectedMilestone } = this.state; if (!kanboard) { return } return (
{kanboard} {this.renderNewCardModal()}
); } renderNewCardModal() { const { newCardModalActive, newCardLaneID } = this.state; const { board } = this.props; if (!board || newCardLaneID === undefined) return null; return (

"{board.lanes[newCardLaneID].title}" - Nouveau ticket

) } renderCard(card: any) { return ; } renderLaneHeader(lane: any) { return (
{lane.cards.length}

{lane.title}

) } onMinimizeColumn(e: any) { e.currentTarget.closest('.react-kanban-column').classList.toggle('minimized'); } onCardDragEnd(card: any, source: any, dest: any) { const { board } = this.props; this.props.dispatch(moveCard( board.id, source.fromColumnId, source.fromPosition, dest.toColumnId, dest.toPosition )); } componentDidMount() { const { board } = this.props; if (!board) { this.requestBoardsUpdate(); return } this.requestBuildKanboard(); } onNewCardClick(laneID: string) { const { board } = this.props; this.setState({ newCardModalActive: true, newCardLaneID: laneID, newCard: { title: "", body: "", project: board.projects[0], } }); } onNewCardCloseClick() { this.setState({ newCardModalActive: false }); } onNewCardAttrChange(attrName: string, evt: React.ChangeEvent) { const value = (evt.target as HTMLInputElement).value; this.setState((state: any) => { return { ...state, newCard: { ...state.newCard, [attrName]: value, } } }) } onNewCardSaveClick() { const { newCard, newCardLaneID } = this.state; const { board } = this.props; this.setState({ newCardModalActive: false }); this.props.dispatch(createIssue( newCard.project, newCard.title, newCard.body, board.lanes[newCardLaneID].issueLabel )); } componentDidUpdate(prevProps: any) { if (prevProps.board !== this.props.board) this.requestBuildKanboard(); } requestBoardsUpdate() { this.props.dispatch(fetchBoards()); } requestBuildKanboard() { const { board } = this.props; const { selectedMilestone } = this.state; if (!board) return; this.props.dispatch(fetchProjectsMilestones(board.projects)); this.props.dispatch(buildKanboard(board, selectedMilestone)); } onCompactModeChange(evt: React.ChangeEvent) { const checked = (evt.currentTarget as HTMLInputElement).checked; this.setState(state => ({ ...state, compactMode: checked })); } } export const ConnectedBoardPage = connect(function (state: any, props: any) { const boardID = props.match.params.id; return { board: state.boards.byID[boardID], kanboard: state.kanboards.byID[boardID], milestones: state.projects.milestones }; })(BoardPage);