Modification to Credits not Received.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { Checkbox, notification, Space, Spin } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { MUTATION_UPDATE_PO_CM_REECEIVED } from "../../graphql/parts-orders.queries";
|
||||
|
||||
export default function PartsOrderCmReceived({
|
||||
checked,
|
||||
orderLineId,
|
||||
partsOrderId,
|
||||
}) {
|
||||
const [updateLine] = useMutation(MUTATION_UPDATE_PO_CM_REECEIVED);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleChange = async (e) => {
|
||||
setLoading(true);
|
||||
const result = await updateLine({
|
||||
variables: {
|
||||
partsLineId: orderLineId,
|
||||
partsOrder: { cm_received: e.target.checked },
|
||||
},
|
||||
update(cache) {
|
||||
cache.modify({
|
||||
id: cache.identify({
|
||||
id: partsOrderId,
|
||||
__typename: "parts_orders",
|
||||
}),
|
||||
|
||||
fields: {
|
||||
parts_order_lines(ex, { readField }) {
|
||||
console.log(ex);
|
||||
return ex.map((lineref) => {
|
||||
if (orderLineId.id !== readField("id", lineref)) {
|
||||
lineref.cm_received = e.target.checked;
|
||||
}
|
||||
return lineref;
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({
|
||||
message: t("parts_orders.successes.line_updated"),
|
||||
});
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("parts_orders.errors.saving", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<Checkbox checked={checked} onChange={handleChange} />
|
||||
{loading && <Spin size="small" />}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user