Further UI Improvements

This commit is contained in:
Patrick Fic
2021-03-26 17:23:16 -07:00
parent 6c47918542
commit 17264ff7d6
26 changed files with 993 additions and 815 deletions

View File

@@ -0,0 +1,77 @@
import { Table } from "antd";
import Dinero from "dinero.js";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { alphaSort } from "../../utils/sorters";
export default function JobTotalsTableOther({ job }) {
const { t } = useTranslation();
const [state, setState] = useState({
sortedInfo: {},
filteredInfo: {},
});
const data = useMemo(() => {
return [
{
key: t("jobs.labels.subletstotal"),
total: job.job_totals.parts.sublets.total,
},
{
key: t("jobs.labels.additionaltotal"),
total: job.job_totals.additional,
},
];
}, [job.job_totals, t]);
const columns = [
{
//title: t("joblines.fields.part_type"),
dataIndex: "key",
key: "key",
sorter: (a, b) => alphaSort(a.key, b.key),
sortOrder: state.sortedInfo.columnKey === "key" && state.sortedInfo.order,
width: "0%",
},
{
title: t("joblines.fields.total"),
dataIndex: "total",
key: "total",
sorter: (a, b) => a.total.amount - b.total.amount,
sortOrder:
state.sortedInfo.columnKey === "total" && state.sortedInfo.order,
width: "20%",
align: "right",
render: (text, record) => Dinero(record.total).toFormat(),
},
];
const handleTableChange = (pagination, filters, sorter) => {
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
};
return (
<Table
columns={columns}
rowKey="key"
pagination={false}
onChange={handleTableChange}
dataSource={data}
scroll={{
x: true,
}}
summary={() => (
<Table.Summary.Row>
<Table.Summary.Cell>
{t("jobs.labels.additionaltotal")}
</Table.Summary.Cell>
<Table.Summary.Cell>
<strong>
{Dinero(job.job_totals.parts.parts.total).toFormat()}
</strong>
</Table.Summary.Cell>
</Table.Summary.Row>
)}
/>
);
}