export default class OutsideClick extends Component {
constructor(props) {
super(props);
this.setWrapperRef = this.setWrapperRef.bind(this);
this.handleClickOutside = this.handleClickOutside.bind(this);
}
componentDidMount() {
document.addEventListener('mousedown', this.handleClickOutside);
}
componentWillUnmount() {
document.removeEventListener('mousedown', this.handleClickOutside);
}
/**
* Set the wrapper ref
*/
setWrapperRef(node) {
this.wrapperRef = node;
}
/**
* Alert if clicked on outside of element
*/
handleClickOutside(event) {
if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
alert('You clicked outside of me!');
}
}
render() {
return <div ref={this.setWrapperRef}>{this.props.children}</div>;
}
}
/// Delete task
router.route("/:taskId").delete(async (req, res) => {
const deleted = await Task.findByIdAndDelete(req.params.taskId);
if (deleted.executor) {
await User.updateOne(
{ _id: deleted.executor },
{ $unset: { "tasks.$": req.params.taskId } }
);
}
res.send(deleted)
});
async componentDidMount() {
await this.props.getProjectsThunk(this.props.userId);
}