FPSMS-frontend
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

258 linhas
7.4 KiB

  1. "use client";
  2. import {
  3. Box,
  4. Button,
  5. Card,
  6. CardContent,
  7. Grid,
  8. Stack,
  9. TextField,
  10. Typography,
  11. } from "@mui/material";
  12. import { Check, Close, EditNote } from "@mui/icons-material";
  13. import { useFormContext } from "react-hook-form";
  14. import { useTranslation } from "react-i18next";
  15. import InputDataGrid from "../InputDataGrid";
  16. import { useCallback, useMemo, useState } from "react";
  17. import { GridColDef, GridRowModel } from "@mui/x-data-grid";
  18. import { InputDataGridProps, TableRow } from "../InputDataGrid/InputDataGrid";
  19. import { TypeEnum } from "@/app/utils/typeEnum";
  20. import { NumberInputProps } from "./NumberInputProps";
  21. import { CreateItemInputs } from "@/app/api/settings/item/actions";
  22. import { RestartAlt } from "@mui/icons-material";
  23. type Props = {
  24. // isEditMode: boolean;
  25. // type: TypeEnum;
  26. isEditMode: boolean;
  27. // type: TypeEnum;
  28. defaultValues: Partial<CreateItemInputs> | undefined;
  29. qcChecks: ItemQc[]
  30. };
  31. const ProductDetails: React.FC<Props> = ({isEditMode}) => {
  32. const {
  33. t,
  34. i18n: { language },
  35. } = useTranslation();
  36. const {
  37. register,
  38. formState: { errors, defaultValues, touchedFields },
  39. watch,
  40. control,
  41. setValue,
  42. getValues,
  43. reset,
  44. resetField,
  45. setError,
  46. clearErrors,
  47. } = useFormContext<CreateItemInputs>();
  48. // const typeColumns = useMemo<GridColDef[]>(
  49. // () => [
  50. // {
  51. // field: "type",
  52. // headerName: "type",
  53. // flex: 1,
  54. // editable: true,
  55. // },
  56. // ],
  57. // []
  58. // );
  59. // const weightUnitColumns = useMemo<GridColDef[]>(
  60. // () => [
  61. // {
  62. // field: "weightUnit",
  63. // headerName: "Weight Unit",
  64. // flex: 1,
  65. // editable: true,
  66. // },
  67. // {
  68. // field: "conversion",
  69. // headerName: "conversion", // show base unit
  70. // flex: 1,
  71. // type: "number",
  72. // editable: true,
  73. // },
  74. // ],
  75. // []
  76. // );
  77. // const uomColumns = useMemo<GridColDef[]>(
  78. // () => [
  79. // {
  80. // field: "uom",
  81. // headerName: "uom",
  82. // flex: 1,
  83. // editable: true,
  84. // },
  85. // ],
  86. // []
  87. // );
  88. // const validationTest = useCallback(
  89. // (
  90. // newRow: GridRowModel<TableRow<Partial<CreateItemInputs>, EntryError>>
  91. // ): EntryError => {
  92. // const error: EntryError = {};
  93. // console.log(newRow);
  94. // return Object.keys(error).length > 0 ? error : undefined;
  95. // },
  96. // []
  97. // );
  98. const handleCancel = () => {
  99. router.replace(`/settings/product`);
  100. };
  101. return (
  102. <Card sx={{ display: "block" }}>
  103. <CardContent component={Stack} spacing={4}>
  104. <Box>
  105. <Typography variant="overline" display="block" marginBlockEnd={1}>
  106. {t("Product Details")}
  107. </Typography>
  108. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  109. <Grid item xs={6}>
  110. <TextField
  111. label={t("Name")}
  112. fullWidth
  113. {...register("name", {
  114. required: "name required!",
  115. })}
  116. error={Boolean(errors.name)}
  117. helperText={errors.name?.message}
  118. />
  119. </Grid>
  120. <Grid item xs={6}>
  121. <TextField
  122. label={t("Code")}
  123. fullWidth
  124. {...register("code", {
  125. required: "code required!",
  126. })}
  127. error={Boolean(errors.code)}
  128. helperText={errors.code?.message}
  129. />
  130. </Grid>
  131. <Grid item xs={6}>
  132. <TextField
  133. label={t("Type")}
  134. fullWidth
  135. {...register("type", {
  136. required: "type required!",
  137. })}
  138. error={Boolean(errors.type)}
  139. helperText={errors.type?.message}
  140. />
  141. </Grid>
  142. <Grid item xs={6}>
  143. <TextField
  144. label={t("description")}
  145. fullWidth
  146. {...register("description")}
  147. />
  148. </Grid>
  149. <Grid item xs={6}>
  150. <TextField
  151. label={t("shelfLife")}
  152. type="number"
  153. fullWidth
  154. {...register("shelfLife", {
  155. valueAsNumber: true,
  156. required: "shelfLife required!",
  157. })}
  158. error={Boolean(errors.shelfLife)}
  159. helperText={errors.shelfLife?.message}
  160. />
  161. </Grid>
  162. <Grid item xs={6}>
  163. <TextField
  164. label={t("countryOfOrigin")}
  165. fullWidth
  166. {...register("countryOfOrigin", {
  167. required: "countryOfOrigin required!",
  168. })}
  169. error={Boolean(errors.countryOfOrigin)}
  170. helperText={errors.countryOfOrigin?.message}
  171. />
  172. </Grid>
  173. <Grid item xs={6}>
  174. <TextField
  175. label={t("remarks")}
  176. fullWidth
  177. {...register("remarks", {
  178. // required: "remarks required!",
  179. })}
  180. error={Boolean(errors.remarks)}
  181. helperText={errors.remarks?.message}
  182. />
  183. </Grid>
  184. <Grid item xs={6}>
  185. <TextField
  186. label={t("maxQty")}
  187. type="number"
  188. fullWidth
  189. inputProps={NumberInputProps}
  190. {...register("maxQty", {
  191. valueAsNumber: true,
  192. min: 0,
  193. required: "maxQty required!",
  194. })}
  195. error={Boolean(errors.maxQty)}
  196. helperText={errors.maxQty?.message}
  197. />
  198. </Grid>
  199. <Grid item xs={0}>
  200. <Stack direction="row" justifyContent="flex-end" spacing={2} sx={{ mt: 2 }}>
  201. <Button
  202. name="submit"
  203. variant="contained"
  204. startIcon={<Check />}
  205. type="submit"
  206. // disabled={submitDisabled}
  207. >
  208. {isEditMode ? t("Save") : t("Confirm")}
  209. </Button>
  210. <Button
  211. variant="outlined"
  212. startIcon={<Close />}
  213. onClick={handleCancel}
  214. >
  215. {t("Cancel")}
  216. </Button>
  217. <Button
  218. variant="outlined"
  219. startIcon={<RestartAlt />}
  220. onClick={() => reset()}
  221. >
  222. {t("Reset")}
  223. </Button>
  224. </Stack>
  225. </Grid>
  226. {/* <Grid item xs={6}>
  227. <InputDataGrid<CreateItemInputs, EntryError>
  228. _formKey={"type"}
  229. columns={typeColumns}
  230. validateRow={validationTest}
  231. />
  232. </Grid>
  233. <Grid item xs={6}>
  234. <InputDataGrid<CreateItemInputs, EntryError>
  235. _formKey={"uom"}
  236. columns={uomColumns}
  237. validateRow={validationTest}
  238. />
  239. </Grid>
  240. <Grid item xs={12}>
  241. <InputDataGrid<CreateItemInputs, EntryError>
  242. _formKey={"weightUnit"}
  243. columns={weightUnitColumns}
  244. validateRow={validationTest}
  245. />
  246. </Grid>*/}
  247. </Grid>
  248. </Box>
  249. </CardContent>
  250. </Card>
  251. );
  252. };
  253. export default ProductDetails;