Added add to and remove from scoreboard functionality. BOD-91

This commit is contained in:
Patrick Fic
2020-06-29 11:27:47 -07:00
parent 5650a66916
commit 0009f7d3bb
10 changed files with 253 additions and 3 deletions

View File

@@ -0,0 +1,125 @@
import { useMutation } from "@apollo/react-hooks";
import {
Button,
Card,
DatePicker,
Form,
InputNumber,
notification,
Popover,
} from "antd";
import moment from "moment";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { INSERT_SCOREBOARD_ENTRY } from "../../graphql/scoreboard.queries";
export default function ScoreboardAddButton({ job, ...otherBtnProps }) {
const { t } = useTranslation();
const [insertScoreboardEntry] = useMutation(INSERT_SCOREBOARD_ENTRY);
const [loading, setLoading] = useState(false);
const [form] = Form.useForm();
const [visibility, setVisibility] = useState(false);
const handleFinish = async (values) => {
setLoading(true);
const result = await insertScoreboardEntry({
variables: { sbInput: [{ jobid: job.id, ...values }] },
});
if (!!result.errors) {
notification["error"]({
message: t("scoreboard.errors.adding", {
message: JSON.stringify(result.errors),
}),
});
} else {
notification["success"]({
message: t("scoreboard.successes.added"),
});
}
setLoading(false);
setVisibility(false);
};
const overlay = (
<Card>
<div>
<Form
form={form}
layout='vertical'
onFinish={handleFinish}
initialValues={{}}>
<Form.Item
label={t("scoreboard.fields.date")}
name='date'
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}>
<DatePicker />
</Form.Item>
<Form.Item
label={t("scoreboard.fields.bodyhrs")}
name='bodyhrs'
rules={[
{
required: true,
message: t("general.validation.required"),
},
]}>
<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'>
{t("general.actions.save")}
</Button>
</Form>
</div>
</Card>
);
const handleClick = (e) => {
setLoading(true);
const v = job.joblines.reduce(
(acc, val) => {
if (val.mod_lbr_ty === "LAB")
acc = { ...acc, bodyhrs: acc.bodyhrs + val.mod_lb_hrs };
if (val.mod_lbr_ty === "LAR")
acc = { ...acc, painthrs: acc.painthrs + val.mod_lb_hrs };
return acc;
},
{
bodyhrs: 0,
painthrs: 0,
}
);
form.setFieldsValue({
date: new moment(),
bodyhrs: Math.round(v.bodyhrs * 10) / 10,
painthrs: Math.round(v.painthrs * 10) / 10,
});
setVisibility(true);
setLoading(false);
};
return (
<Popover content={overlay} visible={visibility}>
<Button loading={loading} onClick={handleClick} {...otherBtnProps}>
{t("jobs.actions.addtoscoreboard")}
</Button>
</Popover>
);
}

View File

@@ -57,9 +57,9 @@ export function JobsCloseSaveButton({
return (
<Button
onClick={handleSave}
type='primary'
disabled={suspenseAmount > 0 || disabled}
loading={loading}
>
loading={loading}>
{t("general.actions.save")}
</Button>
);

View File

@@ -56,7 +56,7 @@ export default function ScoreboardJobsList({ scoreBoardlist }) {
];
const overlay = (
<div style={{ width: "30vw" }}>
<div style={{ width: "50vw" }}>
<Table
size='small'
pagination={false}

View File

@@ -22,6 +22,10 @@ export default function ScoreboardRemoveButton({ scoreboardId }) {
message: JSON.stringify(result.errors),
}),
});
} else {
notification["success"]({
message: t("scoreboard.successes.removed"),
});
}
setLoading(false);
};