[dyad] Fixed BookOut data mapping for item name, SKU, and date formatting - wrote 1 file(s)
This commit is contained in:
parent
66263fd137
commit
2def045906
1 changed files with 12 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ import {
|
|||
import { columns, BookOutRecord } from "../components/book-out/columns";
|
||||
import { BookOutDataTable } from "../components/book-out/BookOutDataTable";
|
||||
import pb from "@/lib/pocketbase";
|
||||
import { showError } from "@/utils/toast"; // Import showError
|
||||
import { showError } from "@/utils/toast";
|
||||
|
||||
const BookOut = () => {
|
||||
const [bookOutOpen, setBookOutOpen] = useState(false);
|
||||
|
|
@ -29,12 +29,17 @@ const BookOut = () => {
|
|||
|
||||
const formattedData: BookOutRecord[] = records.items.map((record: any) => ({
|
||||
id: record.id,
|
||||
// Correctly access expanded customer name and item details
|
||||
customerName: record.expand?.customer?.comapny_name || 'N/A', // Use 'comapny_name' as per schema
|
||||
itemName: record.expand?.items?.name || 'N/A',
|
||||
sku: record.expand?.items?.sku || 'N/A',
|
||||
quantity: record.quantity || 0, // Default to 0 if quantity is missing
|
||||
dateBookedOut: record.bookOutDate ? new Date(record.bookOutDate).toISOString() : 'Invalid Date', // Ensure date is correctly parsed and formatted
|
||||
customerName: record.expand?.customer?.comapny_name || 'N/A', // Customer name from expanded relation
|
||||
itemName: record.expand?.items?.name || 'N/A', // Item name (description) from expanded stock item
|
||||
sku: record.expand?.items?.sku || 'N/A', // SKU from expanded stock item
|
||||
quantity: record.quantity || 0, // Quantity from record field
|
||||
dateBookedOut: record.date_booked_out
|
||||
? new Date(record.date_booked_out).toLocaleDateString("en-ZA", {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
})
|
||||
: 'N/A', // Properly formatted date or N/A
|
||||
}));
|
||||
setBookOutRecords(formattedData);
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue