|
- "use server";
- import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
- import { revalidateTag } from "next/cache";
- import { BASE_API_URL } from "@/config/api";
- import { HTMLInputTypeAttribute } from "react";
-
- export type TypeInputs = {
- type: string
- }
- export type UomInputs = {
- uom: string
- }
- export type WeightUnitInputs = {
- weightUnit: string
- conversion: number
- }
- export type CreateMaterialInputs = {
- id?: string | number
- code: string;
- name: string;
- isConsumables: boolean;
- // same goes for other props
- // change backend for null or not null
- description?: string | undefined;
- remarks?: string | undefined;
- shelfLife?: Number | undefined;
- countryOfOrigin?: string | undefined;
- minHumid?: number | undefined;
- maxHumid?: number | undefined;
- minTemp?: number | undefined;
- maxTemp?: number | undefined;
- sampleRate?: number | undefined;
- passingRate?: number | undefined;
- netWeight?: number | undefined;
- type?: TypeInputs[];
- uom?: UomInputs[];
- weightUnit?: WeightUnitInputs[];
- }
- export interface CreateProductMaterialResponse {
- id: number | null;
- name: string;
- code: string;
- message: string | null;
- errorPosition: keyof CreateMaterialInputs;
- }
-
- export const saveMaterial = async (data: CreateMaterialInputs) => {
- // try {
- const material = await serverFetchJson<CreateProductMaterialResponse>(`${BASE_API_URL}/material/new`, {
- method: "POST",
- body: JSON.stringify(data),
- headers: { "Content-Type": "application/json" },
- });
- revalidateTag("material");
- return material
- };
|