IO-990 Refactor job closing.

This commit is contained in:
Patrick Fic
2021-05-05 09:35:22 -07:00
parent 6469cb7e87
commit 1a9eddf7c6
6 changed files with 54 additions and 33 deletions

View File

@@ -3,12 +3,11 @@ import { Button, Form, notification, Popconfirm, Space } from "antd";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { useHistory } from "react-router-dom";
//import { useHistory } from "react-router-dom";
import { createStructuredSelector } from "reselect";
import FormsFieldChanged from "../../components/form-fields-changed-alert/form-fields-changed-alert.component";
import JobsScoreboardAdd from "../../components/job-scoreboard-add-button/job-scoreboard-add-button.component";
import JobsCloseAutoAllocate from "../../components/jobs-close-auto-allocate/jobs-close-auto-allocate.component";
import JobsCloseExportButton from "../../components/jobs-close-export-button/jobs-close-export-button.component";
import JobsCloseLines from "../../components/jobs-close-lines/jobs-close-lines.component";
import { generateJobLinesUpdatesForInvoicing } from "../../graphql/jobs-lines.queries";
import { UPDATE_JOB } from "../../graphql/jobs.queries";
@@ -23,12 +22,9 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
const { t } = useTranslation();
const [form] = Form.useForm();
const client = useApolloClient();
const history = useHistory();
// const history = useHistory();
const [closeJob] = useMutation(UPDATE_JOB);
const [loading, setLoading] = useState(false);
// useEffect(() => {
// //if (job && form) form.setFields({ joblines: job.joblines });
// }, [job, form]);
const handleFinish = async (values) => {
setLoading(true);
@@ -37,7 +33,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
refetchQueries: ["QUERY_JOB_CLOSE_DETAILS"],
awaitRefetchQueries: true,
});
if (!!!result.errors) {
if (!result.errors) {
notification["success"]({ message: t("jobs.successes.save") });
// form.resetFields();
} else {
@@ -46,15 +42,12 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
error: JSON.stringify(result.errors),
}),
});
return; // Abandon the rest of the close.
}
form.resetFields();
form.resetFields();
setLoading(false);
};
const handleClose = async () => {
setLoading(true);
const result = await closeJob({
const closeResult = await closeJob({
variables: {
jobId: job.id,
job: {
@@ -64,21 +57,23 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
},
});
if (!!!result.errors) {
if (!closeResult.errors) {
setLoading(false);
notification["success"]({
message: t("jobs.successes.closed"),
});
history.push(`/manage/jobs/${job.id}`);
// history.push(`/manage/jobs/${job.id}`);
} else {
setLoading(false);
notification["error"]({
message: t("job.errors.closing", {
error: JSON.stringify(result.errors),
error: JSON.stringify(closeResult.errors),
}),
});
}
setLoading(false);
};
return (
@@ -97,16 +92,18 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
disabled={!!job.date_exported || jobRO}
/>
<Button
loading={loading}
onClick={() => form.submit()}
disabled={jobRO}
>
{t("general.actions.save")}
</Button>
{
// <Button
// loading={loading}
// onClick={() => form.submit()}
// disabled={jobRO}
// >
// {t("general.actions.save")}
// </Button>
}
<Popconfirm
onConfirm={handleClose}
onConfirm={() => form.submit()}
disabled={jobRO}
okText={t("general.labels.yes")}
cancelText={t("general.labels.no")}
@@ -118,7 +115,9 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
</Popconfirm>
<JobsScoreboardAdd job={job} disabled={false} />
<JobsCloseExportButton jobId={job.id} disabled={job.date_exported} />
{
// <JobsCloseExportButton jobId={job.id} disabled={job.date_exported} />
}
</Space>
<FormsFieldChanged form={form} />
<JobsCloseLines job={job} />