IO-1283 IO-1371 Updates to add to scoreboard button.
This commit is contained in:
@@ -1,11 +1,24 @@
|
|||||||
import { useMutation } from "@apollo/client";
|
import { useMutation, useLazyQuery } from "@apollo/client";
|
||||||
import { Button, Card, Form, InputNumber, notification, Popover } from "antd";
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Form,
|
||||||
|
InputNumber,
|
||||||
|
notification,
|
||||||
|
Popover,
|
||||||
|
Space,
|
||||||
|
} from "antd";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import React, { useState } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import { INSERT_SCOREBOARD_ENTRY } from "../../graphql/scoreboard.queries";
|
import {
|
||||||
|
INSERT_SCOREBOARD_ENTRY,
|
||||||
|
QUERY_SCOREBOARD_ENTRY,
|
||||||
|
UPDATE_SCOREBOARD_ENTRY,
|
||||||
|
} from "../../graphql/scoreboard.queries";
|
||||||
import FormDatePicker from "../form-date-picker/form-date-picker.component";
|
import FormDatePicker from "../form-date-picker/form-date-picker.component";
|
||||||
|
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
||||||
|
|
||||||
export default function ScoreboardAddButton({
|
export default function ScoreboardAddButton({
|
||||||
job,
|
job,
|
||||||
@@ -14,17 +27,46 @@ export default function ScoreboardAddButton({
|
|||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [insertScoreboardEntry] = useMutation(INSERT_SCOREBOARD_ENTRY);
|
const [insertScoreboardEntry] = useMutation(INSERT_SCOREBOARD_ENTRY);
|
||||||
|
const [updateScoreboardEntry] = useMutation(UPDATE_SCOREBOARD_ENTRY);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [visibility, setVisibility] = useState(false);
|
const [visibility, setVisibility] = useState(false);
|
||||||
|
const [callQuery, { loading: entryLoading, data: entryData }] = useLazyQuery(
|
||||||
|
QUERY_SCOREBOARD_ENTRY
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (visibility) {
|
||||||
|
callQuery({ variables: { jobid: job.id } });
|
||||||
|
}
|
||||||
|
}, [visibility, job.id, callQuery]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("UE", entryData);
|
||||||
|
if (entryData && entryData.scoreboard && entryData.scoreboard[0]) {
|
||||||
|
console.log("Setting FOrm");
|
||||||
|
form.setFieldsValue(entryData.scoreboard[0]);
|
||||||
|
}
|
||||||
|
}, [entryData, form]);
|
||||||
|
|
||||||
const handleFinish = async (values) => {
|
const handleFinish = async (values) => {
|
||||||
logImEXEvent("job_close_add_to_scoreboard");
|
logImEXEvent("job_close_add_to_scoreboard");
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await insertScoreboardEntry({
|
let result;
|
||||||
variables: { sbInput: [{ jobid: job.id, ...values }] },
|
|
||||||
});
|
if (entryData && entryData.scoreboard && entryData.scoreboard[0]) {
|
||||||
|
result = await updateScoreboardEntry({
|
||||||
|
variables: {
|
||||||
|
sbId: entryData.scoreboard[0].id,
|
||||||
|
sbInput: values,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result = await insertScoreboardEntry({
|
||||||
|
variables: { sbInput: [{ jobid: job.id, ...values }] },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!!result.errors) {
|
if (!!result.errors) {
|
||||||
notification["error"]({
|
notification["error"]({
|
||||||
@@ -44,53 +86,62 @@ export default function ScoreboardAddButton({
|
|||||||
const overlay = (
|
const overlay = (
|
||||||
<Card>
|
<Card>
|
||||||
<div>
|
<div>
|
||||||
<Form
|
{entryLoading ? (
|
||||||
form={form}
|
<LoadingSpinner />
|
||||||
layout="vertical"
|
) : (
|
||||||
onFinish={handleFinish}
|
<Form
|
||||||
initialValues={{}}
|
form={form}
|
||||||
>
|
layout="vertical"
|
||||||
<Form.Item
|
onFinish={handleFinish}
|
||||||
label={t("scoreboard.fields.date")}
|
initialValues={{}}
|
||||||
name="date"
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
//message: t("general.validation.required"),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
<FormDatePicker />
|
<Form.Item
|
||||||
</Form.Item>
|
label={t("scoreboard.fields.date")}
|
||||||
<Form.Item
|
name="date"
|
||||||
label={t("scoreboard.fields.bodyhrs")}
|
rules={[
|
||||||
name="bodyhrs"
|
{
|
||||||
rules={[
|
required: true,
|
||||||
{
|
//message: t("general.validation.required"),
|
||||||
required: true,
|
},
|
||||||
//message: t("general.validation.required"),
|
]}
|
||||||
},
|
>
|
||||||
]}
|
<FormDatePicker />
|
||||||
>
|
</Form.Item>
|
||||||
<InputNumber precision={1} />
|
<Form.Item
|
||||||
</Form.Item>
|
label={t("scoreboard.fields.bodyhrs")}
|
||||||
<Form.Item
|
name="bodyhrs"
|
||||||
label={t("scoreboard.fields.painthrs")}
|
rules={[
|
||||||
name="painthrs"
|
{
|
||||||
rules={[
|
required: true,
|
||||||
{
|
//message: t("general.validation.required"),
|
||||||
required: true,
|
},
|
||||||
//message: t("general.validation.required"),
|
]}
|
||||||
},
|
>
|
||||||
]}
|
<InputNumber precision={1} />
|
||||||
>
|
</Form.Item>
|
||||||
<InputNumber precision={1} />
|
<Form.Item
|
||||||
</Form.Item>
|
label={t("scoreboard.fields.painthrs")}
|
||||||
|
name="painthrs"
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
//message: t("general.validation.required"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<InputNumber precision={1} />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
<Button type="primary" htmlType="submit">
|
<Space wrap>
|
||||||
{t("general.actions.save")}
|
<Button type="primary" htmlType="submit">
|
||||||
</Button>
|
{t("general.actions.save")}
|
||||||
</Form>
|
</Button>
|
||||||
|
<Button onClick={() => setVisibility(false)}>
|
||||||
|
{t("general.actions.cancel")}
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Form>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
@@ -99,7 +150,7 @@ export default function ScoreboardAddButton({
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const v = job.joblines.reduce(
|
const v = job.joblines.reduce(
|
||||||
(acc, val) => {
|
(acc, val) => {
|
||||||
if (val.mod_lbr_ty === "LAB")
|
if (val.mod_lbr_ty !== "LAR")
|
||||||
acc = { ...acc, bodyhrs: acc.bodyhrs + val.mod_lb_hrs };
|
acc = { ...acc, bodyhrs: acc.bodyhrs + val.mod_lb_hrs };
|
||||||
if (val.mod_lbr_ty === "LAR")
|
if (val.mod_lbr_ty === "LAR")
|
||||||
acc = { ...acc, painthrs: acc.painthrs + val.mod_lb_hrs };
|
acc = { ...acc, painthrs: acc.painthrs + val.mod_lb_hrs };
|
||||||
|
|||||||
@@ -51,3 +51,14 @@ export const UPDATE_SCOREBOARD_ENTRY = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const QUERY_SCOREBOARD_ENTRY = gql`
|
||||||
|
query QUERY_SCOREBOARD_ENTRY($jobid: uuid!) {
|
||||||
|
scoreboard(where: { jobid: { _eq: $jobid } }) {
|
||||||
|
bodyhrs
|
||||||
|
date
|
||||||
|
id
|
||||||
|
painthrs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user