- the great reformat

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-02-06 18:20:58 -05:00
parent 30c530bcc4
commit e83badb454
912 changed files with 108516 additions and 107493 deletions

View File

@@ -1,54 +1,55 @@
import { Form, Select } from "antd";
import {Form, Select} from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {useTranslation} from "react-i18next";
import {connect} from "react-redux";
import {createStructuredSelector} from "reselect";
import {selectBodyshop} from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
bodyshop: selectBodyshop,
//currentUser: selectCurrentUser
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export function TimeTicketShiftFormComponent({ bodyshop, form }) {
const { t } = useTranslation();
return (
<div>
<Form.Item
name="memo"
label={t("timetickets.fields.memo")}
rules={[
{
required: true,
//message: t("general.validation.required"),
},
]}
>
<Select>
<Select.Option value="timetickets.labels.amshift">
{t("timetickets.labels.amshift")}
</Select.Option>
<Select.Option value="timetickets.labels.ambreak">
{t("timetickets.labels.ambreak")}
</Select.Option>
<Select.Option value="timetickets.labels.lunch">
{t("timetickets.labels.lunch")}
</Select.Option>
<Select.Option value="timetickets.labels.pmshift">
{t("timetickets.labels.pmshift")}
</Select.Option>
<Select.Option value="timetickets.labels.pmbreak">
{t("timetickets.labels.pmbreak")}
</Select.Option>
</Select>
</Form.Item>
</div>
);
export function TimeTicketShiftFormComponent({bodyshop, form}) {
const {t} = useTranslation();
return (
<div>
<Form.Item
name="memo"
label={t("timetickets.fields.memo")}
rules={[
{
required: true,
//message: t("general.validation.required"),
},
]}
>
<Select>
<Select.Option value="timetickets.labels.amshift">
{t("timetickets.labels.amshift")}
</Select.Option>
<Select.Option value="timetickets.labels.ambreak">
{t("timetickets.labels.ambreak")}
</Select.Option>
<Select.Option value="timetickets.labels.lunch">
{t("timetickets.labels.lunch")}
</Select.Option>
<Select.Option value="timetickets.labels.pmshift">
{t("timetickets.labels.pmshift")}
</Select.Option>
<Select.Option value="timetickets.labels.pmbreak">
{t("timetickets.labels.pmbreak")}
</Select.Option>
</Select>
</Form.Item>
</div>
);
}
export default connect(
mapStateToProps,
mapDispatchToProps
mapStateToProps,
mapDispatchToProps
)(TimeTicketShiftFormComponent);

View File

@@ -1,144 +1,143 @@
import { useMutation } from "@apollo/client";
import { Button, Form, Space, notification } from "antd";
import {useMutation} from "@apollo/client";
import {Button, Form, notification, Space} from "antd";
import axios from "axios";
import dayjs from "../../utils/day";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { INSERT_NEW_TIME_TICKET } from "../../graphql/timetickets.queries";
import { selectTechnician } from "../../redux/tech/tech.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import React, {useMemo, useState} from "react";
import {useTranslation} from "react-i18next";
import {connect} from "react-redux";
import {createStructuredSelector} from "reselect";
import {INSERT_NEW_TIME_TICKET} from "../../graphql/timetickets.queries";
import {selectTechnician} from "../../redux/tech/tech.selectors";
import {selectBodyshop, selectCurrentUser,} from "../../redux/user/user.selectors";
import TechJobPrintTickets from "../tech-job-print-tickets/tech-job-print-tickets.component";
import TimeTicektShiftComponent from "./time-ticket-shift-form.component";
const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser,
bodyshop: selectBodyshop,
technician: selectTechnician,
currentUser: selectCurrentUser,
bodyshop: selectBodyshop,
technician: selectTechnician,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export function TimeTicektShiftContainer({
bodyshop,
technician,
currentUser,
isTechConsole,
checkIfAlreadyClocked,
}) {
console.log(
"🚀 ~ file: time-ticket-shift-form.container.jsx:28 ~ technician:",
technician
);
const [form] = Form.useForm();
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET);
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
bodyshop,
technician,
currentUser,
isTechConsole,
checkIfAlreadyClocked,
}) {
console.log(
"🚀 ~ file: time-ticket-shift-form.container.jsx:28 ~ technician:",
technician
);
const [form] = Form.useForm();
const [insertTimeTicket] = useMutation(INSERT_NEW_TIME_TICKET);
const {t} = useTranslation();
const [loading, setLoading] = useState(false);
const employeeId = useMemo(() => {
const assoc = bodyshop.associations.filter(
(a) => a.useremail === currentUser.email
)[0];
const employeeId = useMemo(() => {
const assoc = bodyshop.associations.filter(
(a) => a.useremail === currentUser.email
)[0];
return assoc && assoc.user && assoc.user.employee && assoc.user.employee.id;
}, [bodyshop, currentUser.email]);
return assoc && assoc.user && assoc.user.employee && assoc.user.employee.id;
}, [bodyshop, currentUser.email]);
const handleFinish = async (values) => {
setLoading(true);
const handleFinish = async (values) => {
setLoading(true);
const alreadyClocked = await checkIfAlreadyClocked();
const alreadyClocked = await checkIfAlreadyClocked();
if (alreadyClocked) {
//Show the error.
notification["error"]({
message: t("timetickets.errors.shiftalreadyclockedon"),
});
} else {
const theTime = dayjs((await axios.post("/utils/time")).data);
if (alreadyClocked) {
//Show the error.
notification["error"]({
message: t("timetickets.errors.shiftalreadyclockedon"),
});
} else {
const theTime = dayjs((await axios.post("/utils/time")).data);
const result = await insertTimeTicket({
variables: {
timeTicketInput: [
{
bodyshopid: bodyshop.id,
employeeid: isTechConsole ? technician.id : employeeId,
cost_center: "timetickets.labels.shift",
clockon: theTime,
date:
typeof bodyshop.timezone === "string"
// TODO: Client Update - This may be broken
? dayjs.tz(theTime, bodyshop.timezone).format("YYYY-MM-DD")
: typeof bodyshop.timezone === "number"
? dayjs(theTime)
.utcOffset(bodyshop.timezone)
.format("YYYY-MM-DD")
: dayjs(theTime).format("YYYY-MM-DD"),
memo: values.memo,
created_by: isTechConsole
? currentUser.email.concat(
" | ",
technician.employee_number
.concat(
" ",
technician.first_name,
" ",
technician.last_name
)
.trim()
)
: currentUser.displayName
? currentUser.email.concat(" | ", currentUser.displayName)
: currentUser.email,
},
],
},
awaitRefetchQueries: true,
refetchQueries: ["QUERY_ACTIVE_SHIFT_TIME_TICKETS"],
});
const result = await insertTimeTicket({
variables: {
timeTicketInput: [
{
bodyshopid: bodyshop.id,
employeeid: isTechConsole ? technician.id : employeeId,
cost_center: "timetickets.labels.shift",
clockon: theTime,
date:
typeof bodyshop.timezone === "string"
// TODO: Client Update - This may be broken
? dayjs.tz(theTime, bodyshop.timezone).format("YYYY-MM-DD")
: typeof bodyshop.timezone === "number"
? dayjs(theTime)
.utcOffset(bodyshop.timezone)
.format("YYYY-MM-DD")
: dayjs(theTime).format("YYYY-MM-DD"),
memo: values.memo,
created_by: isTechConsole
? currentUser.email.concat(
" | ",
technician.employee_number
.concat(
" ",
technician.first_name,
" ",
technician.last_name
)
.trim()
)
: currentUser.displayName
? currentUser.email.concat(" | ", currentUser.displayName)
: currentUser.email,
},
],
},
awaitRefetchQueries: true,
refetchQueries: ["QUERY_ACTIVE_SHIFT_TIME_TICKETS"],
});
if (!!result.errors) {
notification["error"]({
message: t("timetickets.errors.clockingin", {
message: JSON.stringify(result.errors),
}),
});
} else {
notification["success"]({
message: t("timetickets.successes.clockedin"),
});
}
}
if (!!result.errors) {
notification["error"]({
message: t("timetickets.errors.clockingin", {
message: JSON.stringify(result.errors),
}),
});
} else {
notification["success"]({
message: t("timetickets.successes.clockedin"),
});
}
}
setLoading(false);
};
setLoading(false);
};
return (
<div>
<Form
form={form}
layout="vertical"
autoComplete="no"
onFinish={handleFinish}
initialValues={{ cost_center: t("timetickets.labels.shift") }}
>
<TimeTicektShiftComponent form={form} />
<Space wrap>
<Button htmlType="submit" loading={loading} type="primary">
{t("timetickets.actions.clockin")}
</Button>
{isTechConsole === true ? (
<TechJobPrintTickets attendacePrint={true} />
) : null}
</Space>
</Form>
</div>
);
return (
<div>
<Form
form={form}
layout="vertical"
autoComplete="no"
onFinish={handleFinish}
initialValues={{cost_center: t("timetickets.labels.shift")}}
>
<TimeTicektShiftComponent form={form}/>
<Space wrap>
<Button htmlType="submit" loading={loading} type="primary">
{t("timetickets.actions.clockin")}
</Button>
{isTechConsole === true ? (
<TechJobPrintTickets attendacePrint={true}/>
) : null}
</Space>
</Form>
</div>
);
}
export default connect(
mapStateToProps,
mapDispatchToProps
mapStateToProps,
mapDispatchToProps
)(TimeTicektShiftContainer);