Refactor data fetching to use getFullList in forms

Replaced usage of getList with getFullList for fetching records in BookOutForm, PurchaseOrderForm, AddItemForm, and EditItemForm. This change simplifies data retrieval and ensures all records are fetched without pagination.
This commit is contained in:
davidels1 2025-09-29 09:17:39 +02:00
parent 75bb145241
commit 1030dad876
4 changed files with 12 additions and 12 deletions

View file

@ -67,8 +67,8 @@ export function BookOutForm({ setOpen, refreshData }: BookOutFormProps) {
const fetchStockItems = useCallback(async () => {
try {
const records = await pb.collection('stock_items').getList(1, 50, { sort: '-created' });
const formattedStockItems: StockItem[] = records.items.map((item: any) => ({
const records = await pb.collection('stock_items').getFullList({ sort: '-created' });
const formattedStockItems: StockItem[] = records.map((item: any) => ({
id: item.id,
name: item.name,
sku: item.sku,
@ -83,8 +83,8 @@ export function BookOutForm({ setOpen, refreshData }: BookOutFormProps) {
const fetchCustomers = useCallback(async () => {
try {
const records = await pb.collection('customers').getList(1, 50, { sort: '-created' });
const formattedCustomers: Customer[] = records.items.map((item: any) => ({
const records = await pb.collection('customers').getFullList({ sort: '-created' });
const formattedCustomers: Customer[] = records.map((item: any) => ({
id: item.id,
name: item.comapny_name,
}));

View file

@ -71,10 +71,10 @@ export function PurchaseOrderForm({ setOpen, refreshData }: PurchaseOrderFormPro
// Fetch suppliers when the component mounts
const fetchSuppliers = useCallback(async () => {
try {
const records = await pb.collection('suppliers').getList(1, 50, {
const records = await pb.collection('suppliers').getFullList({
sort: '-created',
});
const formattedSuppliers: Supplier[] = records.items.map((item: any) => ({
const formattedSuppliers: Supplier[] = records.map((item: any) => ({
id: item.id,
name: item.supplier_name, // Use the correct field name from PocketBase
}));
@ -88,10 +88,10 @@ export function PurchaseOrderForm({ setOpen, refreshData }: PurchaseOrderFormPro
// Fetch stock items when the component mounts
const fetchStockItems = useCallback(async () => {
try {
const records = await pb.collection('stock_items').getList(1, 50, {
const records = await pb.collection('stock_items').getFullList({
sort: '-created',
});
const formattedStockItems: StockItem[] = records.items.map((item: any) => ({
const formattedStockItems: StockItem[] = records.map((item: any) => ({
id: item.id,
name: item.name,
sku: item.sku,

View file

@ -39,11 +39,11 @@ export function AddItemForm({ setOpen, refreshData }: AddItemFormProps) {
const fetchCategories = React.useCallback(async () => {
try {
const records = await pb.collection('stock_items').getList(1, 50, {
const records = await pb.collection('stock_items').getFullList({
fields: 'category',
});
// Get unique categories from stock_items
const uniqueCategories = Array.from(new Set(records.items.map(item => item.category)));
const uniqueCategories = Array.from(new Set(records.map(item => item.category)));
const options = uniqueCategories.map((cat: string) => ({
value: cat.toLowerCase(),
label: cat,

View file

@ -41,10 +41,10 @@ export function EditItemForm({ setOpen, refreshData, item }: EditItemFormProps)
const fetchCategories = React.useCallback(async () => {
try {
const records = await pb.collection('stock_items').getList(1, 50, {
const records = await pb.collection('stock_items').getFullList({
fields: 'category',
});
const uniqueCategories = Array.from(new Set(records.items.map((item: { category: string }) => item.category)));
const uniqueCategories = Array.from(new Set(records.map((item: { category: string }) => item.category)));
const options = uniqueCategories.map((cat: string) => ({
value: cat.toLowerCase(),
label: cat,