import React, { useState, forwardRef, useRef } from 'react';
import get from 'lodash/get';
import classnames from 'classnames';
import { IconChevronRight, IconDots } from '@tabler/icons';
import Dropdown from 'components/Dropdown';
import { collectionClicked } from 'providers/ReduxStore/slices/collections';
import { useDispatch } from 'react-redux';
import NewRequest from 'components/Sidebar/NewRequest';
import NewFolder from 'components/Sidebar/NewFolder';
import CollectionItem from './CollectionItem';
import StyledWrapper from './StyledWrapper';
const Collection = ({collection}) => {
const [showNewFolderModal, setShowNewFolderModal] = useState(false);
const [showNewRequestModal, setShowNewRequestModal] = useState(false);
const dispatch = useDispatch();
const menuDropdownTippyRef = useRef();
const onMenuDropdownCreate = (ref) => menuDropdownTippyRef.current = ref;
const MenuIcon = forwardRef((props, ref) => {
return (
);
});
const iconClassName = classnames({
'rotate-90': collection.collapsed
});
const handleClick = (event) => {
let tippyEl = get(menuDropdownTippyRef, 'current.reference');
if(tippyEl && tippyEl.contains && tippyEl.contains(event.target)) {
return;
}
if(event && event.target && event.target.className === 'dropdown-item') {
return;
}
dispatch(collectionClicked(collection.uid));
};
const hideNewFolderModal = () => setShowNewFolderModal(false);
const hideNewRequestModal = () => setShowNewRequestModal(false);
return (
{showNewRequestModal && (
)}
{showNewFolderModal && (
)}
{collection.name}
} placement='bottom-start'>
{
menuDropdownTippyRef.current.hide();
setShowNewRequestModal(true)
}}>
New Request
{
menuDropdownTippyRef.current.hide();
setShowNewFolderModal(true)
}}>
New Folder
{collection.collapsed ? (
{collection.items && collection.items.length ? collection.items.map((i) => {
return
}) : null}
) : null}
);
};
export default Collection;