import { CaretDownOutlined, FolderAddOutlined } from '@ant-design/icons'; import { Button, Dropdown, MenuProps, Space, Typography } from 'antd'; import cn from 'classnames'; import React from 'react'; import { withRouter } from 'react-router-dom'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; import { hasSiteId, siteChangeAvailable } from 'App/routes'; import NewSiteForm from 'Components/Client/Sites/NewSiteForm'; import { useModal } from 'Components/Modal'; import { Icon } from 'UI'; const { Text } = Typography; function ProjectDropdown(props: { location: any }) { const mstore = useStore(); const { projectsStore, searchStore, searchStoreLive, userStore } = mstore; const account = userStore.account; const sites = projectsStore.list; const siteId = projectsStore.siteId; const setSiteId = projectsStore.setSiteId; const initProject = projectsStore.initProject; const { location } = props; const isAdmin = account.admin || account.superAdmin; const activeSite = sites.find((s) => s.id === siteId); const showCurrent = hasSiteId(location.pathname) || siteChangeAvailable(location.pathname); const { showModal, hideModal } = useModal(); const handleSiteChange = async (newSiteId: string) => { mstore.initClient(); setSiteId(newSiteId); searchStore.clearSearch(); searchStore.clearList(); searchStoreLive.clearSearch(); // await customFieldStore.fetchList(newSiteId); // await searchStore.fetchSavedSearchList() }; const addProjectClickHandler = () => { initProject({}); showModal(, { right: true }); }; const menuItems: MenuProps['items'] = sites.map((site) => ({ key: site.id, label: (
{site.host}
) })); if (isAdmin) { menuItems?.unshift({ key: 'add-proj', label: (
Add Project
) }, { type: 'divider' }); } return ( { if (e.key === 'add-proj') { addProjectClickHandler(); } else { void handleSiteChange(e.key); } } }} placement="bottomLeft" > ); } export default withRouter( observer(ProjectDropdown) );