79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
import { useMemo } from "react";
|
|
import { Tag, Tooltip } from "antd";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
bodyshop: selectBodyshop
|
|
});
|
|
const mapDispatchToProps = () => ({
|
|
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
|
});
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(JobPartsQueueCount);
|
|
|
|
export function JobPartsQueueCount({ bodyshop, parts }) {
|
|
const { t } = useTranslation();
|
|
const partsStatus = useMemo(() => {
|
|
if (!parts) return null;
|
|
const statusKeys = ["default_bo", "default_ordered", "default_received", "default_returned"];
|
|
return parts.reduce(
|
|
(acc, val) => {
|
|
if (val.part_type === "PAS" || val.part_type === "PASL") return acc;
|
|
acc.total = acc.total + val.count;
|
|
acc[val.status] = acc[val.status] + val.count;
|
|
return acc;
|
|
},
|
|
{
|
|
total: 0,
|
|
null: 0,
|
|
...Object.fromEntries(statusKeys.map((key) => [bodyshop.md_order_statuses[key], 0]))
|
|
}
|
|
);
|
|
}, [bodyshop, parts]);
|
|
|
|
if (!parts) return null;
|
|
return (
|
|
<div
|
|
style={{
|
|
display: "grid",
|
|
gridTemplateColumns: "repeat(auto-fit, minmax(40px, 1fr))",
|
|
gap: "8px",
|
|
width: "100%",
|
|
justifyItems: "start"
|
|
}}
|
|
>
|
|
<Tooltip title="Total">
|
|
<Tag style={{ minWidth: "40px", textAlign: "center" }}>{partsStatus.total}</Tag>
|
|
</Tooltip>
|
|
<Tooltip title={t("dashboard.errors.status_normal")}>
|
|
<Tag color="gold" style={{ minWidth: "40px", textAlign: "center" }}>
|
|
{partsStatus["null"]}
|
|
</Tag>
|
|
</Tooltip>
|
|
<Tooltip title={bodyshop.md_order_statuses.default_bo}>
|
|
<Tag color="red" style={{ minWidth: "40px", textAlign: "center" }}>
|
|
{partsStatus[bodyshop.md_order_statuses.default_bo]}
|
|
</Tag>
|
|
</Tooltip>
|
|
<Tooltip title={bodyshop.md_order_statuses.default_ordered}>
|
|
<Tag color="blue" style={{ minWidth: "40px", textAlign: "center" }}>
|
|
{partsStatus[bodyshop.md_order_statuses.default_ordered]}
|
|
</Tag>
|
|
</Tooltip>
|
|
<Tooltip title={bodyshop.md_order_statuses.default_received}>
|
|
<Tag color="green" style={{ minWidth: "40px", textAlign: "center" }}>
|
|
{partsStatus[bodyshop.md_order_statuses.default_received]}
|
|
</Tag>
|
|
</Tooltip>
|
|
<Tooltip title={bodyshop.md_order_statuses.default_returned}>
|
|
<Tag color="orange" style={{ minWidth: "40px", textAlign: "center" }}>
|
|
{partsStatus[bodyshop.md_order_statuses.default_returned]}
|
|
</Tag>
|
|
</Tooltip>
|
|
</div>
|
|
);
|
|
}
|