From 413400fa7164bc152225e67d7452a6985a37b327 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 19 Jan 2022 12:45:16 -0800 Subject: [PATCH] IO-1652 Printing tickets from tech console. --- .../tech-job-clock-in-form.container.jsx | 16 ++- .../tech-job-print-tickets.component.jsx | 125 ++++++++++++++++++ 2 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 client/src/components/tech-job-print-tickets/tech-job-print-tickets.component.jsx diff --git a/client/src/components/tech-job-clock-in-form/tech-job-clock-in-form.container.jsx b/client/src/components/tech-job-clock-in-form/tech-job-clock-in-form.container.jsx index 499f40af1..eeff6d2de 100644 --- a/client/src/components/tech-job-clock-in-form/tech-job-clock-in-form.container.jsx +++ b/client/src/components/tech-job-clock-in-form/tech-job-clock-in-form.container.jsx @@ -1,5 +1,5 @@ import { useMutation } from "@apollo/client"; -import { Button, Card, Form, notification } from "antd"; +import { Button, Card, Form, notification, Space } from "antd"; import axios from "axios"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; @@ -9,6 +9,7 @@ import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries"; import { selectTechnician } from "../../redux/tech/tech.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors"; import TechClockInComponent from "./tech-job-clock-in-form.component"; +import TechJobPrintTickets from "../tech-job-print-tickets/tech-job-print-tickets.component"; const mapStateToProps = createStructuredSelector({ technician: selectTechnician, @@ -71,9 +72,16 @@ export function TechClockInContainer({ technician, bodyshop }) { form.submit()} loading={loading}> - {t("timetickets.actions.clockin")} - + + + + } >
diff --git a/client/src/components/tech-job-print-tickets/tech-job-print-tickets.component.jsx b/client/src/components/tech-job-print-tickets/tech-job-print-tickets.component.jsx new file mode 100644 index 000000000..e09691a65 --- /dev/null +++ b/client/src/components/tech-job-print-tickets/tech-job-print-tickets.component.jsx @@ -0,0 +1,125 @@ +import { Button, Card, DatePicker, Form, Popover, Space } from "antd"; +import moment from "moment"; +import React, { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { logImEXEvent } from "../../firebase/firebase.utils"; +import { selectTechnician } from "../../redux/tech/tech.selectors"; +import DatePIckerRanges from "../../utils/DatePickerRanges"; +import { GenerateDocument } from "../../utils/RenderTemplate"; +import { TemplateList } from "../../utils/TemplateConstants"; + +const mapStateToProps = createStructuredSelector({ + technician: selectTechnician, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect( + mapStateToProps, + mapDispatchToProps +)(TechJobPrintTickets); + +export function TechJobPrintTickets({ technician, event }) { + const { t } = useTranslation(); + + const [loading, setLoading] = useState(false); + const [form] = Form.useForm(); + const [visibility, setVisibility] = useState(false); + + useEffect(() => { + if (visibility && event) { + form.setFieldsValue(event); + } + }, [visibility, form, event]); + + const handleFinish = async (values) => { + logImEXEvent("schedule_manual_event"); + + setLoading(true); + const start = values.dates[0]; + const end = values.dates[1]; + + try { + await GenerateDocument( + { + name: TemplateList().timetickets_employee.key, + variables: { + ...(start + ? { start: moment(start).startOf("day").format("YYYY-MM-DD") } + : {}), + ...(end + ? { end: moment(end).endOf("day").format("YYYY-MM-DD") } + : {}), + ...(start ? { starttz: moment(start).startOf("day") } : {}), + ...(end ? { endtz: moment(end).endOf("day") } : {}), + + id: technician.id, + }, + }, + { + to: technician.email, + subject: TemplateList().timetickets_employee.subject, + }, + "p" + ); + } catch (error) { + console.log(error); + } finally { + setLoading(false); + setVisibility(false); + form.resetFields(); + } + }; + + const overlay = ( + +
+ + + + + + + + + + +
+
+ ); + + const handleClick = (e) => { + setVisibility(true); + }; + + return ( + + + + ); +}