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.
 
 

212 line
5.8 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 { CreateEquipmentInputs } from "@/app/api/settings/equipment/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<CreateEquipmentInputs> | undefined;
  29. };
  30. const ProductDetails: React.FC<Props> = ({ isEditMode }) => {
  31. const {
  32. t,
  33. i18n: { language },
  34. } = useTranslation();
  35. const {
  36. register,
  37. formState: { errors, defaultValues, touchedFields },
  38. watch,
  39. control,
  40. setValue,
  41. getValues,
  42. reset,
  43. resetField,
  44. setError,
  45. clearErrors,
  46. } = useFormContext<CreateEquipmentInputs>();
  47. // const typeColumns = useMemo<GridColDef[]>(
  48. // () => [
  49. // {
  50. // field: "type",
  51. // headerName: "type",
  52. // flex: 1,
  53. // editable: true,
  54. // },
  55. // ],
  56. // []
  57. // );
  58. // const weightUnitColumns = useMemo<GridColDef[]>(
  59. // () => [
  60. // {
  61. // field: "weightUnit",
  62. // headerName: "Weight Unit",
  63. // flex: 1,
  64. // editable: true,
  65. // },
  66. // {
  67. // field: "conversion",
  68. // headerName: "conversion", // show base unit
  69. // flex: 1,
  70. // type: "number",
  71. // editable: true,
  72. // },
  73. // ],
  74. // []
  75. // );
  76. // const uomColumns = useMemo<GridColDef[]>(
  77. // () => [
  78. // {
  79. // field: "uom",
  80. // headerName: "uom",
  81. // flex: 1,
  82. // editable: true,
  83. // },
  84. // ],
  85. // []
  86. // );
  87. // const validationTest = useCallback(
  88. // (
  89. // newRow: GridRowModel<TableRow<Partial<CreateItemInputs>, EntryError>>
  90. // ): EntryError => {
  91. // const error: EntryError = {};
  92. // console.log(newRow);
  93. // return Object.keys(error).length > 0 ? error : undefined;
  94. // },
  95. // []
  96. // );
  97. const handleCancel = () => {
  98. // router.replace(`/settings/equipment`);
  99. console.log("cancel");
  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("Equipment Details")}
  107. </Typography>
  108. <Grid item xs={6}>
  109. <TextField
  110. label={t("Equipment Type")}
  111. fullWidth
  112. {...register("equipmentTypeId")}
  113. />
  114. </Grid>
  115. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  116. {/*
  117. <Grid item xs={6}>
  118. <TextField
  119. label={t("Name")}
  120. fullWidth
  121. {...register("name", {
  122. required: "name required!",
  123. })}
  124. error={Boolean(errors.name)}
  125. helperText={errors.name?.message}
  126. />
  127. </Grid>
  128. <Grid item xs={6}>
  129. <TextField
  130. label={t("Code")}
  131. fullWidth
  132. {...register("code", {
  133. required: "code required!",
  134. })}
  135. error={Boolean(errors.code)}
  136. helperText={errors.code?.message}
  137. />
  138. </Grid>
  139. */}
  140. <Grid item xs={6}>
  141. <TextField
  142. label={t("description")}
  143. fullWidth
  144. {...register("description")}
  145. />
  146. </Grid>
  147. <Grid item xs={12}>
  148. <Stack
  149. direction="row"
  150. justifyContent="flex-start"
  151. spacing={2}
  152. sx={{ mt: 2 }}
  153. >
  154. <Button
  155. name="submit"
  156. variant="contained"
  157. startIcon={<Check />}
  158. type="submit"
  159. // disabled={submitDisabled}
  160. >
  161. {isEditMode ? t("Save") : t("Confirm")}
  162. </Button>
  163. <Button
  164. variant="outlined"
  165. startIcon={<Close />}
  166. onClick={handleCancel}
  167. >
  168. {t("Cancel")}
  169. </Button>
  170. <Button
  171. variant="outlined"
  172. startIcon={<RestartAlt />}
  173. onClick={() => reset()}
  174. >
  175. {t("Reset")}
  176. </Button>
  177. </Stack>
  178. </Grid>
  179. {/* <Grid item xs={6}>
  180. <InputDataGrid<CreateItemInputs, EntryError>
  181. _formKey={"type"}
  182. columns={typeColumns}
  183. validateRow={validationTest}
  184. />
  185. </Grid>
  186. <Grid item xs={6}>
  187. <InputDataGrid<CreateItemInputs, EntryError>
  188. _formKey={"uom"}
  189. columns={uomColumns}
  190. validateRow={validationTest}
  191. />
  192. </Grid>
  193. <Grid item xs={12}>
  194. <InputDataGrid<CreateItemInputs, EntryError>
  195. _formKey={"weightUnit"}
  196. columns={weightUnitColumns}
  197. validateRow={validationTest}
  198. />
  199. </Grid>*/}
  200. </Grid>
  201. </Box>
  202. </CardContent>
  203. </Card>
  204. );
  205. };
  206. export default ProductDetails;