Further work to refactor job costing + qb posting. BOD-383
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Button, Form, Space, notification, Popconfirm } from "antd";
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
@@ -24,22 +24,33 @@ export function JobsCloseComponent({ job, bodyshop }) {
|
||||
const client = useApolloClient();
|
||||
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) => {
|
||||
console.log(values);
|
||||
|
||||
setLoading(true);
|
||||
const result = await client.mutate({
|
||||
mutation: generateJobLinesUpdatesForInvoicing(values.joblines),
|
||||
});
|
||||
console.log("result.data", result.data);
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({ message: t("job.successes.saved") });
|
||||
form.resetFields();
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("job.errors.saving", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
form.resetFields();
|
||||
form.resetFields();
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const handleClose = async () => {
|
||||
setLoading(true);
|
||||
const result = await closeJob({
|
||||
variables: {
|
||||
jobId: job.id,
|
||||
@@ -54,6 +65,7 @@ export function JobsCloseComponent({ job, bodyshop }) {
|
||||
notification["success"]({ message: t("job.successes.closed") });
|
||||
history.push(`/manage/jobs/${job.id}`);
|
||||
} else {
|
||||
setLoading(false);
|
||||
notification["error"]({
|
||||
message: t("job.errors.closing", {
|
||||
error: JSON.stringify(result.errors),
|
||||
@@ -69,6 +81,7 @@ export function JobsCloseComponent({ job, bodyshop }) {
|
||||
form={form}
|
||||
onFinish={handleFinish}
|
||||
initialValues={{ joblines: job.joblines }}
|
||||
scrollToFirstError
|
||||
>
|
||||
<Space>
|
||||
<JobsCloseAutoAllocate
|
||||
@@ -77,7 +90,7 @@ export function JobsCloseComponent({ job, bodyshop }) {
|
||||
disabled={!!job.date_exported}
|
||||
/>
|
||||
|
||||
<Button onClick={() => form.submit()}>
|
||||
<Button loading={loading} onClick={() => form.submit()}>
|
||||
{t("general.actions.save")}
|
||||
</Button>
|
||||
|
||||
@@ -87,7 +100,9 @@ export function JobsCloseComponent({ job, bodyshop }) {
|
||||
cancelText={t("general.labels.no")}
|
||||
title={t("jobs.labels.closeconfirm")}
|
||||
>
|
||||
<Button type="danger">{t("general.actions.close")}</Button>
|
||||
<Button loading={loading} type="danger">
|
||||
{t("general.actions.close")}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
|
||||
<JobsScoreboardAdd job={job} disabled={false} />
|
||||
|
||||
Reference in New Issue
Block a user