"use server"; import { ServerFetchError, serverFetchJson, serverFetchWithNoContent, } from "@/app/utils/fetchUtil"; import { revalidateTag } from "next/cache"; import { BASE_API_URL } from "@/config/api"; import { CreateItemResponse, RecordsRes } from "../../utils"; import { ItemQc, ItemsResult } from "."; import { QcChecksInputs } from "../qcCheck/actions"; import { cache } from "react"; // export type TypeInputs = { // id: number; // name: string // } // export type UomInputs = { // uom: string // } // export type WeightUnitInputs = { // weightUnit: string // conversion: number // } export type CreateItemInputs = { id?: string | number; code: string; name: string; description?: string | undefined; remarks?: string | undefined; shelfLife?: number | undefined; countryOfOrigin?: string | undefined; maxQty: number; type: string; qcChecks: QcChecksInputs[]; qcChecks_active: number[]; qcCategoryId: number | undefined; }; export const saveItem = async (data: CreateItemInputs) => { const item = await serverFetchJson>( `${BASE_API_URL}/items/new`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); revalidateTag("items"); return item; }; export interface ItemCombo { id: number, label: string, uomId: number, uom: string, uomDesc: string, group?: string, currentStockBalance?: number, } export const fetchAllItemsInClient = cache(async () => { return serverFetchJson(`${BASE_API_URL}/items/consumables`, { next: { tags: ["items"] }, }); }); export const fetchPickOrderItemsByPageClient = cache( async (queryParams?: Record) => { if (queryParams) { const queryString = new URLSearchParams(queryParams).toString(); return serverFetchJson>( `${BASE_API_URL}/items/pickOrderItems?${queryString}`, { method: "GET", next: { tags: ["pickorder"] }, }, ); } else { return serverFetchJson>( `${BASE_API_URL}/items/pickOrderItems`, { method: "GET", next: { tags: ["pickorder"] }, }, ); } }, );