# Conflicts: # .circleci/config.yml # client/package-lock.json # client/src/components/header/header.component.jsx # client/src/components/jobs-admin-change-status/jobs-admin-change.status.component.jsx # client/src/components/jobs-admin-delete-intake/jobs-admin-delete-intake.component.jsx # client/src/components/jobs-admin-mark-reexport/jobs-admin-mark-reexport.component.jsx # client/src/components/jobs-admin-unvoid/jobs-admin-unvoid.component.jsx # client/src/components/production-list-detail/production-list-detail.component.jsx # client/src/components/report-center-modal/report-center-modal.component.jsx # client/src/pages/jobs-admin/jobs-admin.page.jsx # client/src/pages/jobs-detail/jobs-detail.page.component.jsx # client/src/utils/TemplateConstants.js # client/yarn.lock # package-lock.json # server.js
167 lines
4.8 KiB
JavaScript
167 lines
4.8 KiB
JavaScript
import { useMutation } from "@apollo/client";
|
|
import { Button, Space, notification } from "antd";
|
|
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import moment from "moment";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
|
import {
|
|
MARK_JOB_AS_EXPORTED,
|
|
MARK_JOB_AS_UNINVOICED,
|
|
MARK_JOB_FOR_REEXPORT,
|
|
} from "../../graphql/jobs.queries";
|
|
import { insertAuditTrail } from "../../redux/application/application.actions";
|
|
import {
|
|
selectBodyshop,
|
|
selectCurrentUser,
|
|
} from "../../redux/user/user.selectors";
|
|
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
bodyshop: selectBodyshop,
|
|
currentUser: selectCurrentUser,
|
|
});
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
insertAuditTrail: ({jobid, operation}) =>
|
|
dispatch(insertAuditTrail({jobid, operation})),
|
|
});
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(JobAdminMarkReexport);
|
|
|
|
export function JobAdminMarkReexport({
|
|
insertAuditTrail,
|
|
bodyshop,
|
|
currentUser,
|
|
job,
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const [loading, setLoading] = useState(false);
|
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
|
|
|
const [markJobForReexport] = useMutation(MARK_JOB_FOR_REEXPORT);
|
|
const [markJobExported] = useMutation(MARK_JOB_AS_EXPORTED);
|
|
const [markJobUninvoiced] = useMutation(MARK_JOB_AS_UNINVOICED);
|
|
|
|
const handleMarkForExport = async () => {
|
|
setLoading(true);
|
|
const result = await markJobForReexport({
|
|
variables: {
|
|
jobId: job.id,
|
|
default_invoiced: bodyshop.md_ro_statuses.default_invoiced,
|
|
},
|
|
});
|
|
|
|
if (!result.errors) {
|
|
notification["success"]({message: t("jobs.successes.save")});
|
|
insertAuditTrail({
|
|
jobid: job.id,
|
|
operation: AuditTrailMapping.admin_jobmarkforreexport(),
|
|
});
|
|
} else {
|
|
notification["error"]({
|
|
message: t("jobs.errors.saving", {
|
|
error: JSON.stringify(result.errors),
|
|
}),
|
|
});
|
|
}
|
|
setLoading(false);
|
|
};
|
|
|
|
const handleMarkExported = async () => {
|
|
setLoading(true);
|
|
const result = await markJobExported({
|
|
variables: {
|
|
jobId: job.id,
|
|
date_exported: moment(),
|
|
default_exported: bodyshop.md_ro_statuses.default_exported,
|
|
},
|
|
});
|
|
|
|
await insertExportLog({
|
|
variables: {
|
|
logs: [
|
|
{
|
|
bodyshopid: bodyshop.id,
|
|
jobid: job.id,
|
|
successful: true,
|
|
message: JSON.stringify([t("general.labels.markedexported")]),
|
|
useremail: currentUser.email,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
if (!result.errors) {
|
|
notification["success"]({message: t("jobs.successes.save")});
|
|
insertAuditTrail({
|
|
jobid: job.id,
|
|
operation: AuditTrailMapping.admin_jobmarkexported(),
|
|
});
|
|
} else {
|
|
notification["error"]({
|
|
message: t("jobs.errors.saving", {
|
|
error: JSON.stringify(result.errors),
|
|
}),
|
|
});
|
|
}
|
|
setLoading(false);
|
|
};
|
|
|
|
const handleUninvoice = async () => {
|
|
setLoading(true);
|
|
const result = await markJobUninvoiced({
|
|
variables: {
|
|
jobId: job.id,
|
|
default_delivered: bodyshop.md_ro_statuses.default_delivered,
|
|
},
|
|
});
|
|
|
|
if (!result.errors) {
|
|
notification["success"]({message: t("jobs.successes.save")});
|
|
insertAuditTrail({
|
|
jobid: job.id,
|
|
operation: AuditTrailMapping.admin_jobuninvoice(),
|
|
});
|
|
} else {
|
|
notification["error"]({
|
|
message: t("jobs.errors.saving", {
|
|
error: JSON.stringify(result.errors),
|
|
}),
|
|
});
|
|
}
|
|
setLoading(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Space wrap>
|
|
<Button
|
|
loading={loading}
|
|
disabled={!job.date_exported}
|
|
onClick={handleMarkForExport}
|
|
>
|
|
{t("jobs.labels.markforreexport")}
|
|
</Button>
|
|
<Button
|
|
loading={loading}
|
|
disabled={job.date_exported}
|
|
onClick={handleMarkExported}
|
|
>
|
|
{t("jobs.actions.markasexported")}
|
|
</Button>
|
|
<Button
|
|
loading={loading}
|
|
disabled={!job.date_invoiced || job.date_exported}
|
|
onClick={handleUninvoice}
|
|
>
|
|
{t("jobs.actions.uninvoice")}
|
|
</Button>
|
|
</Space>
|
|
</>
|
|
);
|
|
}
|