FPSMS-frontend
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 

135 rader
4.6 KiB

  1. "use client";
  2. import {
  3. Box,
  4. Card,
  5. CardContent,
  6. Grid,
  7. Stack,
  8. TextField,
  9. Typography,
  10. } from "@mui/material";
  11. import { Controller, useFormContext } from "react-hook-form";
  12. import { useTranslation } from "react-i18next";
  13. import InputDataGrid from "../InputDataGrid";
  14. import { useCallback, useEffect, useMemo, useState } from "react";
  15. import { GridColDef, GridRowModel } from "@mui/x-data-grid";
  16. import { InputDataGridProps, TableRow } from "../InputDataGrid/InputDataGrid";
  17. import { TypeEnum } from "@/app/utils/typeEnum";
  18. import { CreateItemInputs } from "@/app/api/settings/item/actions";
  19. import { NumberInputProps } from "@/components/CreateItem/NumberInputProps";
  20. import { arrayToDateString, integerFormatter } from "@/app/utils/formatUtil";
  21. import { DetailedProdScheduleResult } from "@/app/api/scheduling";
  22. // import { SaveDetailedSchedule } from "./DetailedScheduleDetailView";
  23. // temp interface input
  24. type Props = {
  25. // recordDetails: SaveDetailedSchedule;
  26. isEditing: boolean;
  27. };
  28. const DetailInfoCard: React.FC<Props> = ({
  29. // recordDetails,
  30. isEditing
  31. }) => {
  32. const {
  33. t,
  34. i18n: { language },
  35. } = useTranslation();
  36. const {
  37. control,
  38. register,
  39. getValues,
  40. formState: { errors, defaultValues, touchedFields },
  41. } = useFormContext<DetailedProdScheduleResult>();
  42. // const [details, setDetails] = useState<DetailedProdScheduleResult | undefined>(undefined);
  43. useEffect(() => {
  44. console.log("[debug] record details", defaultValues)
  45. // setDetails(defaultValues as DetailedProdScheduleResult);
  46. }, [defaultValues])
  47. useEffect(() => {
  48. console.log("[debug] isEdit", isEditing);
  49. }, [isEditing]);
  50. return (
  51. <Card sx={{ display: "block" }}>
  52. <CardContent component={Stack} spacing={4}>
  53. <Box>
  54. {/* <Typography variant="overline" display="block" marginBlockEnd={1}>
  55. {t("Schedule Detail")}
  56. </Typography> */}
  57. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  58. <Grid item xs={6}>
  59. <TextField
  60. label={t("Production Date")}
  61. fullWidth
  62. // {...register("scheduleAt", {
  63. // required: "Schedule At required!",
  64. // })}
  65. defaultValue={`${arrayToDateString(getValues("scheduleAt"))}`}
  66. // defaultValue={details?.scheduledPeriod}
  67. disabled={!isEditing}
  68. // error={Boolean(errors.name)}
  69. // helperText={errors.name?.message}
  70. />
  71. </Grid>
  72. <Grid item xs={6}>
  73. <TextField
  74. label={t("Total Job Orders")}
  75. fullWidth
  76. // {...register("totalFGType", {
  77. // required: "Total FG Type required!",
  78. // })}
  79. // TODO: May update by table row qty
  80. defaultValue={
  81. typeof getValues("totalFGType") == "number"
  82. ? integerFormatter.format(getValues("totalFGType"))
  83. : getValues("totalFGType")
  84. }
  85. // defaultValue={details?.productCount}
  86. disabled={!isEditing}
  87. // error={Boolean(errors.code)}
  88. // helperText={errors.code?.message}
  89. />
  90. </Grid>
  91. <Grid item xs={6}>
  92. <Controller
  93. name="totalEstProdCount"
  94. control={control}
  95. render={({ field }) => (
  96. <TextField
  97. {...field}
  98. label={t("Total Production Qty")}
  99. fullWidth
  100. disabled={!isEditing}
  101. // TODO: May update by table demand qty
  102. defaultValue={
  103. typeof field.value == "number"
  104. ? integerFormatter.format(field.value)
  105. : field.value
  106. }
  107. // value={
  108. // typeof field.value == "number"
  109. // ? integerFormatter.format(field.value)
  110. // : field.value
  111. // }
  112. // defaultValue={typeof (details?.productionCount) == "number" ? integerFormatter.format(details?.productionCount) : details?.productionCount}
  113. // error={Boolean(errors.type)}
  114. // helperText={errors.type?.message}
  115. required
  116. />
  117. )}
  118. />
  119. </Grid>
  120. </Grid>
  121. </Box>
  122. </CardContent>
  123. </Card>
  124. );
  125. };
  126. export default DetailInfoCard;