Uecko_ERP/modules/customer-invoices/src/web/components/customer-invoices-list-grid.tsx

83 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-07-07 18:25:13 +00:00
import { useState } from "react";
2025-05-17 19:12:01 +00:00
2025-07-02 08:57:09 +00:00
import { AG_GRID_LOCALE_ES } from "@ag-grid-community/locale";
// Grid
import type { ColDef, GridOptions, ValueFormatterParams } from "ag-grid-community";
2025-05-17 19:12:01 +00:00
import { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
ModuleRegistry.registerModules([AllCommunityModule]);
2025-07-02 08:57:09 +00:00
import { MoneyDTO } from "@erp/core";
import { formatDate, formatMoney } from "@erp/core/client";
2025-05-17 19:47:08 +00:00
// Core CSS
import { AgGridReact } from "ag-grid-react";
2025-06-24 18:38:57 +00:00
import { useCustomerInvoicesQuery } from "../hooks";
2025-07-07 18:25:13 +00:00
import { CustomerInvoiceStatusBadge } from "./customer-invoice-status-badge";
2025-05-17 19:12:01 +00:00
// Create new GridExample component
2025-07-07 18:25:13 +00:00
export const CustomerInvoicesListGrid = () => {
2025-07-09 17:56:15 +00:00
const { t } = useTranslation();
2025-06-24 18:38:57 +00:00
const { data, isLoading, isPending, isError, error } = useCustomerInvoicesQuery({});
2025-05-17 19:12:01 +00:00
// Column Definitions: Defines & controls grid columns.
const [colDefs] = useState<ColDef[]>([
{
2025-07-02 08:57:09 +00:00
field: "invoice_status",
filter: true,
2025-07-07 18:25:13 +00:00
headerName: t("pages.list.grid_columns.invoice_status"),
cellRenderer: (params: ValueFormatterParams) => {
return <CustomerInvoiceStatusBadge status={params.value} />;
},
2025-05-27 17:47:03 +00:00
},
2025-07-07 18:25:13 +00:00
{ field: "invoice_number", headerName: t("pages.list.grid_columns.invoice_number") },
{ field: "invoice_series", headerName: t("pages.list.grid_columns.invoice_series") },
2025-05-27 17:47:03 +00:00
{
2025-07-02 08:57:09 +00:00
field: "issue_date",
2025-07-07 18:25:13 +00:00
headerName: t("pages.list.grid_columns.issue_date"),
2025-07-02 08:57:09 +00:00
valueFormatter: (params: ValueFormatterParams) => {
return formatDate(params.value);
},
},
2025-05-17 19:12:01 +00:00
{
2025-07-02 08:57:09 +00:00
field: "total_price",
2025-07-07 18:25:13 +00:00
headerName: t("pages.list.grid_columns.total_price"),
2025-05-17 19:12:01 +00:00
valueFormatter: (params: ValueFormatterParams) => {
2025-07-02 08:57:09 +00:00
const rawValue: MoneyDTO = params.value;
return formatMoney(rawValue);
2025-05-17 19:12:01 +00:00
},
},
]);
2025-07-02 08:57:09 +00:00
const gridOptions: GridOptions = {
columnDefs: colDefs,
defaultColDef: {
editable: true,
flex: 1,
minWidth: 100,
filter: false,
2025-05-18 11:53:00 +00:00
sortable: false,
2025-07-02 08:57:09 +00:00
resizable: true,
},
pagination: true,
paginationPageSize: 10,
paginationPageSizeSelector: [10, 20, 30, 50],
localeText: AG_GRID_LOCALE_ES,
rowSelection: { mode: "multiRow" },
};
2025-05-17 19:12:01 +00:00
// Container: Defines the grid's theme & dimensions.
return (
2025-05-18 11:53:00 +00:00
<div
2025-05-20 10:08:24 +00:00
className='ag-theme-alpine'
style={{
height: "100%",
width: "100%",
}}
2025-05-18 11:53:00 +00:00
>
2025-07-02 08:57:09 +00:00
<AgGridReact rowData={data?.items ?? []} loading={isLoading || isPending} {...gridOptions} />
2025-05-17 19:12:01 +00:00
</div>
);
};