import Icon from "@ant-design/icons"; import { Popover, Space } from "antd"; import _ from "lodash"; import moment from "moment"; 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"; 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 && moment(date).isSame(moment(e.start), "day") ), "job.alt_transport" ); }, [events, date]); const isDayBlocked = useMemo(() => { if (!events) return []; return ( events && events.filter( (e) => moment(date).isSame(moment(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 (moment(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} {calculating ? : LoadComponent}
); } export default connect( mapStateToProps, mapDispatchToProps )(ScheduleCalendarHeaderComponent);