From 0009f7d3bb479540a19101e13357692aa8117e16 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 29 Jun 2020 11:27:47 -0700 Subject: [PATCH] Added add to and remove from scoreboard functionality. BOD-91 --- bodyshop_translations.babel | 89 +++++++++++++ .../job-scoreboard-add-button.component.jsx | 125 ++++++++++++++++++ .../jobs-close-save-button.component.jsx | 4 +- .../scoreboard-jobs-list.component.jsx | 2 +- .../scorebard-remove-button.component.jsx | 4 + client/src/graphql/scoreboard.queries.js | 12 ++ .../pages/jobs-close/jobs-close.component.jsx | 2 + client/src/translations/en_us/common.json | 6 + client/src/translations/es/common.json | 6 + client/src/translations/fr/common.json | 6 + 10 files changed, 253 insertions(+), 3 deletions(-) create mode 100644 client/src/components/job-scoreboard-add-button/job-scoreboard-add-button.component.jsx diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index dc2a4d597..222e050e3 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -7930,6 +7930,27 @@ + + addtoscoreboard + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + allocate false @@ -16212,6 +16233,27 @@ errors + + adding + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + removing false @@ -16392,6 +16434,53 @@ + + successes + + + added + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + removed + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + diff --git a/client/src/components/job-scoreboard-add-button/job-scoreboard-add-button.component.jsx b/client/src/components/job-scoreboard-add-button/job-scoreboard-add-button.component.jsx new file mode 100644 index 000000000..4fef7f88a --- /dev/null +++ b/client/src/components/job-scoreboard-add-button/job-scoreboard-add-button.component.jsx @@ -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 = ( + +
+
+ + + + + + + + + + + +
+
+
+ ); + + 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 ( + + + + ); +} diff --git a/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx b/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx index 9b8895163..0f52e1e40 100644 --- a/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx +++ b/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx @@ -57,9 +57,9 @@ export function JobsCloseSaveButton({ return ( ); diff --git a/client/src/components/scoreboard-jobs-list/scoreboard-jobs-list.component.jsx b/client/src/components/scoreboard-jobs-list/scoreboard-jobs-list.component.jsx index 7a7813e40..496227219 100644 --- a/client/src/components/scoreboard-jobs-list/scoreboard-jobs-list.component.jsx +++ b/client/src/components/scoreboard-jobs-list/scoreboard-jobs-list.component.jsx @@ -56,7 +56,7 @@ export default function ScoreboardJobsList({ scoreBoardlist }) { ]; const overlay = ( -
+
+