From 7b129076e9bdcf91f4025548742fbdb9ff4b541f Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 23 Mar 2021 08:46:03 -0700 Subject: [PATCH] IO-777 Added employee select to report center. --- bodyshop_translations.babel | 21 ++++++++ .../report-center-modal.component.jsx | 53 ++++++++++++++++--- client/src/translations/en_us/common.json | 1 + client/src/translations/es/common.json | 1 + client/src/translations/fr/common.json | 1 + client/src/utils/TemplateConstants.js | 19 +++---- 6 files changed, 80 insertions(+), 16 deletions(-) diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 285be0ac8..465de8c3b 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -27410,6 +27410,27 @@ + + employee + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + generateasemail false diff --git a/client/src/components/report-center-modal/report-center-modal.component.jsx b/client/src/components/report-center-modal/report-center-modal.component.jsx index c8202658d..652b86aa7 100644 --- a/client/src/components/report-center-modal/report-center-modal.component.jsx +++ b/client/src/components/report-center-modal/report-center-modal.component.jsx @@ -1,7 +1,7 @@ import { useLazyQuery } from "@apollo/client"; import { Button, DatePicker, Form, Select, Switch } from "antd"; import moment from "moment"; -import React from "react"; +import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; @@ -11,6 +11,8 @@ import { GenerateDocument } from "../../utils/RenderTemplate"; import { TemplateList } from "../../utils/TemplateConstants"; import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component"; import DatePIckerRanges from "../../utils/DatePickerRanges"; +import EmployeeSearchSelect from "../employee-search-select/employee-search-select.component"; +import { QUERY_ACTIVE_EMPLOYEES } from "../../graphql/employees.queries"; const mapStateToProps = createStructuredSelector({ reportCenterModal: selectReportCenter, @@ -25,11 +27,15 @@ export default connect( export function ReportCenterModalComponent({ reportCenterModal }) { const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); const { t } = useTranslation(); const Templates = TemplateList("report_center"); const { visible } = reportCenterModal; - const [callVendorQuery, { data, called }] = useLazyQuery(QUERY_ALL_VENDORS, { + const [ + callVendorQuery, + { data: vendorData, called: vendorCalled }, + ] = useLazyQuery(QUERY_ALL_VENDORS, { skip: !( visible && Templates[form.getFieldValue("key")] && @@ -37,12 +43,24 @@ export function ReportCenterModalComponent({ reportCenterModal }) { ), }); - const handleFinish = (values) => { + const [ + callEmployeeQuery, + { data: employeeData, called: employeeCalled }, + ] = useLazyQuery(QUERY_ACTIVE_EMPLOYEES, { + skip: !( + visible && + Templates[form.getFieldValue("key")] && + Templates[form.getFieldValue("key")].idtype + ), + }); + + const handleFinish = async (values) => { + setLoading(true); const start = values.dates[0]; const end = values.dates[1]; const { id } = values; console.log("values", values); - GenerateDocument( + await GenerateDocument( { name: values.key, variables: { @@ -56,6 +74,7 @@ export function ReportCenterModalComponent({ reportCenterModal }) { }, values.email ? "e" : "p" ); + setLoading(false); }; return ( @@ -89,7 +108,8 @@ export function ReportCenterModalComponent({ reportCenterModal }) { //Kind of Id const idtype = Templates[key] && Templates[key].idtype; if (!idtype) return null; - if (!called && idtype === "vendor") callVendorQuery(); + if (!vendorCalled && idtype === "vendor") callVendorQuery(); + if (!employeeCalled && idtype === "employee") callEmployeeQuery(); if (idtype === "vendor") return ( - + + + ); + if (idtype === "employee") + return ( + + ); else return null; @@ -138,7 +177,7 @@ export function ReportCenterModalComponent({ reportCenterModal }) { marginTop: "1rem", }} > - diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 8bf6acdcf..92313b507 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1662,6 +1662,7 @@ }, "labels": { "dates": "Dates", + "employee": "Employee", "generateasemail": "Generate as Email?", "key": "Report", "vendor": "Vendor" diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index dcba5ec87..be2219678 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1662,6 +1662,7 @@ }, "labels": { "dates": "", + "employee": "", "generateasemail": "", "key": "", "vendor": "" diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 7e036deb0..b70d37225 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1662,6 +1662,7 @@ }, "labels": { "dates": "", + "employee": "", "generateasemail": "", "key": "", "vendor": "" diff --git a/client/src/utils/TemplateConstants.js b/client/src/utils/TemplateConstants.js index bef2ee906..c0133c618 100644 --- a/client/src/utils/TemplateConstants.js +++ b/client/src/utils/TemplateConstants.js @@ -326,13 +326,7 @@ export const TemplateList = (type, context) => { key: "schedule", disabled: false, }, - timetickets: { - title: i18n.t("reportcenter.templates.timetickets"), - description: "Est Detail", - subject: i18n.t("reportcenter.templates.timetickets"), - key: "timetickets", - disabled: false, - }, + purchases_by_vendor_detailed_date_range: { title: i18n.t( "reportcenter.templates.purchases_by_vendor_detailed_date_range" @@ -357,12 +351,19 @@ export const TemplateList = (type, context) => { idtype: "vendor", disabled: false, }, + timetickets: { + title: i18n.t("reportcenter.templates.timetickets"), + description: "Est Detail", + subject: i18n.t("reportcenter.templates.timetickets"), + key: "timetickets", + disabled: false, + }, timetickets_employee: { title: i18n.t("reportcenter.templates.timetickets_employee"), description: "Est Detail", subject: i18n.t("reportcenter.templates.timetickets_employee"), key: "timetickets_employee", - idtype: "vendor", + idtype: "employee", disabled: false, }, timetickets_summary: { @@ -370,7 +371,7 @@ export const TemplateList = (type, context) => { description: "Est Detail", subject: i18n.t("reportcenter.templates.timetickets_summary"), key: "timetickets_summary", - idtype: "vendor", + //idtype: "vendor", disabled: false, }, }