206 lines
6.6 KiB
JavaScript
206 lines
6.6 KiB
JavaScript
import { Button, Popover, Space } from "antd";
|
|
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import { Link, useHistory, useLocation } from "react-router-dom";
|
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
|
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
|
import PhoneFormatter from "../../utils/PhoneFormatter";
|
|
import { GenerateDocument } from "../../utils/RenderTemplate";
|
|
import { TemplateList } from "../../utils/TemplateConstants";
|
|
import DataLabel from "../data-label/data-label.component";
|
|
import ScheduleAtChange from "./job-at-change.component";
|
|
import ScheduleEventColor from "./schedule-event.color.component";
|
|
import queryString from "query-string";
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
setScheduleContext: (context) =>
|
|
dispatch(setModalContext({ context: context, modal: "schedule" })),
|
|
});
|
|
|
|
export function ScheduleEventComponent({
|
|
event,
|
|
refetch,
|
|
handleCancel,
|
|
setScheduleContext,
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const [visible, setVisible] = useState(false);
|
|
const history = useHistory();
|
|
const searchParams = queryString.parse(useLocation().search);
|
|
|
|
const blockContent = (
|
|
<div>
|
|
<Button onClick={() => handleCancel(event.id)} disabled={event.arrived}>
|
|
{t("appointments.actions.cancel")}
|
|
</Button>
|
|
</div>
|
|
);
|
|
|
|
const popoverContent = (
|
|
<div>
|
|
{!event.isintake ? (
|
|
<strong>{event.title}</strong>
|
|
) : (
|
|
<Space>
|
|
<strong>{`${(event.job && event.job.ownr_fn) || ""} ${
|
|
(event.job && event.job.ownr_ln) || ""
|
|
}`}</strong>
|
|
<span style={{ margin: 4 }}>
|
|
{`${(event.job && event.job.v_model_yr) || ""} ${
|
|
(event.job && event.job.v_make_desc) || ""
|
|
} ${(event.job && event.job.v_model_desc) || ""}`}
|
|
</span>
|
|
<ScheduleEventColor event={event} />
|
|
</Space>
|
|
)}
|
|
|
|
{event.job ? (
|
|
<div>
|
|
<DataLabel label={t("jobs.fields.ro_number")}>
|
|
{(event.job && event.job.ro_number) || ""}
|
|
</DataLabel>
|
|
<DataLabel label={t("jobs.fields.clm_total")}>
|
|
<CurrencyFormatter>
|
|
{(event.job && event.job.clm_total) || ""}
|
|
</CurrencyFormatter>
|
|
</DataLabel>
|
|
<DataLabel hideIfNull label={t("jobs.fields.ins_co_nm")}>
|
|
{(event.job && event.job.ins_co_nm) || ""}
|
|
</DataLabel>
|
|
<DataLabel hideIfNull label={t("jobs.fields.clm_no")}>
|
|
{(event.job && event.job.clm_no) || ""}
|
|
</DataLabel>
|
|
<DataLabel label={t("jobs.fields.ownr_ea")}>
|
|
{(event.job && event.job.ownr_ea) || ""}
|
|
</DataLabel>
|
|
<DataLabel label={t("jobs.fields.ownr_ph1")}>
|
|
<PhoneFormatter>
|
|
{(event.job && event.job.ownr_ph1) || ""}
|
|
</PhoneFormatter>
|
|
</DataLabel>
|
|
<DataLabel label={t("jobs.fields.alt_transport")}>
|
|
{(event.job && event.job.alt_transport) || ""}
|
|
<ScheduleAtChange job={event && event.job} />
|
|
</DataLabel>
|
|
</div>
|
|
) : null}
|
|
|
|
<Space wrap>
|
|
{event.job ? (
|
|
<Link to={`/manage/jobs/${event.job && event.job.id}`}>
|
|
<Button>{t("appointments.actions.viewjob")}</Button>
|
|
</Link>
|
|
) : null}
|
|
{event.job ? (
|
|
<Button
|
|
onClick={() => {
|
|
history.push({
|
|
search: queryString.stringify({
|
|
...searchParams,
|
|
selected: event.job.id,
|
|
}),
|
|
});
|
|
}}
|
|
>
|
|
{t("appointments.actions.preview")}
|
|
</Button>
|
|
) : null}
|
|
<Button
|
|
onClick={() => {
|
|
const Template = TemplateList("job").appointment_reminder;
|
|
GenerateDocument(
|
|
{
|
|
name: Template.key,
|
|
variables: { id: event.job.id },
|
|
},
|
|
{ to: event.job && event.job.ownr_ea, subject: Template.subject },
|
|
"e",
|
|
event.job && event.job.id
|
|
);
|
|
}}
|
|
disabled={event.arrived}
|
|
>
|
|
{t("appointments.actions.sendreminder")}
|
|
</Button>
|
|
<Button onClick={() => handleCancel(event.id)} disabled={event.arrived}>
|
|
{t("appointments.actions.cancel")}
|
|
</Button>
|
|
<Button
|
|
disabled={event.arrived}
|
|
onClick={() => {
|
|
setVisible(false);
|
|
setScheduleContext({
|
|
actions: { refetch: refetch },
|
|
context: {
|
|
jobId: event.job.id,
|
|
job: event.job,
|
|
previousEvent: event.id,
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
{t("appointments.actions.reschedule")}
|
|
</Button>
|
|
{event.isintake ? (
|
|
<Link
|
|
to={{
|
|
pathname: `/manage/jobs/${event.job && event.job.id}/intake`,
|
|
search: `?appointmentId=${event.id}`,
|
|
}}
|
|
>
|
|
<Button disabled={event.arrived}>
|
|
{t("appointments.actions.intake")}
|
|
</Button>
|
|
</Link>
|
|
) : null}
|
|
</Space>
|
|
</div>
|
|
);
|
|
|
|
const RegularEvent = event.isintake ? (
|
|
<div style={{ display: "flex", flexWrap: "wrap" }}>
|
|
<Space>
|
|
<strong>{`${event.job.ro_number || t("general.labels.na")}`}</strong>
|
|
<span>{`${(event.job && event.job.ownr_fn) || ""} ${
|
|
(event.job && event.job.ownr_ln) || ""
|
|
} ${(event.job && event.job.ownr_co_nm) || ""}`}</span>
|
|
</Space>
|
|
<Space>
|
|
<span>
|
|
{`${(event.job && event.job.v_model_yr) || ""} ${
|
|
(event.job && event.job.v_make_desc) || ""
|
|
} ${(event.job && event.job.v_model_desc) || ""}`}
|
|
</span>
|
|
<span>
|
|
{`(${
|
|
(event.job && event.job.labhrs.aggregate.sum.mod_lb_hrs) || "0"
|
|
} / ${
|
|
(event.job && event.job.larhrs.aggregate.sum.mod_lb_hrs) || "0"
|
|
})`}
|
|
</span>
|
|
</Space>
|
|
{event.job && event.job.alt_transport && (
|
|
<div style={{ margin: ".1rem" }}>{event.job.alt_transport}</div>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<div>
|
|
<strong>{`${event.title || ""}`}</strong>
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<Popover
|
|
visible={visible}
|
|
onVisibleChange={(vis) => setVisible(vis)}
|
|
trigger="click"
|
|
content={event.block ? blockContent : popoverContent}
|
|
style={{ height: "100%", width: "100%" }}
|
|
>
|
|
{RegularEvent}
|
|
</Popover>
|
|
);
|
|
}
|
|
export default connect(null, mapDispatchToProps)(ScheduleEventComponent);
|