"use server"; import { ServerFetchError, serverFetchJson, serverFetchWithNoContent, } from "@/app/utils/fetchUtil"; import { revalidateTag } from "next/cache"; import { BASE_API_URL } from "@/config/api"; import { CreateItemResponse } 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[]; }; 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, } export const fetchAllItemsInClient = cache(async () => { return serverFetchJson(`${BASE_API_URL}/items/consumables`, { next: { tags: ["items"] }, }); });