From d81255b582913853b424bfbaee5a95dabfb01f9c Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 3 Jul 2020 16:53:43 -0700 Subject: [PATCH] Added a delete in-progress time ticket button. BOD-183 --- bodyshop_translations.babel | 63 +++++++++++++++++++ .../tech-job-clock-out-button.component.jsx | 2 + .../tech-job-clock-out-delete.component.jsx | 40 ++++++++++++ client/src/graphql/timetickets.queries.js | 7 +++ client/src/translations/en_us/common.json | 7 ++- client/src/translations/es/common.json | 7 ++- client/src/translations/fr/common.json | 7 ++- 7 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 client/src/components/tech-job-clock-out-delete/tech-job-clock-out-delete.component.jsx diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index ff388214d..c1a7af70f 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -16970,6 +16970,27 @@ + + deleting + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + @@ -17211,6 +17232,27 @@ + + deleteconfirm + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + edit false @@ -17342,6 +17384,27 @@ + + deleted + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + diff --git a/client/src/components/tech-job-clock-out-button/tech-job-clock-out-button.component.jsx b/client/src/components/tech-job-clock-out-button/tech-job-clock-out-button.component.jsx index 961cebae3..4b5a94b40 100644 --- a/client/src/components/tech-job-clock-out-button/tech-job-clock-out-button.component.jsx +++ b/client/src/components/tech-job-clock-out-button/tech-job-clock-out-button.component.jsx @@ -16,6 +16,7 @@ import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { selectBodyshop } from "../../redux/user/user.selectors"; import { selectTechnician } from "../../redux/tech/tech.selectors"; +import TechJobClockoutDelete from "../tech-job-clock-out-delete/tech-job-clock-out-delete.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, technician: selectTechnician, @@ -114,6 +115,7 @@ export function TechClockOffButton({ + diff --git a/client/src/components/tech-job-clock-out-delete/tech-job-clock-out-delete.component.jsx b/client/src/components/tech-job-clock-out-delete/tech-job-clock-out-delete.component.jsx new file mode 100644 index 000000000..e4febc563 --- /dev/null +++ b/client/src/components/tech-job-clock-out-delete/tech-job-clock-out-delete.component.jsx @@ -0,0 +1,40 @@ +import React from "react"; +import { Popconfirm, notification } from "antd"; +import { DeleteFilled } from "@ant-design/icons"; +import { DELETE_TIME_TICKET } from "../../graphql/timetickets.queries"; +import { useTranslation } from "react-i18next"; +import { useMutation } from "@apollo/react-hooks"; + +export default function TechJobClockoutDelete({ timeTicketId }) { + const [deleteTimeTicket] = useMutation(DELETE_TIME_TICKET); + const { t } = useTranslation(); + const handleDelete = async () => { + const result = await deleteTimeTicket({ + variables: { id: timeTicketId }, + refetchQueries: ["QUERY_ACTIVE_TIME_TICKETS"], + }); + + if (!!result.errors) { + notification["error"]({ + message: t("timetickets.errors.deleting", { + message: JSON.stringify(result.errors), + }), + }); + } else { + notification["success"]({ + message: t("timetickets.successes.deleted"), + }); + } + }; + + return ( + + + + ); +} diff --git a/client/src/graphql/timetickets.queries.js b/client/src/graphql/timetickets.queries.js index c39b509d4..090044ec0 100644 --- a/client/src/graphql/timetickets.queries.js +++ b/client/src/graphql/timetickets.queries.js @@ -91,3 +91,10 @@ export const QUERY_ACTIVE_TIME_TICKETS = gql` } } `; +export const DELETE_TIME_TICKET = gql` + mutation DELETE_TIME_TICKET($id: uuid!) { + delete_timetickets_by_pk(id: $id) { + id + } + } +`; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 57b2bb234..969edc9df 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1074,7 +1074,8 @@ }, "errors": { "clockingin": "Error while clocking in. {{message}}", - "clockingout": "Error while clocking out. {{message}}" + "clockingout": "Error while clocking out. {{message}}", + "deleting": "Error deleting time ticket. {{message}}" }, "fields": { "actualhrs": "Actual Hours", @@ -1090,6 +1091,7 @@ "labels": { "alreadyclockedon": "You are already clocked in to the following job(s):", "clockintojob": "Clock In to Job", + "deleteconfirm": "Are you sure you want to delete this time ticket? This cannot be undone.", "edit": "Edit Time Ticket", "flat_rate": "Flat Rate", "new": "New Time Ticket", @@ -1097,7 +1099,8 @@ }, "successes": { "clockedin": "Clocked in successfully.", - "clockedout": "Clocked out successfully." + "clockedout": "Clocked out successfully.", + "deleted": "Time ticket deleted successfully." } }, "titles": { diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 5e4824a18..0ed722fe3 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1074,7 +1074,8 @@ }, "errors": { "clockingin": "", - "clockingout": "" + "clockingout": "", + "deleting": "" }, "fields": { "actualhrs": "", @@ -1090,6 +1091,7 @@ "labels": { "alreadyclockedon": "", "clockintojob": "", + "deleteconfirm": "", "edit": "", "flat_rate": "", "new": "", @@ -1097,7 +1099,8 @@ }, "successes": { "clockedin": "", - "clockedout": "" + "clockedout": "", + "deleted": "" } }, "titles": { diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 58dafdce8..61ade57e0 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1074,7 +1074,8 @@ }, "errors": { "clockingin": "", - "clockingout": "" + "clockingout": "", + "deleting": "" }, "fields": { "actualhrs": "", @@ -1090,6 +1091,7 @@ "labels": { "alreadyclockedon": "", "clockintojob": "", + "deleteconfirm": "", "edit": "", "flat_rate": "", "new": "", @@ -1097,7 +1099,8 @@ }, "successes": { "clockedin": "", - "clockedout": "" + "clockedout": "", + "deleted": "" } }, "titles": {