import Icon, { BankFilled, BarChartOutlined, CarFilled, CheckCircleOutlined, ClockCircleFilled, DashboardFilled, DollarCircleFilled, ExportOutlined, FieldTimeOutlined, FileAddFilled, FileAddOutlined, FileFilled, HomeFilled, ImportOutlined, InfoCircleOutlined, LineChartOutlined, PaperClipOutlined, PhoneOutlined, PlusCircleOutlined, QuestionCircleFilled, ScheduleOutlined, SettingOutlined, TeamOutlined, ToolFilled, UnorderedListOutlined, UserOutlined, } from '@ant-design/icons'; import {useSplitTreatments} from '@splitsoftware/splitio-react'; import {Layout, Menu, Switch, Tooltip} from 'antd'; import React, {useEffect, useState} from 'react'; import {useTranslation} from 'react-i18next'; import {BsKanban} from 'react-icons/bs'; import { FaCalendarAlt, FaCarCrash, FaCreditCard, FaFileInvoiceDollar, FaTasks } from 'react-icons/fa'; import {GiPayMoney, GiPlayerTime, GiSettingsKnobs} from 'react-icons/gi'; import {IoBusinessOutline} from 'react-icons/io5'; import {RiSurveyLine} from 'react-icons/ri'; import {connect} from 'react-redux'; import {Link} from 'react-router-dom'; import {createStructuredSelector} from 'reselect'; import { selectRecentItems, selectSelectedHeader, } from '../../redux/application/application.selectors'; import {setModalContext} from '../../redux/modals/modals.actions'; import {signOutStart} from '../../redux/user/user.actions'; import {selectBodyshop, selectCurrentUser} from '../../redux/user/user.selectors'; import {FiLogOut} from 'react-icons/fi'; import {checkBeta, handleBeta, setBeta} from '../../utils/betaHandler'; import InstanceRenderManager from '../../utils/instanceRenderMgr'; import {HasFeatureAccess} from '../feature-wrapper/feature-wrapper.component'; const mapStateToProps = createStructuredSelector({ currentUser: selectCurrentUser, recentItems: selectRecentItems, selectedHeader: selectSelectedHeader, bodyshop: selectBodyshop, }); const mapDispatchToProps = (dispatch) => ({ setBillEnterContext: (context) => dispatch(setModalContext({ context: context, modal: 'billEnter' })), setTimeTicketContext: (context) => dispatch(setModalContext({ context: context, modal: 'timeTicket' })), setPaymentContext: (context) => dispatch(setModalContext({ context: context, modal: 'payment' })), setReportCenterContext: (context) => dispatch(setModalContext({ context: context, modal: 'reportCenter' })), signOutStart: () => dispatch(signOutStart()), setCardPaymentContext: (context) => dispatch(setModalContext({ context: context, modal: 'cardPayment' })), setTaskUpsertContext: (context) => dispatch(setModalContext({ context: context, modal: 'taskUpsert' })), }); function Header({ handleMenuClick, currentUser, bodyshop, selectedHeader, signOutStart, setBillEnterContext, setTimeTicketContext, setPaymentContext, setReportCenterContext, recentItems, setCardPaymentContext, setTaskUpsertContext, }) { const { treatments: { ImEXPay, DmsAp, Simple_Inventory }, } = useSplitTreatments({ attributes: {}, names: ['ImEXPay', 'DmsAp', 'Simple_Inventory'], splitKey: bodyshop && bodyshop.imexshopid, }); const [betaSwitch, setBetaSwitch] = useState(false); const { t } = useTranslation(); useEffect(() => { const isBeta = checkBeta(); setBetaSwitch(isBeta); }, []); const betaSwitchChange = (checked) => { setBeta(checked); setBetaSwitch(checked); handleBeta(); }; const accountingChildren = []; if ( InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'bills', bodyshop }), }) ) { accountingChildren.push( { key: 'bills', icon: , label: {t('menus.header.bills')}, }, { key: 'enterbills', icon: , label: t('menus.header.enterbills'), onClick: () => { setBillEnterContext({ actions: {}, context: {}, }); }, } ); } if (Simple_Inventory.treatment === 'on') { accountingChildren.push( { type: 'divider', }, { key: 'inventory', icon: , label: {t('menus.header.inventory')}, } ); } if ( InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'payments', bodyshop }), }) ) { accountingChildren.push( { type: 'divider', }, { key: 'allpayments', icon: , label: {t('menus.header.allpayments')}, }, { key: 'enterpayments', icon: , label: t('menus.header.enterpayment'), onClick: () => { setPaymentContext({ actions: {}, context: null, }); }, } ); } if (ImEXPay.treatment === 'on') { accountingChildren.push({ key: 'entercardpayments', icon: , label: t('menus.header.entercardpayment'), onClick: () => { setCardPaymentContext({ actions: {}, context: {}, }); }, }); } if ( InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'timetickets', bodyshop }), }) ) { accountingChildren.push( { type: 'divider', }, { key: 'timetickets', icon: , label: {t('menus.header.timetickets')}, } ); if (bodyshop?.md_tasks_presets?.use_approvals) { accountingChildren.push({ key: 'ttapprovals', icon: , label: {t('menus.header.ttapprovals')}, }); } accountingChildren.push( { key: 'entertimetickets', icon: , label: t('menus.header.entertimeticket'), onClick: () => { setTimeTicketContext({ actions: {}, context: { created_by: currentUser.displayName ? currentUser.email.concat(' | ', currentUser.displayName) : currentUser.email, }, }); }, }, { type: 'divider', } ); } const accountingExportChildren = [ { key: 'receivables', label: ( {t('menus.header.accounting-receivables')} ), }, ]; if ( !((bodyshop && bodyshop.cdk_dealerid) || (bodyshop && bodyshop.pbs_serialnumber)) || DmsAp.treatment === 'on' ) { accountingExportChildren.push({ key: 'payables', label: {t('menus.header.accounting-payables')}, }); } if (!((bodyshop && bodyshop.cdk_dealerid) || (bodyshop && bodyshop.pbs_serialnumber))) { accountingExportChildren.push({ key: 'payments', label: {t('menus.header.accounting-payments')}, }); } accountingExportChildren.push( { type: 'divider', }, { key: 'exportlogs', label: {t('menus.header.export-logs')}, } ); if ( InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'export', bodyshop }), }) ) { accountingChildren.push({ key: 'accountingexport', icon: , label: t('menus.header.export'), children: accountingExportChildren, }); } const menuItems = [ { key: 'home', icon: , label: {t('menus.header.home')}, }, { key: 'schedule', icon: , label: {t('menus.header.schedule')}, }, { key: 'jobssubmenu', id: 'header-jobs', icon: , label: t('menus.header.jobs'), children: [ { key: 'activejobs', icon: , label: {t('menus.header.activejobs')}, }, { key: 'readyjobs', icon: , label: {t('menus.header.readyjobs')}, }, { key: 'parts-queue', icon: , label: {t('menus.header.parts-queue')}, }, { key: 'availablejobs', id: 'header-jobs-available', icon: , label: {t('menus.header.availablejobs')}, }, { key: 'newjob', icon: , label: {t('menus.header.newjob')}, }, { key: 'alljobs', icon: , label: {t('menus.header.alljobs')}, }, { type: 'divider', }, { key: 'productionlist', icon: , label: {t('menus.header.productionlist')}, }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'visualboard', bodyshop }), }) ? [ { key: 'productionboard', icon: , label: ( {t('menus.header.productionboard')} ), }, ] : []), ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'scoreboard', bodyshop }), }) ? [ { type: 'divider', }, { key: 'scoreboard', icon: , label: {t('menus.header.scoreboard')}, }, ] : []), ], }, { key: 'customers', icon: , label: t('menus.header.customers'), children: [ { key: 'owners', icon: , label: {t('menus.header.owners')}, }, { key: 'vehicles', icon: , label: {t('menus.header.vehicles')}, }, ], }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: false, // HasFeatureAccess({ featureName: 'courtesycars', bodyshop }), }) ? [ { key: 'ccs', icon: , label: t('menus.header.courtesycars'), children: [ { key: 'courtesycarsall', icon: , label: {t('menus.header.courtesycars-all')}, }, { key: 'contracts', icon: , label: ( {t('menus.header.courtesycars-contracts')} ), }, { key: 'newcontract', icon: , label: ( {t('menus.header.courtesycars-newcontract')} ), }, ], }, ] : []), ...(accountingChildren.length > 0 ? [ { key: 'accounting', icon: , label: t('menus.header.accounting'), children: accountingChildren, }, ] : []), { key: 'phonebook', icon: , label: {t('menus.header.phonebook')}, }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'media', bodyshop }), }) ? [ { key: 'temporarydocs', icon: , label: {t('menus.header.temporarydocs')}, }, ] : []), { key: 'tasks', id: 'tasks', icon: , label: t('menus.header.my_tasks'), children: [ { key: 'createTask', icon: , label: t('menus.header.create_task'), onClick: () => { setTaskUpsertContext({ actions: {}, context: {}, }); }, }, { key: 'mytasks', icon: , label: {t('menus.header.tasks')}, } ] }, { key: 'shopsubmenu', icon: , label: t('menus.header.shop'), children: [ { key: 'shop', icon: , label: {t('menus.header.shop_config')}, }, { key: 'dashboard', icon: , label: {t('menus.header.dashboard')}, }, { key: 'reportcenter', icon: , label: t('menus.header.reportcenter'), onClick: () => { setReportCenterContext({ actions: {}, context: {}, }); }, }, { key: 'shop-vendors', icon: , label: {t('menus.header.shop_vendors')}, }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'csi', bodyshop }), }) ? [ { key: 'shop-csi', icon: , label: {t('menus.header.shop_csi')}, }, ] : []), ], }, { key: 'user', label: currentUser.displayName || currentUser.email || t('general.labels.unknown'), children: [ { key: 'signout', icon: , danger: true, label: t('user.actions.signout'), onClick: () => signOutStart(), }, { key: 'help', icon: , label: t('menus.header.help'), onClick: () => { window.open( InstanceRenderManager({ imex: 'https://help.imex.online/', rome: 'https://rometech.com//', promanager: 'https://web-est.com', }), '_blank' ); }, }, // { // key: 'rescue', // icon: , // label: t("menus.header.rescueme"), // onClick: () => { // window.open("https://imexrescue.com/", "_blank"); // } // }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: 'timetickets', bodyshop }), }) ? [ { key: 'shiftclock', icon: , label: {t('menus.header.shiftclock')}, }, ] : []), { key: 'profile', icon: , label: {t('menus.currentuser.profile')}, }, // { // key: 'langselecter', // label: t("menus.currentuser.languageselector"), // children: [ // { // key: 'en-US', // label: t("general.languages.english"), // onClick: () => { // window.location.href = "/?lang=en-US"; // } // }, // { // key: 'fr-CA', // label: t("general.languages.french"), // onClick: () => { // window.location.href = "/?lang=fr-CA"; // } // }, // { // key: 'es-MX', // label: t("general.languages.spanish"), // onClick: () => { // window.location.href = "/?lang=es-MX"; // } // }, // ] // }, ], }, { key: 'recent', icon: , children: recentItems.map((i, idx) => ({ key: idx, label: {i.label}, })), }, ]; menuItems.push({ key: 'beta-switch', style: { marginLeft: 'auto' }, label: ( Try the new app ), }); return ( ); } export default connect(mapStateToProps, mapDispatchToProps)(Header);