121 lines
3.2 KiB
JavaScript
121 lines
3.2 KiB
JavaScript
import { SyncOutlined } from "@ant-design/icons";
|
|
import { Button, Card, Input, Space, Table, Typography } from "antd";
|
|
import queryString from "query-string";
|
|
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Link, useHistory, useLocation } from "react-router-dom";
|
|
export default function VehiclesListComponent({
|
|
loading,
|
|
vehicles,
|
|
total,
|
|
refetch,
|
|
}) {
|
|
const search = queryString.parse(useLocation().search);
|
|
const {
|
|
page,
|
|
//sortcolumn, sortorder,
|
|
} = search;
|
|
const history = useHistory();
|
|
|
|
const [state, setState] = useState({
|
|
sortedInfo: {},
|
|
filteredInfo: { text: "" },
|
|
});
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const columns = [
|
|
{
|
|
title: t("vehicles.fields.v_vin"),
|
|
dataIndex: "v_vin",
|
|
key: "v_vin",
|
|
render: (text, record) => (
|
|
<Link to={"/manage/vehicles/" + record.id}>
|
|
{record.v_vin || "N/A"}
|
|
</Link>
|
|
),
|
|
},
|
|
{
|
|
title: t("vehicles.fields.description"),
|
|
dataIndex: "description",
|
|
key: "description",
|
|
render: (text, record) => {
|
|
return (
|
|
<span>{`${record.v_model_yr || ""} ${record.v_make_desc || ""} ${
|
|
record.v_model_desc || ""
|
|
} ${record.v_color || ""}`}</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: t("vehicles.fields.plate_no"),
|
|
dataIndex: "plate",
|
|
key: "plate",
|
|
render: (text, record) => {
|
|
return (
|
|
<span>{`${record.plate_st || ""} | ${record.plate_no || ""}`}</span>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
|
|
const handleTableChange = (pagination, filters, sorter) => {
|
|
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
|
search.page = pagination.current;
|
|
search.sortcolumn = sorter.columnKey;
|
|
search.sortorder = sorter.order;
|
|
history.push({ search: queryString.stringify(search) });
|
|
};
|
|
|
|
return (
|
|
<Card
|
|
title={t("menus.header.vehicles")}
|
|
extra={
|
|
<Space wrap>
|
|
{search.search && (
|
|
<>
|
|
<Typography.Title level={4}>
|
|
{t("general.labels.searchresults", { search: search.search })}
|
|
</Typography.Title>
|
|
<Button
|
|
onClick={() => {
|
|
delete search.search;
|
|
history.push({ search: queryString.stringify(search) });
|
|
}}
|
|
>
|
|
{t("general.actions.clear")}
|
|
</Button>
|
|
</>
|
|
)}
|
|
<Button onClick={() => refetch()}>
|
|
<SyncOutlined />
|
|
</Button>
|
|
<Input.Search
|
|
placeholder={search.search || t("general.labels.search")}
|
|
onSearch={(value) => {
|
|
search.search = value;
|
|
history.push({ search: queryString.stringify(search) });
|
|
}}
|
|
enterButton
|
|
/>
|
|
</Space>
|
|
}
|
|
>
|
|
<Table
|
|
loading={loading}
|
|
pagination={{
|
|
position: "top",
|
|
pageSize: 25,
|
|
current: parseInt(page || 1),
|
|
total: total,
|
|
}}
|
|
columns={columns}
|
|
rowKey="id"
|
|
scroll={{ x: true }}
|
|
dataSource={vehicles}
|
|
onChange={handleTableChange}
|
|
/>
|
|
</Card>
|
|
);
|
|
}
|