- Merge client update into test-beta
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,81 +1,81 @@
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { Button, Card, Col, Row, Table, notification } from "antd";
|
||||
import moment from "moment-business-days";
|
||||
import {useMutation} from "@apollo/client";
|
||||
import {Button, Card, Col, notification, Row, Table} from "antd";
|
||||
import day from "../../utils/day";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { UPDATE_PARTS_DISPATCH_LINE } from "../../graphql/parts-dispatch.queries";
|
||||
import { DateTimeFormatter } from "../../utils/DateFormatter";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {UPDATE_PARTS_DISPATCH_LINE} from "../../graphql/parts-dispatch.queries";
|
||||
import {DateTimeFormatter} from "../../utils/DateFormatter";
|
||||
|
||||
export default function PartsDispatchExpander({ dispatch, job }) {
|
||||
const { t } = useTranslation();
|
||||
const [updateDispatchLine] = useMutation(UPDATE_PARTS_DISPATCH_LINE);
|
||||
export default function PartsDispatchExpander({dispatch, job}) {
|
||||
const {t} = useTranslation();
|
||||
const [updateDispatchLine] = useMutation(UPDATE_PARTS_DISPATCH_LINE);
|
||||
|
||||
const handleAccept = async ({ partsDispatchLineId }) => {
|
||||
const accepted_at = moment();
|
||||
const result = await updateDispatchLine({
|
||||
variables: { id: partsDispatchLineId, line: { accepted_at } },
|
||||
optimisticResponse: {
|
||||
update_parts_dispatch_lines_by_pk: {
|
||||
accepted_at,
|
||||
id: partsDispatchLineId,
|
||||
const handleAccept = async ({partsDispatchLineId}) => {
|
||||
const accepted_at = day();
|
||||
const result = await updateDispatchLine({
|
||||
variables: {id: partsDispatchLineId, line: {accepted_at}},
|
||||
optimisticResponse: {
|
||||
update_parts_dispatch_lines_by_pk: {
|
||||
accepted_at,
|
||||
id: partsDispatchLineId,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (result.errors) {
|
||||
notification.open({
|
||||
type: "error",
|
||||
message: t("parts_dispatch.errors.accepting", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("joblines.fields.part_qty"),
|
||||
dataIndex: "quantity",
|
||||
key: "quantity",
|
||||
width: "10%",
|
||||
//sorter: (a, b) => alphaSort(a.number, b.number),
|
||||
},
|
||||
},
|
||||
});
|
||||
if (result.errors) {
|
||||
notification.open({
|
||||
type: "error",
|
||||
message: t("parts_dispatch.errors.accepting", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
};
|
||||
{
|
||||
title: t("joblines.fields.line_desc"),
|
||||
dataIndex: "joblineid",
|
||||
key: "joblineid",
|
||||
//sorter: (a, b) => alphaSort(a.number, b.number),
|
||||
render: (text, record) => record.jobline.line_desc,
|
||||
},
|
||||
{
|
||||
title: t("parts_dispatch_lines.fields.accepted_at"),
|
||||
dataIndex: "accepted_at",
|
||||
key: "accepted_at",
|
||||
width: "20%",
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("joblines.fields.part_qty"),
|
||||
dataIndex: "quantity",
|
||||
key: "quantity",
|
||||
width: "10%",
|
||||
//sorter: (a, b) => alphaSort(a.number, b.number),
|
||||
},
|
||||
{
|
||||
title: t("joblines.fields.line_desc"),
|
||||
dataIndex: "joblineid",
|
||||
key: "joblineid",
|
||||
//sorter: (a, b) => alphaSort(a.number, b.number),
|
||||
render: (text, record) => record.jobline.line_desc,
|
||||
},
|
||||
{
|
||||
title: t("parts_dispatch_lines.fields.accepted_at"),
|
||||
dataIndex: "accepted_at",
|
||||
key: "accepted_at",
|
||||
width: "20%",
|
||||
|
||||
//sorter: (a, b) => alphaSort(a.number, b.number),
|
||||
render: (text, record) =>
|
||||
record.accepted_at ? (
|
||||
<DateTimeFormatter>{record.accepted_at}</DateTimeFormatter>
|
||||
) : (
|
||||
<Button
|
||||
onClick={() => handleAccept({ partsDispatchLineId: record.id })}
|
||||
>
|
||||
{t("parts_dispatch.actions.accept")}
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
return (
|
||||
<Card>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Table
|
||||
rowKey={"id"}
|
||||
dataSource={dispatch.parts_dispatch_lines}
|
||||
columns={columns}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
);
|
||||
//sorter: (a, b) => alphaSort(a.number, b.number),
|
||||
render: (text, record) =>
|
||||
record.accepted_at ? (
|
||||
<DateTimeFormatter>{record.accepted_at}</DateTimeFormatter>
|
||||
) : (
|
||||
<Button
|
||||
onClick={() => handleAccept({partsDispatchLineId: record.id})}
|
||||
>
|
||||
{t("parts_dispatch.actions.accept")}
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
return (
|
||||
<Card>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Table
|
||||
rowKey={"id"}
|
||||
dataSource={dispatch.parts_dispatch_lines}
|
||||
columns={columns}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user