import React, {useEffect} from 'react'; import { useHistory } from 'react-router'; import { connect } from 'react-redux'; import { Alignment, Navbar, NavbarGroup, Tabs, Tab, Button } from '@blueprintjs/core'; import { useParams, withRouter } from 'react-router-dom'; import Icon from 'components/Icon'; import { Link } from 'react-router-dom'; import { FormattedMessage as T } from 'react-intl'; import {useUpdateEffect} from 'hooks'; import withDashboard from 'containers/Dashboard/withDashboard'; import withAccounts from 'containers/Accounts/withAccounts'; import withAccountsTableActions from 'containers/Accounts/withAccountsTableActions'; import withViewDetail from 'containers/Views/withViewDetails'; import { compose } from 'utils'; function AccountsViewsTabs({ // #withViewDetail viewId, viewItem, // #withAccounts accountsViews, // #withAccountsTableActions addAccountsTableQueries, changeAccountsCurrentView, // #withDashboard setTopbarEditView, changePageSubtitle, // props customViewChanged, onViewChanged, }) { const history = useHistory(); const { custom_view_id: customViewId = null } = useParams(); useEffect(() => { changeAccountsCurrentView(customViewId || -1); setTopbarEditView(customViewId); changePageSubtitle((customViewId && viewItem) ? viewItem.name : ''); addAccountsTableQueries({ custom_view_id: customViewId, }); return () => { setTopbarEditView(null); changePageSubtitle(''); changeAccountsCurrentView(null) }; }, [customViewId]); useUpdateEffect(() => { onViewChanged && onViewChanged(customViewId); }, [customViewId]); // Handle click a new view tab. const handleClickNewView = () => { setTopbarEditView(null); history.push('/custom_views/accounts/new'); }; // Handle view tab link click. const handleViewLinkClick = () => { setTopbarEditView(customViewId); }; const tabs = accountsViews.map((view) => { const baseUrl = '/accounts'; const link = ( { view.name } ); return ; }); return ( } onClick={handleViewLinkClick} /> { tabs }