From 12a458a09d9efdcbc14a73a8711a028579516ef5 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 19 Jan 2021 11:22:17 -0800 Subject: [PATCH] Delete non-converted job IO-589 --- bodyshop_translations.babel | 63 +++++++++++++++++++ .../jobs-detail-header-actions.component.jsx | 39 ++++++++++-- client/src/graphql/jobs.queries.js | 8 +++ client/src/translations/en_us/common.json | 3 + client/src/translations/es/common.json | 3 + client/src/translations/fr/common.json | 3 + 6 files changed, 115 insertions(+), 4 deletions(-) diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 41bcf1745..2a14bb002 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -17399,6 +17399,27 @@ + + deleteconfirm + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + difference false @@ -18753,6 +18774,27 @@ + + delete + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + deleted false @@ -19849,6 +19891,27 @@ + + deletejob + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + duplicate false diff --git a/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx b/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx index a5bfc9038..9d2d8571f 100644 --- a/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx +++ b/client/src/components/jobs-detail-header-actions/jobs-detail-header-actions.component.jsx @@ -1,19 +1,19 @@ import { DownCircleFilled } from "@ant-design/icons"; -import { useApolloClient } from "@apollo/react-hooks"; -import { Button, Dropdown, Menu, Popconfirm } from "antd"; +import { useApolloClient, useMutation } from "@apollo/react-hooks"; +import { Button, Dropdown, Menu, notification, Popconfirm } from "antd"; import React, { useMemo } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { Link, useHistory } from "react-router-dom"; import { createStructuredSelector } from "reselect"; import { logImEXEvent } from "../../firebase/firebase.utils"; +import { DELETE_JOB } from "../../graphql/jobs.queries"; import { selectJobReadOnly } from "../../redux/application/application.selectors"; import { setModalContext } from "../../redux/modals/modals.actions"; import { selectBodyshop } from "../../redux/user/user.selectors"; import AddToProduction from "./jobs-detail-header-actions.addtoproduction.util"; import JobsDetaiLheaderCsi from "./jobs-detail-header-actions.csi.component"; import DuplicateJob from "./jobs-detail-header-actions.duplicate.util"; - const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, jobRO: selectJobReadOnly, @@ -43,7 +43,7 @@ export function JobsDetailHeaderActions({ const { t } = useTranslation(); const client = useApolloClient(); const history = useHistory(); - + const [deleteJob] = useMutation(DELETE_JOB); const jobInProduction = useMemo(() => { return bodyshop.md_ro_statuses.production_statuses.includes(job.status); }, [job, bodyshop.md_ro_statuses.production_statuses]); @@ -252,6 +252,37 @@ export function JobsDetailHeaderActions({ > {t("jobs.labels.jobcosting")} + {job && !job.converted && ( + + e.stopPropagation()} + onConfirm={async () => { + //delete the job. + const result = await deleteJob({ variables: { id: job.id } }); + + if (!!!result.errors) { + notification["success"]({ + message: t("jobs.successes.delete"), + }); + //go back to jobs list. + history.push(`/manage/`); + } else { + notification["error"]({ + message: t("jobs.errors.deleted", { + error: JSON.stringify(result.errors), + }), + }); + } + }} + getPopupContainer={(trigger) => trigger.parentNode} + > + {t("menus.jobsactions.deletejob")} + + + )} ); return ( diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index e50718bd9..88f301c56 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -1320,3 +1320,11 @@ export const QUERY_JOB_LBR_ADJUSTMENTS = gql` } } `; + +export const DELETE_JOB = gql` + mutation DELETE_JOB($id: uuid!) { + delete_jobs_by_pk(id: $id) { + id + } + } +`; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index a95d483a8..efd630014 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1069,6 +1069,7 @@ "waived": "Waived", "yes": "Yes" }, + "deleteconfirm": "Are you sure you want to delete this job? This cannot be undone. ", "difference": "Difference", "documents": "Documents", "documents-images": "Images", @@ -1137,6 +1138,7 @@ "created": "Job created successfully. Click to view.", "created_subtitle": "Estimate Number {{est_number}} has been created.", "creatednoclick": "Job created successfully. ", + "delete": "Job deleted successfully.", "deleted": "Job deleted successfully.", "exported": "Job exported successfully. ", "invoiced": "Job closed and invoiced successfully.", @@ -1198,6 +1200,7 @@ "jobsactions": { "admin": "Admin", "closejob": "Close Job", + "deletejob": "Delete Job", "duplicate": "Duplicate this Job", "duplicatenolines": "Duplicate this Job without Repair Data", "newcccontract": "Create Courtesy Car Contract" diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index fd2d638f1..2999927e0 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1069,6 +1069,7 @@ "waived": "", "yes": "" }, + "deleteconfirm": "", "difference": "", "documents": "documentos", "documents-images": "", @@ -1137,6 +1138,7 @@ "created": "Trabajo creado con éxito. Click para ver.", "created_subtitle": "", "creatednoclick": "", + "delete": "", "deleted": "Trabajo eliminado con éxito.", "exported": "", "invoiced": "", @@ -1198,6 +1200,7 @@ "jobsactions": { "admin": "", "closejob": "", + "deletejob": "", "duplicate": "", "duplicatenolines": "", "newcccontract": "" diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index b0b7e0f23..1c6e9a5f2 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1069,6 +1069,7 @@ "waived": "", "yes": "" }, + "deleteconfirm": "", "difference": "", "documents": "Les documents", "documents-images": "", @@ -1137,6 +1138,7 @@ "created": "Le travail a été créé avec succès. Clique pour voir.", "created_subtitle": "", "creatednoclick": "", + "delete": "", "deleted": "Le travail a bien été supprimé.", "exported": "", "invoiced": "", @@ -1198,6 +1200,7 @@ "jobsactions": { "admin": "", "closejob": "", + "deletejob": "", "duplicate": "", "duplicatenolines": "", "newcccontract": ""