Home Reference Source

application/components/assignment/addons/dragAndDrop/DraggableEventWrapper.js

import PropTypes from 'prop-types';
import React from 'react'
import { DragSource } from 'react-dnd';
import cn from 'classnames';

import BigCalendar from 'react-big-calendar';

/* drag sources */

let eventSource = {
    beginDrag(props) {
        return props.event;
    }
}

function collectSource(connect, monitor) {
    return {
        connectDragSource: connect.dragSource(),
        isDragging: monitor.isDragging()
    };
}

const propTypes = {
    connectDragSource: PropTypes.func.isRequired,
    isDragging: PropTypes.bool.isRequired,
    event: PropTypes.object.isRequired,
}

class DraggableEventWrapper extends React.Component {
    render() {
        let { connectDragSource, isDragging, children, event } = this.props;
        let EventWrapper = BigCalendar.components.eventWrapper;

        children = React.cloneElement(children, {
            className: cn(
            children.props.className,
            isDragging && 'rbc-addons-dnd-dragging'
            )
        })

        if (event.type == 'issue' || event.lock) {
            return (
            <EventWrapper event={event}>
                {children}
            </EventWrapper>                
            )
        }
        return (
            <EventWrapper event={event}>
                {connectDragSource(children)}
            </EventWrapper>
        );      
    }
}

DraggableEventWrapper.propTypes = propTypes;

export default DragSource('event', eventSource, collectSource)(DraggableEventWrapper);