import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { Modal, Button, Tab } from 'react-bootstrap'; import Axios from 'axios'; import { toast } from 'react-toastify'; import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd'; export default class TableSettings extends Component { constructor(props) { super(props) this.state = { visible: this.props.data[0], hidden: this.props.data[1], } } handleOnDragEnd = (result) => { console.log(result); if (!result.destination) return; let visible = this.state.visible; let hidden = this.state.hidden; let from = result.source.droppableId == 'visibleColumns' ? visible.obj.value : hidden.obj.value; let to = result.destination.droppableId == 'visibleColumns' ? visible.obj.value : hidden.obj.value; let [reorderedItem] = from.splice(result.source.index, 1); to.splice(result.destination.index, 0, reorderedItem); this.setState({ visible: visible, hidden: hidden }); } save = () => { var url = 'api/settings/bulk?token=' + window.token; Axios.post(url, { data: [ { name: 'visible_columns', value: this.state.visible.obj.value }, { name: 'hidden_columns', value: this.state.hidden.obj.value } ], }) .then((resp) => { console.log(resp); }) .catch((err) => { console.log(err); }) } render() { let visible = this.state.visible; let hidden = this.state.hidden; return ( {visible.obj.description} {(provided) => ( {visible.obj.value.map((e, i) => { return ( {(provided) => ( {e} )} ); })} {provided.placeholder} )} {(provided) => ( {hidden.obj.value.map((e, i) => { return ( {(provided) => ( {e} )} ); })} {provided.placeholder} )} { this.save() }}>Save ); } } if (document.getElementById('TableSettings')) { ReactDOM.render(, document.getElementById('TableSettings')); }
{visible.obj.description}