Fixed bugs on parts allocations + added totals BOD-131

This commit is contained in:
Patrick Fic
2020-05-20 10:03:03 -07:00
parent 94777bf661
commit 0dbacf0b9e
8 changed files with 118 additions and 32 deletions

View File

@@ -4,6 +4,8 @@ import { createStructuredSelector } from "reselect";
import JobsCloseLaborMaterialAllocation from "../../components/jobs-close-labmat-allocation/jobs-close-labmat-allocation.component";
import { selectBodyshop } from "../../redux/user/user.selectors";
import JobsClosePartsAllocation from "../../components/jobs-close-parts-allocation/jobs-close-parts-allocation.component";
import Dinero from "dinero.js";
import JobsCloseTotals from "../../components/jobs-close-totals/jobs-close-totals.component";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
@@ -20,24 +22,59 @@ export function JobsCloseComponent({ job, bodyshop, jobTotals }) {
return acc;
}, {})
);
console.log("JobsCloseComponent -> labmatAllocations", labmatAllocations);
const [partsAllocations, setPartsAllocations] = useState(
Object.keys(jobTotals.parts.parts.list).reduce((acc, val) => {
const [partsAllocations, setPartsAllocations] = useState({
...Object.keys(jobTotals.parts.parts.list).reduce((acc, val) => {
acc[val] = { ...jobTotals.parts.parts.list[val], allocations: [] };
return acc;
}, {})
);
}, {}),
sublet: {
...jobTotals.parts.sublets,
allocations: [],
},
});
console.log("JobsCloseComponent -> partsAllocations", partsAllocations);
const labmatAllocatedTotalsArray = Object.keys(labmatAllocations)
.filter((i) => !i.includes("subtotal"))
.map((i) => labmatAllocations[i].allocations)
.flat();
const labmatAllocatedTotal = Dinero({
amount: labmatAllocatedTotalsArray.reduce((acc, val) => {
return (acc = acc + val.amount.getAmount());
}, 0),
});
const partsAllocatedTotalsArray = Object.keys(partsAllocations)
.map((i) => partsAllocations[i].allocations)
.flat();
const partsAllocatedTotal = Dinero({
amount: partsAllocatedTotalsArray.reduce((acc, val) => {
return (acc = acc + val.amount.getAmount());
}, 0),
});
return (
<div>
<JobsCloseTotals
jobTotals={jobTotals}
labMatTotal={labmatAllocatedTotal}
partsTotal={partsAllocatedTotal}
/>
<JobsCloseLaborMaterialAllocation
labmatAllocations={labmatAllocations}
setLabmatAllocations={setLabmatAllocations}
labMatTotalAllocation={labmatAllocatedTotal}
/>
<JobsClosePartsAllocation
partsAllocations={partsAllocations}
setPartsAllocations={setPartsAllocations}
partsAllocatedTotal={partsAllocatedTotal}
/>
</div>
);

View File

@@ -50,7 +50,6 @@ export function JobsCloseContainer({ setBreadcrumbs, bodyshop }) {
]);
}, [setBreadcrumbs, t, jobId, data]);
console.log("Container rerender");
if (loading) return <LoadingSpinner />;
if (error) return <AlertComponent message={error.message} type="error" />;