Added parts backorder + receiving for orders BOD-159
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "antd";
|
||||
import { useMutation } from "@apollo/react-hooks";
|
||||
import { MUTATION_BACKORDER_PART_LINE } from "../../graphql/parts-orders.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function PartsOrderLineBackorderButton({
|
||||
partsOrderStatus,
|
||||
partsLineId,
|
||||
jobLineId,
|
||||
bodyshop,
|
||||
}) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [backorderLine] = useMutation(MUTATION_BACKORDER_PART_LINE);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const isAlreadyBackordered =
|
||||
bodyshop.md_order_statuses.default_bo === partsOrderStatus;
|
||||
|
||||
const handleOnClick = async () => {
|
||||
setLoading(true);
|
||||
|
||||
const result = await backorderLine({
|
||||
variables: {
|
||||
jobLineId,
|
||||
partsLineId,
|
||||
status: isAlreadyBackordered
|
||||
? bodyshop.md_order_statuses.default_received || "Received*"
|
||||
: bodyshop.md_order_statuses.default_bo || "Backordered*",
|
||||
},
|
||||
});
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button loading={loading} onClick={handleOnClick}>
|
||||
{isAlreadyBackordered
|
||||
? t("parts_orders.actions.receive")
|
||||
: t("parts_orders.actions.backordered")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(PartsOrderLineBackorderButton);
|
||||
Reference in New Issue
Block a user