FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 rivejä
1.6 KiB

  1. "use server";
  2. import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  3. import { revalidateTag } from "next/cache";
  4. import { BASE_API_URL } from "@/config/api";
  5. import { HTMLInputTypeAttribute } from "react";
  6. export type TypeInputs = {
  7. type: string
  8. }
  9. export type UomInputs = {
  10. uom: string
  11. }
  12. export type WeightUnitInputs = {
  13. weightUnit: string
  14. conversion: number
  15. }
  16. export type CreateMaterialInputs = {
  17. id?: string | number
  18. code: string;
  19. name: string;
  20. isConsumables: boolean;
  21. // same goes for other props
  22. // change backend for null or not null
  23. description?: string | undefined;
  24. remarks?: string | undefined;
  25. shelfLife?: Number | undefined;
  26. countryOfOrigin?: string | undefined;
  27. minHumid?: number | undefined;
  28. maxHumid?: number | undefined;
  29. minTemp?: number | undefined;
  30. maxTemp?: number | undefined;
  31. sampleRate?: number | undefined;
  32. passingRate?: number | undefined;
  33. netWeight?: number | undefined;
  34. type?: TypeInputs[];
  35. uom?: UomInputs[];
  36. weightUnit?: WeightUnitInputs[];
  37. }
  38. export interface CreateProductMaterialResponse {
  39. id: number | null;
  40. name: string;
  41. code: string;
  42. message: string | null;
  43. errorPosition: keyof CreateMaterialInputs;
  44. }
  45. export const saveMaterial = async (data: CreateMaterialInputs) => {
  46. // try {
  47. const material = await serverFetchJson<CreateProductMaterialResponse>(`${BASE_API_URL}/material/new`, {
  48. method: "POST",
  49. body: JSON.stringify(data),
  50. headers: { "Content-Type": "application/json" },
  51. });
  52. revalidateTag("material");
  53. return material
  54. };