FPSMS-frontend
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 

148 строки
4.2 KiB

  1. "use client";
  2. import { UserResult } from "@/app/api/user";
  3. import { UserInputs } from "@/app/api/user/actions";
  4. import {
  5. Card,
  6. CardContent,
  7. Grid,
  8. Stack,
  9. TextField,
  10. Typography,
  11. makeStyles,
  12. } from "@mui/material";
  13. import { useFormContext } from "react-hook-form";
  14. import { useTranslation } from "react-i18next";
  15. const UserDetail: React.FC = () => {
  16. const { t } = useTranslation("user");
  17. const {
  18. register,
  19. formState: { errors },
  20. control,
  21. watch,
  22. } = useFormContext<UserInputs>();
  23. const password = watch("password");
  24. const confirmPassword = watch("confirmPassword");
  25. const username = watch("username");
  26. const staffNo = watch("staffNo");
  27. return (
  28. <Card>
  29. <CardContent component={Stack} spacing={4}>
  30. <Typography variant="overline" display="block" marginBlockEnd={1}>
  31. {t("User Detail")}
  32. </Typography>
  33. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  34. <Grid item xs={6}>
  35. <TextField
  36. label={t("username")}
  37. fullWidth
  38. variant="filled"
  39. InputLabelProps={{
  40. shrink: !!username,
  41. sx: { fontSize: "0.9375rem" },
  42. }}
  43. InputProps={{
  44. sx: { paddingTop: "8px" },
  45. }}
  46. {...register("username", {
  47. required: "username required!",
  48. })}
  49. error={Boolean(errors.username)}
  50. />
  51. </Grid>
  52. <Grid item xs={6}>
  53. <TextField
  54. label={t("staffNo")}
  55. fullWidth
  56. variant="filled"
  57. InputLabelProps={{
  58. shrink: !!staffNo,
  59. sx: { fontSize: "0.9375rem" },
  60. }}
  61. InputProps={{
  62. sx: { paddingTop: "8px" },
  63. }}
  64. {...register("staffNo")}
  65. error={Boolean(errors.staffNo)}
  66. helperText={
  67. Boolean(errors.staffNo) && errors.staffNo?.message
  68. ? t(errors.staffNo.message)
  69. : ""
  70. }
  71. />
  72. </Grid>
  73. <Grid item xs={6}>
  74. <TextField
  75. label={t("password")}
  76. fullWidth
  77. type="password"
  78. variant="filled"
  79. InputLabelProps={{
  80. shrink: !!password,
  81. sx: { fontSize: "0.9375rem" },
  82. }}
  83. InputProps={{
  84. sx: { paddingTop: "8px" },
  85. }}
  86. {...register("password")}
  87. helperText={
  88. Boolean(errors.password) &&
  89. (errors.password?.message
  90. ? t(errors.password.message)
  91. : t("Please input correct password"))
  92. }
  93. error={Boolean(errors.password)}
  94. />
  95. </Grid>
  96. <Grid item xs={6}>
  97. <TextField
  98. label={t("Confirm Password")}
  99. fullWidth
  100. type="password"
  101. variant="filled"
  102. InputLabelProps={{
  103. shrink: !!confirmPassword,
  104. sx: { fontSize: "0.9375rem" },
  105. }}
  106. InputProps={{
  107. sx: { paddingTop: "8px" },
  108. }}
  109. {...register("confirmPassword", {
  110. validate: (value) => {
  111. if (password && value !== password) {
  112. return "Passwords do not match";
  113. }
  114. return true;
  115. },
  116. })}
  117. error={Boolean(errors.confirmPassword)}
  118. helperText={
  119. Boolean(errors.confirmPassword) &&
  120. (errors.confirmPassword?.message
  121. ? t(errors.confirmPassword.message)
  122. : "")
  123. }
  124. />
  125. </Grid>
  126. {/* <Grid item xs={6}>
  127. <TextField
  128. label={t("name")}
  129. fullWidth
  130. {...register("name", {
  131. required: "name required!",
  132. })}
  133. error={Boolean(errors.name)}
  134. />
  135. </Grid> */}
  136. </Grid>
  137. </CardContent>
  138. </Card>
  139. );
  140. };
  141. export default UserDetail;