import Icon from "@ant-design/icons"; import { Popover, Space } from "antd"; import _ from "lodash"; import dayjs from "../../utils/day"; import React, { useMemo } from "react"; import { useTranslation } from "react-i18next"; import { MdFileDownload, MdFileUpload } from "react-icons/md"; import { connect } from "react-redux"; import { Link } from "react-router-dom"; import { createStructuredSelector } from "reselect"; import { selectScheduleLoad, selectScheduleLoadCalculating } from "../../redux/application/application.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors"; import { DateTimeFormatter } from "../../utils/DateFormatter"; import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component"; import OwnerNameDisplay from "../owner-name-display/owner-name-display.component"; import ScheduleBlockDay from "../schedule-block-day/schedule-block-day.component"; import ScheduleCalendarHeaderGraph from "./schedule-calendar-header-graph.component"; import InstanceRenderMgr from "../../utils/instanceRenderMgr"; import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, load: selectScheduleLoad, calculating: selectScheduleLoadCalculating }); const mapDispatchToProps = (dispatch) => ({}); export function ScheduleCalendarHeaderComponent({ bodyshop, label, refetch, date, load, calculating, events, ...otherProps }) { const ATSToday = useMemo(() => { if (!events) return []; return _.groupBy( events.filter((e) => !e.vacation && e.isintake && dayjs(date).isSame(dayjs(e.start), "day")), "job.alt_transport" ); }, [events, date]); const isDayBlocked = useMemo(() => { if (!events) return []; return events && events.filter((e) => dayjs(date).isSame(dayjs(e.start), "day") && e.block); }, [events, date]); const { t } = useTranslation(); const loadData = load[date.toISOString().substr(0, 10)]; const jobsOutPopup = () => (
e.stopPropagation()}> {loadData && loadData.allJobsOut ? ( loadData.allJobsOut.map((j) => ( )) ) : ( )}
{j.ro_number} ({j.status}) {`(${j.labhrs?.aggregate?.sum?.mod_lb_hrs?.toFixed(1) || 0}/${ j.larhrs?.aggregate?.sum?.mod_lb_hrs?.toFixed(1) || 0 }/${(j.labhrs.aggregate?.sum?.mod_lb_hrs + j.larhrs.aggregate?.sum?.mod_lb_hrs).toFixed( 1 )} ${t("general.labels.hours")})`} {j.scheduled_completion}
{t("appointments.labels.nocompletingjobs")}
); const jobsInPopup = () => (
e.stopPropagation()}> {loadData && loadData.allJobsIn ? ( loadData.allJobsIn.map((j) => ( )) ) : ( )}
{j.ro_number} {`(${j.labhrs?.aggregate?.sum.mod_lb_hrs?.toFixed(1) || 0}/${ j.larhrs?.aggregate?.sum?.mod_lb_hrs?.toFixed(1) || 0 }/${(j.labhrs?.aggregate?.sum?.mod_lb_hrs + j.larhrs?.aggregate?.sum?.mod_lb_hrs).toFixed( 1 )} ${t("general.labels.hours")})`} {j.scheduled_in}
{t("appointments.labels.noarrivingjobs")}
); const LoadComponent = loadData ? (
{(loadData.allHoursInBody || 0) && loadData.allHoursInBody.toFixed(1)}/ {(loadData.allHoursInRefinish || 0) && loadData.allHoursInRefinish.toFixed(1)}/ {(loadData.allHoursIn || 0) && loadData.allHoursIn.toFixed(1)} {(loadData.allHoursOut || 0) && loadData.allHoursOut.toFixed(1)}
) : null; const isShopOpen = (date) => { let day; switch (dayjs(date).day()) { case 0: day = "sunday"; break; case 1: day = "monday"; break; case 2: day = "tuesday"; break; case 3: day = "wednesday"; break; case 4: day = "thursday"; break; case 5: day = "friday"; break; case 6: day = "saturday"; break; default: day = "sunday"; break; } return bodyshop.workingdays[day]; }; return (
0} date={date} refetch={refetch}>
{label} {InstanceRenderMgr({ imex: HasFeatureAccess({ featureName: "smartscheduling", bodyshop }) ? ( calculating ? ( ) : ( LoadComponent ) ) : ( <> ), rome: "USE_IMEX" })}
); } export default connect(mapStateToProps, mapDispatchToProps)(ScheduleCalendarHeaderComponent);