import { useRouter } from 'next/router' import { toJS } from 'mobx' import { observer } from 'mobx-react-lite' import { Button, Dropdown, IconPlus } from 'ui' import { useStore } from 'hooks' import { IS_PLATFORM } from 'lib/constants' const OrgDropdown = () => { const router = useRouter() const { app, ui } = useStore() const sortedOrganizations: any[] = app.organizations.list() const selectedOrganization: any = ui.selectedOrganization return IS_PLATFORM ? ( {sortedOrganizations .sort((a, b) => a.name.localeCompare(b.name)) .map((x) => { const slug = toJS(x.slug) return ( { if (!slug) { // The user should not see this error as the page should // be rerendered with the value of slug before they can click. // It is just here in case they are the flash. return ui.setNotification({ category: 'error', message: 'Could not navigate to organization settings, please try again or contact support', }) } router.push({ pathname: `/org/[slug]/settings`, query: { slug }, hash: router.asPath.split('#')[1]?.toLowerCase(), }) }} > {x.name} ) })} } onClick={() => router.push(`/new`)}> New organization } > ) : ( ) } export default observer(OrgDropdown)