Changes in Prettier
This commit is contained in:
Allan Carr
2023-04-20 09:46:21 -07:00
parent 7725080a11
commit 2a0ad46eea

View File

@@ -1,14 +1,14 @@
import { useLazyQuery } from "@apollo/client"; import { useLazyQuery } from "@apollo/client";
import { import {
Button, Button,
Card, Card,
Col, Col,
DatePicker, DatePicker,
Form, Form,
Input, Input,
Radio, Radio,
Row, Row,
Typography, Typography,
} from "antd"; } from "antd";
import _ from "lodash"; import _ from "lodash";
import moment from "moment"; import moment from "moment";
@@ -26,281 +26,281 @@ import EmployeeSearchSelect from "../employee-search-select/employee-search-sele
import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component"; import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component";
import "./report-center-modal.styles.scss"; import "./report-center-modal.styles.scss";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
reportCenterModal: selectReportCenter, reportCenterModal: selectReportCenter,
}); });
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language)) //setUserLanguage: language => dispatch(setUserLanguage(language))
}); });
export default connect( export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(ReportCenterModalComponent); )(ReportCenterModalComponent);
export function ReportCenterModalComponent({ reportCenterModal }) { export function ReportCenterModalComponent({ reportCenterModal }) {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const { t } = useTranslation(); const { t } = useTranslation();
const Templates = TemplateList("report_center"); const Templates = TemplateList("report_center");
const ReportsList = Object.keys(Templates).map((key) => { const ReportsList = Object.keys(Templates).map((key) => {
return Templates[key]; return Templates[key];
}); });
const { visible } = reportCenterModal; const { visible } = reportCenterModal;
const [callVendorQuery, { data: vendorData, called: vendorCalled }] = const [callVendorQuery, { data: vendorData, called: vendorCalled }] =
useLazyQuery(QUERY_ALL_VENDORS, { useLazyQuery(QUERY_ALL_VENDORS, {
skip: !( skip: !(
visible && visible &&
Templates[form.getFieldValue("key")] && Templates[form.getFieldValue("key")] &&
Templates[form.getFieldValue("key")].idtype Templates[form.getFieldValue("key")].idtype
), ),
}); });
const [callEmployeeQuery, { data: employeeData, called: employeeCalled }] = const [callEmployeeQuery, { data: employeeData, called: employeeCalled }] =
useLazyQuery(QUERY_ACTIVE_EMPLOYEES, { useLazyQuery(QUERY_ACTIVE_EMPLOYEES, {
skip: !( skip: !(
visible && visible &&
Templates[form.getFieldValue("key")] && Templates[form.getFieldValue("key")] &&
Templates[form.getFieldValue("key")].idtype Templates[form.getFieldValue("key")].idtype
), ),
}); });
const handleFinish = async (values) => { const handleFinish = async (values) => {
setLoading(true); setLoading(true);
const start = values.dates[0]; const start = values.dates[0];
const end = values.dates[1]; const end = values.dates[1];
const { id } = values; const { id } = values;
await GenerateDocument( await GenerateDocument(
{ {
name: values.key, name: values.key,
variables: { variables: {
...(start ...(start
? { start: moment(start).startOf("day").format("YYYY-MM-DD") } ? { start: moment(start).startOf("day").format("YYYY-MM-DD") }
: {}), : {}),
...(end ...(end
? { end: moment(end).endOf("day").format("YYYY-MM-DD") } ? { end: moment(end).endOf("day").format("YYYY-MM-DD") }
: {}), : {}),
...(start ? { starttz: moment(start).startOf("day") } : {}), ...(start ? { starttz: moment(start).startOf("day") } : {}),
...(end ? { endtz: moment(end).endOf("day") } : {}), ...(end ? { endtz: moment(end).endOf("day") } : {}),
...(id ? { id: id } : {}), ...(id ? { id: id } : {}),
}, },
}, },
{ {
to: values.to, to: values.to,
subject: Templates[values.key]?.subject, subject: Templates[values.key]?.subject,
}, },
values.sendby === "excel" ? "x" : values.sendby === "email" ? "e" : "p", values.sendby === "excel" ? "x" : values.sendby === "email" ? "e" : "p",
id id
); );
setLoading(false); setLoading(false);
}; };
const FilteredReportsList = const FilteredReportsList =
search !== "" search !== ""
? ReportsList.filter((r) => ? ReportsList.filter((r) =>
r.title.toLowerCase().includes(search.toLowerCase()) r.title.toLowerCase().includes(search.toLowerCase())
) )
: ReportsList; : ReportsList;
//Group it, create cards, and then filter out. //Group it, create cards, and then filter out.
const grouped = _.groupBy(FilteredReportsList, "group"); const grouped = _.groupBy(FilteredReportsList, "group");
return ( return (
<div> <div>
<Form <Form
onFinish={handleFinish} onFinish={handleFinish}
autoComplete={"off"} autoComplete={"off"}
layout="vertical" layout="vertical"
form={form} form={form}
> >
<Input.Search <Input.Search
onChange={(e) => setSearch(e.target.value)} onChange={(e) => setSearch(e.target.value)}
value={search} value={search}
/> />
<Form.Item <Form.Item
name="key" name="key"
label={t("reportcenter.labels.key")} label={t("reportcenter.labels.key")}
// className="radio-group-columns" // className="radio-group-columns"
rules={[ rules={[
{ {
required: true, required: true,
//message: t("general.validation.required"), //message: t("general.validation.required"),
}, },
]} ]}
> >
<Radio.Group> <Radio.Group>
{/* {Object.keys(Templates).map((key) => ( {/* {Object.keys(Templates).map((key) => (
<Radio key={key} value={key}> <Radio key={key} value={key}>
{Templates[key].title} {Templates[key].title}
</Radio> </Radio>
))} */} ))} */}
<Row gutter={[16, 16]}> <Row gutter={[16, 16]}>
{Object.keys(grouped).map((key) => ( {Object.keys(grouped).map((key) => (
<Col md={8} sm={12} key={key}> <Col md={8} sm={12} key={key}>
<Card.Grid <Card.Grid
style={{ style={{
width: "100%", width: "100%",
height: "100%", height: "100%",
maxHeight: "33vh", maxHeight: "33vh",
overflowY: "scroll", overflowY: "scroll",
}} }}
> >
<Typography.Title level={4}> <Typography.Title level={4}>
{t(`reportcenter.labels.groups.${key}`)} {t(`reportcenter.labels.groups.${key}`)}
</Typography.Title> </Typography.Title>
<ul style={{ columns: "2 auto" }}> <ul style={{ columns: "2 auto" }}>
{grouped[key].map((item) => ( {grouped[key].map((item) => (
<li key={item.key}> <li key={item.key}>
<Radio key={item.key} value={item.key}> <Radio key={item.key} value={item.key}>
{item.title} {item.title}
</Radio> </Radio>
</li> </li>
))} ))}
</ul> </ul>
</Card.Grid> </Card.Grid>
</Col> </Col>
))} ))}
</Row> </Row>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Form.Item style={{ margin: 0, padding: 0 }} dependencies={["key"]}> <Form.Item style={{ margin: 0, padding: 0 }} dependencies={["key"]}>
{() => { {() => {
const key = form.getFieldValue("key"); const key = form.getFieldValue("key");
if (!key) return null; if (!key) return null;
//Kind of Id //Kind of Id
const rangeFilter = Templates[key] && Templates[key].rangeFilter; const rangeFilter = Templates[key] && Templates[key].rangeFilter;
if (!rangeFilter) return null; if (!rangeFilter) return null;
return ( return (
<div> <div>
{t("reportcenter.labels.filterson", { {t("reportcenter.labels.filterson", {
object: rangeFilter.object, object: rangeFilter.object,
field: rangeFilter.field, field: rangeFilter.field,
})} })}
</div> </div>
); );
}} }}
</Form.Item> </Form.Item>
<Form.Item style={{ margin: 0, padding: 0 }} dependencies={["key"]}> <Form.Item style={{ margin: 0, padding: 0 }} dependencies={["key"]}>
{() => { {() => {
const key = form.getFieldValue("key"); const key = form.getFieldValue("key");
const currentId = form.getFieldValue("id"); const currentId = form.getFieldValue("id");
if (!key) return null; if (!key) return null;
//Kind of Id //Kind of Id
const idtype = Templates[key] && Templates[key].idtype; const idtype = Templates[key] && Templates[key].idtype;
if (!idtype && currentId) { if (!idtype && currentId) {
form.setFieldsValue({ id: null }); form.setFieldsValue({ id: null });
return null; return null;
} }
if (!vendorCalled && idtype === "vendor") callVendorQuery(); if (!vendorCalled && idtype === "vendor") callVendorQuery();
if (!employeeCalled && idtype === "employee") callEmployeeQuery(); if (!employeeCalled && idtype === "employee") callEmployeeQuery();
if (idtype === "vendor") if (idtype === "vendor")
return ( return (
<Form.Item <Form.Item
name="id" name="id"
label={t("reportcenter.labels.vendor")} label={t("reportcenter.labels.vendor")}
rules={[ rules={[
{ {
required: true, required: true,
//message: t("general.validation.required"), //message: t("general.validation.required"),
}, },
]} ]}
> >
<VendorSearchSelect <VendorSearchSelect
options={vendorData ? vendorData.vendors : []} options={vendorData ? vendorData.vendors : []}
/> />
</Form.Item> </Form.Item>
); );
if (idtype === "employee") if (idtype === "employee")
return ( return (
<Form.Item <Form.Item
name="id" name="id"
label={t("reportcenter.labels.employee")} label={t("reportcenter.labels.employee")}
rules={[ rules={[
{ {
required: true, required: true,
//message: t("general.validation.required"), //message: t("general.validation.required"),
}, },
]} ]}
> >
<EmployeeSearchSelect <EmployeeSearchSelect
options={employeeData ? employeeData.employees : []} options={employeeData ? employeeData.employees : []}
/> />
</Form.Item> </Form.Item>
); );
else return null; else return null;
}} }}
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="dates" name="dates"
label={t("reportcenter.labels.dates")} label={t("reportcenter.labels.dates")}
rules={[ rules={[
{ {
required: true, required: true,
//message: t("general.validation.required"), //message: t("general.validation.required"),
}, },
]} ]}
> >
<DatePicker.RangePicker <DatePicker.RangePicker
format="MM/DD/YYYY" format="MM/DD/YYYY"
ranges={DatePIckerRanges} ranges={DatePIckerRanges}
/> />
</Form.Item> </Form.Item>
<Form.Item style={{ margin: 0, padding: 0 }} dependencies={["key"]}> <Form.Item style={{ margin: 0, padding: 0 }} dependencies={["key"]}>
{() => { {() => {
const key = form.getFieldValue("key"); const key = form.getFieldValue("key");
const currentId = form.getFieldValue("id"); const currentId = form.getFieldValue("id");
if (!key) return null; if (!key) return null;
//Kind of Id //Kind of Id
const idtype = Templates[key] && Templates[key].idtype; const idtype = Templates[key] && Templates[key].idtype;
if (!idtype && currentId) { if (!idtype && currentId) {
form.setFieldsValue({ id: null }); form.setFieldsValue({ id: null });
return null; return null;
} }
if (idtype === "excel") if (idtype === "excel")
return ( return (
<Form.Item <Form.Item
label={t("general.labels.sendby")} label={t("general.labels.sendby")}
name="sendby" name="sendby"
initialValue="print" initialValue="print"
> >
<Radio.Group> <Radio.Group>
<Radio value="excel">{t("general.labels.excel")}</Radio> <Radio value="excel">{t("general.labels.excel")}</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
); );
if (idtype !== "excel") if (idtype !== "excel")
return ( return (
<Form.Item <Form.Item
label={t("general.labels.sendby")} label={t("general.labels.sendby")}
name="sendby" name="sendby"
initialValue="print" initialValue="print"
> >
<Radio.Group> <Radio.Group>
<Radio value="email">{t("general.labels.email")}</Radio> <Radio value="email">{t("general.labels.email")}</Radio>
<Radio value="print">{t("general.labels.print")}</Radio> <Radio value="print">{t("general.labels.print")}</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
); );
}} }}
</Form.Item> </Form.Item>
<div <div
style={{ style={{
display: "flex", display: "flex",
justifyContent: "center", justifyContent: "center",
marginTop: "1rem", marginTop: "1rem",
}} }}
> >
<Button onClick={() => form.submit()} style={{}} loading={loading}> <Button onClick={() => form.submit()} style={{}} loading={loading}>
{t("reportcenter.actions.generate")} {t("reportcenter.actions.generate")}
</Button> </Button>
</div> </div>
</Form> </Form>
</div> </div>
); );
} }