Implement GRN and Purchase Order sheets with form handling and data fetching
This commit is contained in:
@@ -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' })
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user