2025-05-17 19:12:01 +00:00
|
|
|
// React Grid Logic
|
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
|
|
|
|
|
|
|
|
|
// Theme
|
|
|
|
|
import type { ColDef, ValueFormatterParams } from "ag-grid-community";
|
|
|
|
|
import { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
|
|
|
|
|
|
|
|
|
|
ModuleRegistry.registerModules([AllCommunityModule]);
|
|
|
|
|
|
2025-05-17 19:47:08 +00:00
|
|
|
// Core CSS
|
|
|
|
|
import { AgGridReact } from "ag-grid-react";
|
2025-05-20 10:08:24 +00:00
|
|
|
import { useInvoices } from "../hooks/use-invoices";
|
2025-05-17 19:47:08 +00:00
|
|
|
|
2025-05-17 19:12:01 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch example Json data
|
|
|
|
|
* Not recommended for production use!
|
|
|
|
|
*/
|
|
|
|
|
export const useFetchJson = <T,>(url: string, limit?: number) => {
|
|
|
|
|
const [data, setData] = useState<T[]>();
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
|
|
// Note error handling is omitted here for brevity
|
|
|
|
|
const response = await fetch(url);
|
|
|
|
|
const json = await response.json();
|
|
|
|
|
const data = limit ? json.slice(0, limit) : json;
|
|
|
|
|
setData(data);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
|
|
|
|
fetchData();
|
|
|
|
|
}, [url, limit]);
|
|
|
|
|
return { data, loading };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Row Data Interface
|
|
|
|
|
interface IRow {
|
|
|
|
|
mission: string;
|
|
|
|
|
company: string;
|
|
|
|
|
location: string;
|
|
|
|
|
date: string;
|
|
|
|
|
time: string;
|
|
|
|
|
rocket: string;
|
|
|
|
|
price: number;
|
|
|
|
|
successful: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new GridExample component
|
|
|
|
|
export const InvoicesGrid = () => {
|
2025-05-20 10:08:24 +00:00
|
|
|
const { useList } = useInvoices();
|
|
|
|
|
|
2025-05-27 17:47:03 +00:00
|
|
|
const { data, isLoading, isPending, isError, error } = useList({});
|
2025-05-17 19:12:01 +00:00
|
|
|
|
|
|
|
|
// Column Definitions: Defines & controls grid columns.
|
|
|
|
|
const [colDefs] = useState<ColDef[]>([
|
2025-05-27 17:47:03 +00:00
|
|
|
{ field: "invoice_number" },
|
|
|
|
|
{ field: "invoice_series" },
|
2025-05-17 19:12:01 +00:00
|
|
|
{
|
2025-05-27 17:47:03 +00:00
|
|
|
field: "status",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ field: "issue_date" },
|
|
|
|
|
{ field: "operation_date" },
|
|
|
|
|
{
|
|
|
|
|
field: "subtotal",
|
|
|
|
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
|
|
|
return "0 €";
|
|
|
|
|
//return `£${params.value.toLocaleString()}`;
|
|
|
|
|
},
|
2025-05-17 19:12:01 +00:00
|
|
|
},
|
|
|
|
|
{
|
2025-05-27 17:47:03 +00:00
|
|
|
field: "total",
|
2025-05-17 19:12:01 +00:00
|
|
|
valueFormatter: (params: ValueFormatterParams) => {
|
2025-05-27 17:47:03 +00:00
|
|
|
return "0 €";
|
|
|
|
|
//return `£${params.value.toLocaleString()}`;
|
2025-05-17 19:12:01 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Apply settings across all columns
|
|
|
|
|
const defaultColDef = useMemo<ColDef>(() => {
|
|
|
|
|
return {
|
|
|
|
|
filter: true,
|
2025-05-18 11:53:00 +00:00
|
|
|
sortable: false,
|
|
|
|
|
resizable: false,
|
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-05-17 19:12:01 +00:00
|
|
|
<AgGridReact
|
|
|
|
|
rowData={data}
|
2025-05-27 17:47:03 +00:00
|
|
|
loading={isLoading || isPending}
|
2025-05-17 19:12:01 +00:00
|
|
|
columnDefs={colDefs}
|
|
|
|
|
defaultColDef={defaultColDef}
|
|
|
|
|
pagination={true}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|