IO-710 Export Log Setup. [ci skip]
This commit is contained in:
@@ -9,6 +9,7 @@ import { auth } from "../../firebase/firebase.utils";
|
||||
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -17,6 +18,7 @@ const mapStateToProps = createStructuredSelector({
|
||||
export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
|
||||
const { t } = useTranslation();
|
||||
const [updateJob] = useMutation(UPDATE_JOB);
|
||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const handleQbxml = async () => {
|
||||
logImEXEvent("jobs_close_export");
|
||||
@@ -72,14 +74,43 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
|
||||
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
|
||||
if (failedTransactions.length > 0) {
|
||||
//Uh oh. At least one was no good.
|
||||
failedTransactions.map((ft) =>
|
||||
notification["error"]({
|
||||
failedTransactions.forEach((ft) => {
|
||||
//insert failed export log
|
||||
notification.open({
|
||||
key: "failedexports",
|
||||
type: "error",
|
||||
message: t("jobs.errors.exporting", {
|
||||
error: ft.errorMessage || "",
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
//Call is not awaited as it is not critical to finish before proceeding.
|
||||
insertExportLog({
|
||||
variables: {
|
||||
logs: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
jobid: jobId,
|
||||
success: false,
|
||||
message: JSON.stringify(ft.errorMessage),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
} else {
|
||||
//Insert success export log.
|
||||
insertExportLog({
|
||||
variables: {
|
||||
logs: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
jobid: jobId,
|
||||
success: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const jobUpdateResponse = await updateJob({
|
||||
variables: {
|
||||
jobId: jobId,
|
||||
@@ -90,8 +121,10 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!!!jobUpdateResponse.errors) {
|
||||
notification["success"]({
|
||||
if (!jobUpdateResponse.errors) {
|
||||
notification.open({
|
||||
type: "error",
|
||||
key: "jobsuccessexport",
|
||||
message: t("jobs.successes.exported"),
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user