import * as React from 'react'; import { DragDropContext, Droppable } from 'react-beautiful-dnd'; import I18n from 'i18n-js'; import BoardEditable from './BoardEditable'; import BoardForm from './BoardForm'; import SiteSettingsInfoBox from '../../common/SiteSettingsInfoBox'; import Spinner from '../../common/Spinner'; import Box from '../../common/Box'; import { CenteredMutedText } from '../../common/CustomTexts'; import { BoardsState } from '../../../reducers/boardsReducer'; import IBoard from '../../../interfaces/IBoard'; interface Props { authenticityToken: string; boards: BoardsState; settingsAreUpdating: boolean; settingsError: string; requestBoards(): void; submitBoard( name: string, description: string, onSuccess: Function, authenticityToken: string, ): void; updateBoard( id: number, name: string, description: string, onSuccess: Function, authenticityToken: string, ): void; updateBoardOrder( id: number, boards: Array, sourceIndex: number, destinationIndex: number, authenticityToken: string, ): void; deleteBoard(id: number, authenticityToken: string): void; } class BoardsSiteSettingsP extends React.Component { constructor(props: Props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.handleUpdate = this.handleUpdate.bind(this); this.handleDragEnd = this.handleDragEnd.bind(this); this.handleDelete = this.handleDelete.bind(this); } componentDidMount() { this.props.requestBoards(); } handleSubmit(name: string, description: string, onSuccess: Function) { this.props.submitBoard(name, description, onSuccess, this.props.authenticityToken); } handleUpdate(id: number, name: string, description: string, onSuccess: Function) { this.props.updateBoard(id, name, description, onSuccess, this.props.authenticityToken); } handleDragEnd(result) { if (result.destination == null || result.source.index === result.destination.index) return; this.props.updateBoardOrder( parseInt(result.draggableId), this.props.boards.items, result.source.index, result.destination.index, this.props.authenticityToken, ); } handleDelete(id: number) { this.props.deleteBoard(id, this.props.authenticityToken); } render() { const { boards, settingsAreUpdating, settingsError, } = this.props; return ( <>

{I18n.t('site_settings.boards.title')}

{ boards.items.length > 0 ? {provided => (
    {boards.items.map((board, i) => ( ))} {provided.placeholder}
)}
: boards.areLoading ? : {I18n.t('site_settings.boards.empty')} }

{I18n.t('site_settings.boards.new')}

); } } export default BoardsSiteSettingsP;