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.
 
 

82 lines
2.3 KiB

  1. import { TypeEnum } from "@/app/utils/typeEnum";
  2. import CreateItem from "./CreateItem";
  3. import CreateItemLoading from "./CreateItemLoading";
  4. import { CreateItemInputs } from "@/app/api/settings/item/actions";
  5. import { notFound } from "next/navigation";
  6. import { fetchItem } from "@/app/api/settings/item";
  7. import { fetchQcItems } from "@/app/api/settings/qcItem";
  8. import { fetchQcCategoryCombo } from "@/app/api/settings/qcCategory";
  9. import { fetchWarehouseList } from "@/app/api/warehouse";
  10. interface SubComponents {
  11. Loading: typeof CreateItemLoading;
  12. }
  13. type Props = {
  14. id?: number;
  15. // type: TypeEnum;
  16. };
  17. const CreateItemWrapper: React.FC<Props> & SubComponents = async ({ id }) => {
  18. let result;
  19. let defaultValues: Partial<CreateItemInputs> | undefined;
  20. // console.log(type)
  21. let qcChecks;
  22. if (id) {
  23. result = await fetchItem(id);
  24. const item = result.item;
  25. qcChecks = result.qcChecks;
  26. const activeRows = qcChecks.filter((it) => it.isActive).map((i) => i.id);
  27. // Normalize LocationCode field (handle case sensitivity from MySQL)
  28. const locationCode = item?.LocationCode || item?.locationCode;
  29. console.log("Fetched item data for edit:", {
  30. id: item?.id,
  31. code: item?.code,
  32. name: item?.name,
  33. LocationCode: locationCode,
  34. rawItem: item
  35. });
  36. defaultValues = {
  37. type: item?.type,
  38. id: item?.id,
  39. code: item?.code,
  40. name: item?.name,
  41. description: item?.description,
  42. remarks: item?.remarks,
  43. shelfLife: item?.shelfLife,
  44. countryOfOrigin: item?.countryOfOrigin,
  45. maxQty: item?.maxQty,
  46. qcChecks: qcChecks,
  47. qcChecks_active: activeRows,
  48. qcCategoryId: item.qcCategory?.id,
  49. qcType: result.qcType,
  50. store_id: item?.store_id,
  51. warehouse: item?.warehouse,
  52. area: item?.area,
  53. slot: item?.slot,
  54. LocationCode: locationCode,
  55. isEgg: item?.isEgg,
  56. isFee: item?.isFee,
  57. isBag: item?.isBag,
  58. };
  59. }
  60. const qcCategoryCombo = await fetchQcCategoryCombo();
  61. const warehouses = await fetchWarehouseList();
  62. return (
  63. <CreateItem
  64. isEditMode={Boolean(id)}
  65. defaultValues={defaultValues}
  66. qcChecks={qcChecks || []}
  67. qcCategoryCombo={qcCategoryCombo}
  68. warehouses={warehouses}
  69. />
  70. );
  71. };
  72. CreateItemWrapper.Loading = CreateItemLoading;
  73. export default CreateItemWrapper;