Added job line ignore.

This commit is contained in:
Patrick Fic
2020-10-20 11:20:14 -07:00
parent c277f6d32d
commit 4290c8c497
16 changed files with 394 additions and 58 deletions

View File

@@ -0,0 +1,24 @@
import { useMutation } from "@apollo/client";
import { message, Switch } from "antd";
import React, { useState } from "react";
import { UPDATE_JOB_LINE } from "../../../graphql/joblines.queries";
const { log } = window;
export default function IgnoreJobLineAtom({ ignore, lineId }) {
const [updateJobLine] = useMutation(UPDATE_JOB_LINE);
const [loading, setLoading] = useState(false);
const handleChange = async (checked) => {
setLoading(true);
const result = await updateJobLine({
variables: { lineId: lineId, line: { ignore: checked } },
});
if (result.errors) {
message.error("Error updating line.");
log.error("Error updating job.", result.errors);
} else {
}
setLoading(false);
};
return <Switch checked={ignore} onChange={handleChange} loading={loading} />;
}

View File

@@ -12,17 +12,19 @@ export default function JobPartsGraphAtom({
const data = useMemo(() => {
if (!job) return [];
const sums = job.joblines.reduce((acc, val) => {
if (!acc[val.part_type]) {
acc[val.part_type] = Dinero();
}
const sums = job.joblines
.filter((j) => !j.ignore)
.reduce((acc, val) => {
if (!acc[val.part_type]) {
acc[val.part_type] = Dinero();
}
acc[val.part_type] = acc[val.part_type].add(
Dinero({ amount: Math.round((val[price] || 0) * 100) })
);
acc[val.part_type] = acc[val.part_type].add(
Dinero({ amount: Math.round((val[price] || 0) * 100) })
);
return acc;
}, {});
return acc;
}, {});
return Object.keys(sums).map((key) => {
return {