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,157 @@
import { Table } from "antd";
import Dinero from "dinero.js";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import CurrencyFormatter from "../../utils/CurrencyFormatter";
import { alphaSort } from "../../utils/sorters";
export default function JobTotalsTableLabor({ job }) {
const { t } = useTranslation();
const [state, setState] = useState({
sortedInfo: {
columnKey: "profitcenter_labor",
field: "profitcenter_labor",
order: "ascend",
},
filteredInfo: {},
});
const data = useMemo(() => {
return Object.keys(job.job_totals.rates)
.filter(
(key) =>
key !== "mapa" &&
key !== "mash" &&
key !== "subtotal" &&
key !== "rates_subtotal"
)
.map((key) => {
return {
id: key,
...job.job_totals.rates[key],
};
});
}, [job.job_totals.rates]);
const columns = [
{
title: t("joblines.fields.profitcenter_labor"),
dataIndex: "profitcenter_labor",
key: "profitcenter_labor",
defaultSortOrder: "ascend",
sorter: (a, b) =>
alphaSort(
t(`jobs.fields.rate_${a.id.toLowerCase()}`),
t(`jobs.fields.rate_${b.id.toLowerCase()}`)
),
sortOrder:
state.sortedInfo.columnKey === "profitcenter_labor" &&
state.sortedInfo.order,
render: (text, record) =>
t(`jobs.fields.rate_${record.id.toLowerCase()}`),
},
{
title: t("jobs.labels.rates"),
dataIndex: "rate",
key: "rate",
align: "right",
sorter: (a, b) => a.rate - b.rate,
sortOrder:
state.sortedInfo.columnKey === "rate" && state.sortedInfo.order,
render: (text, record) => (
<CurrencyFormatter>{record.rate}</CurrencyFormatter>
),
},
{
title: t("joblines.fields.mod_lb_hrs"),
dataIndex: "mod_lb_hrs",
key: "mod_lb_hrs",
sorter: (a, b) => a.mod_lb_hrs - b.mod_lb_hrs,
sortOrder:
state.sortedInfo.columnKey === "mod_lb_hrs" && state.sortedInfo.order,
render: (text, record) => record.hours.toFixed(1),
},
{
title: t("joblines.fields.total"),
dataIndex: "total",
key: "total",
align: "right",
sorter: (a, b) => a.total.amount - b.total.amount,
sortOrder:
state.sortedInfo.columnKey === "total" && state.sortedInfo.order,
render: (text, record) => Dinero(record.total).toFormat(),
},
];
const handleTableChange = (pagination, filters, sorter) => {
console.log("sorter :>> ", sorter);
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
};
return (
<Table
columns={columns}
rowKey="id"
pagination={false}
onChange={handleTableChange}
dataSource={data}
scroll={{
x: true,
}}
summary={() => (
<>
<Table.Summary.Row>
<Table.Summary.Cell>
{t("jobs.labels.labor_rates_subtotal")}
</Table.Summary.Cell>
<Table.Summary.Cell />
<Table.Summary.Cell />
<Table.Summary.Cell>
<strong>
{Dinero(job.job_totals.rates.rates_subtotal).toFormat()}
</strong>
</Table.Summary.Cell>
</Table.Summary.Row>
<Table.Summary.Row>
<Table.Summary.Cell>{t("jobs.labels.mapa")}</Table.Summary.Cell>
<Table.Summary.Cell>
{job.job_totals.rates.mapa.rate}
</Table.Summary.Cell>
<Table.Summary.Cell>
{job.job_totals.rates.mapa.hours.toFixed(2)}
</Table.Summary.Cell>
<Table.Summary.Cell>
{Dinero(job.job_totals.rates.mapa.total).toFormat()}
</Table.Summary.Cell>
</Table.Summary.Row>
<Table.Summary.Row>
<Table.Summary.Cell>{t("jobs.labels.mash")}</Table.Summary.Cell>
<Table.Summary.Cell>
{job.job_totals.rates.mash.rate}
</Table.Summary.Cell>
<Table.Summary.Cell>
{job.job_totals.rates.mash.hours.toFixed(2)}
</Table.Summary.Cell>
<Table.Summary.Cell>
{Dinero(job.job_totals.rates.mash.total).toFormat()}
</Table.Summary.Cell>
</Table.Summary.Row>
<Table.Summary.Row>
<Table.Summary.Cell>
{t("jobs.labels.labor_rates_subtotal")}
</Table.Summary.Cell>
<Table.Summary.Cell />
<Table.Summary.Cell />
<Table.Summary.Cell>
<strong>
{Dinero(job.job_totals.rates.rates_subtotal).toFormat()}
</strong>
</Table.Summary.Cell>
</Table.Summary.Row>
</>
)}
/>
);
}