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 { FiLogOut } from "react-icons/fi"; 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 { checkBeta, handleBeta, setBeta } from "../../utils/handleBeta"; 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", id: "header-accounting-bills", icon: , label: {t("menus.header.bills")} }, { key: "enterbills", id: "header-accounting-enterbills", icon: , label: t("menus.header.enterbills"), onClick: () => { setBillEnterContext({ actions: {}, context: {} }); } } ); } if (Simple_Inventory.treatment === "on") { accountingChildren.push( { type: "divider" }, { key: "inventory", id: "header-accounting-inventory", icon: , label: {t("menus.header.inventory")} } ); } if ( InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: "payments", bodyshop }) }) ) { accountingChildren.push( { type: "divider" }, { key: "allpayments", id: "header-accounting-allpayments", icon: , label: {t("menus.header.allpayments")} }, { key: "enterpayments", id: "header-accounting-enterpayments", icon: , label: t("menus.header.enterpayment"), onClick: () => { setPaymentContext({ actions: {}, context: null }); } } ); } if (ImEXPay.treatment === "on") { accountingChildren.push({ key: "entercardpayments", id: "header-accounting-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", id: "header-accounting-timetickets", icon: , label: {t("menus.header.timetickets")} } ); if (bodyshop?.md_tasks_presets?.use_approvals) { accountingChildren.push({ key: "ttapprovals", id: "header-accounting-ttapprovals", icon: , label: {t("menus.header.ttapprovals")} }); } accountingChildren.push( { key: "entertimetickets", icon: , label: t("menus.header.entertimeticket"), id: "header-accounting-entertimetickets", onClick: () => { setTimeTicketContext({ actions: {}, context: { created_by: currentUser.displayName ? currentUser.email.concat(" | ", currentUser.displayName) : currentUser.email } }); } }, { type: "divider" } ); } const accountingExportChildren = [ { key: "receivables", id: "header-accounting-receivables", label: {t("menus.header.accounting-receivables")} } ]; if (!((bodyshop && bodyshop.cdk_dealerid) || (bodyshop && bodyshop.pbs_serialnumber)) || DmsAp.treatment === "on") { accountingExportChildren.push({ key: "payables", id: "header-accounting-payables", label: {t("menus.header.accounting-payables")} }); } if (!((bodyshop && bodyshop.cdk_dealerid) || (bodyshop && bodyshop.pbs_serialnumber))) { accountingExportChildren.push({ key: "payments", id: "header-accounting-payments", label: {t("menus.header.accounting-payments")} }); } accountingExportChildren.push( { type: "divider" }, { key: "exportlogs", id: "header-accounting-exportlogs", label: {t("menus.header.export-logs")} } ); if ( InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: "export", bodyshop }) }) ) { accountingChildren.push({ key: "accountingexport", id: "header-accounting-export", icon: , label: t("menus.header.export"), children: accountingExportChildren }); } const menuItems = [ { key: "home", icon: , id: "header-home", label: {t("menus.header.home")} }, { key: "schedule", id: "header-schedule", icon: , label: {t("menus.header.schedule")} }, { key: "jobssubmenu", id: "header-jobs", icon: , label: t("menus.header.jobs"), children: [ { key: "activejobs", id: "header-active-jobs", icon: , label: {t("menus.header.activejobs")} }, { key: "readyjobs", id: "header-ready-jobs", icon: , label: {t("menus.header.readyjobs")} }, { key: "parts-queue", id: "header-parts-queue", icon: , label: {t("menus.header.parts-queue")} }, { key: "availablejobs", id: "header-jobs-available", icon: , label: {t("menus.header.availablejobs")} }, { key: "newjob", id: "header-new-job", icon: , label: {t("menus.header.newjob")} }, { type: "divider" }, { key: "alljobs", id: "header-all-jobs", icon: , label: {t("menus.header.alljobs")} }, { type: "divider" }, { key: "productionlist", id: "header-production-list", icon: , label: {t("menus.header.productionlist")} }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: "visualboard", bodyshop }) }) ? [ { key: "productionboard", id: "header-production-board", icon: , label: {t("menus.header.productionboard")} } ] : []), ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: "scoreboard", bodyshop }) }) ? [ { type: "divider" }, { key: "scoreboard", id: "header-scoreboard", icon: , label: {t("menus.header.scoreboard")} } ] : []) ] }, { key: "customers", icon: , id: "header-customers", label: t("menus.header.customers"), children: [ { key: "owners", id: "header-owners", icon: , label: {t("menus.header.owners")} }, { key: "vehicles", id: "header-vehicles", icon: , label: {t("menus.header.vehicles")} } ] }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: false // HasFeatureAccess({ featureName: 'courtesycars', bodyshop }), }) ? [ { key: "ccs", id: "header-css", icon: , label: t("menus.header.courtesycars"), children: [ { key: "courtesycarsall", id: "header-courtesycars-all", icon: , label: {t("menus.header.courtesycars-all")} }, { key: "contracts", id: "header-contracts", icon: , label: {t("menus.header.courtesycars-contracts")} }, { key: "newcontract", id: "header-newcontract", icon: , label: {t("menus.header.courtesycars-newcontract")} } ] } ] : []), ...(accountingChildren.length > 0 ? [ { key: "accounting", id: "header-accounting", icon: , label: t("menus.header.accounting"), children: accountingChildren } ] : []), { key: "phonebook", id: "header-phonebook", icon: , label: {t("menus.header.phonebook")} }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: "media", bodyshop }) }) ? [ { key: "temporarydocs", id: "header-temporarydocs", icon: , label: {t("menus.header.temporarydocs")} } ] : []), { key: "tasks", id: "tasks", icon: , label: t("menus.header.tasks"), children: [ { key: "createTask", icon: , label: t("menus.header.create_task"), onClick: () => { setTaskUpsertContext({ actions: {}, context: {} }); } }, { key: "mytasks", icon: , label: {t("menus.header.my_tasks")} }, { key: "all_tasks", icon: , label: {t("menus.header.all_tasks")} } ] }, { key: "shopsubmenu", id: "header-shopsubmenu", icon: , label: t("menus.header.shop"), children: [ { key: "shop", id: "header-shop", icon: , label: {t("menus.header.shop_config")} }, { key: "dashboard", id: "header-dashboard", icon: , label: {t("menus.header.dashboard")} }, { key: "reportcenter", id: "header-reportcenter", icon: , label: t("menus.header.reportcenter"), onClick: () => { setReportCenterContext({ actions: {}, context: {} }); } }, { key: "shop-vendors", id: "header-shop-vendors", icon: , label: {t("menus.header.shop_vendors")} }, ...(InstanceRenderManager({ imex: true, rome: true, promanager: HasFeatureAccess({ featureName: "csi", bodyshop }) }) ? [ { key: "shop-csi", id: "header-shop-csi", icon: , label: {t("menus.header.shop_csi")} } ] : []) ] }, { key: "user", label: currentUser.displayName || currentUser.email || t("general.labels.unknown"), children: [ { key: "signout", id: "header-signout", icon: , danger: true, label: t("user.actions.signout"), onClick: () => signOutStart() }, { key: "help", id: "header-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" ); } }, ...(InstanceRenderManager({ imex: true, rome: false, promanager: false }) ? [ { 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", id: "header-shiftclock", icon: , label: {t("menus.header.shiftclock")} } ] : []), { key: "profile", id: "header-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: , id: "header-recent", children: recentItems.map((i, idx) => ({ key: idx, label: {i.label} })) } ]; InstanceRenderManager({ executeFunction: true, args: [], imex: () => { menuItems.push({ key: "beta-switch", id: "header-beta-switch", style: { marginLeft: "auto" }, label: ( Try the new app ) }); } }); return ( ); } export default connect(mapStateToProps, mapDispatchToProps)(Header);