Implement GRN and Purchase Order sheets with form handling and data fetching

This commit is contained in:
Kalana B. Thilakarathna
2026-08-29 21:03:31 +05:30
parent dc7e7a70fc
commit f4db83654c
7 changed files with 601 additions and 19 deletions
@@ -23,7 +23,7 @@ import {
} from '@/components/ui/dialog'
import { FieldGroup } from '@/components/ui/field'
import { toast } from '@/components/ui/toast'
import { stores as storesApi, routes as routesApi, getApiError } from '@/lib/api/index'
import { stores as storesApi, routes as routesApi, getApiError, getPaginatedItems } from '@/lib/api/index'
import type { StoreResponse, RouteResponse } from '@/types/api'
const schema = z.object({
@@ -47,9 +47,6 @@ interface StoreSheetProps {
onSuccess: () => void
}
function ensureItems<T>(value: { items?: T[] } | null | undefined): T[] {
return Array.isArray(value?.items) ? value.items : []
}
export function StoreSheet({ open, onClose, store, onSuccess }: StoreSheetProps) {
const isEdit = !!store
@@ -72,7 +69,7 @@ export function StoreSheet({ open, onClose, store, onSuccess }: StoreSheetProps)
useEffect(() => {
if (open) {
routesApi.list({ pageSize: 100 }).then((res) => setRoutes(ensureItems(res))).catch((err) =>
routesApi.list({ pageSize: 100 }).then((res) => setRoutes(getPaginatedItems(res))).catch((err) =>
toast.add({ title: 'Failed to load routes', description: getApiError(err), type: 'error' })
)