install.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import TextField from "@mui/material/TextField";
  2. import Grid from "@mui/material/Grid";
  3. import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
  4. import { useForm, Controller, SubmitHandler } from "react-hook-form";
  5. import { useIntl } from "react-intl";
  6. import Layout from "./users/NonSignInLayout";
  7. import {
  8. REAL_NAME_VALIDATOR,
  9. EMAIL_VALIDATOR,
  10. PASSWORD_VALIDATOR,
  11. } from "../../components/form";
  12. interface IFormData {
  13. realName: string;
  14. email: string;
  15. password: string;
  16. passwordConfirmation: string;
  17. }
  18. const Widget = () => {
  19. const intl = useIntl();
  20. const {
  21. control,
  22. formState: { errors },
  23. handleSubmit,
  24. } = useForm<IFormData>({
  25. defaultValues: {
  26. realName: "",
  27. email: "",
  28. password: "",
  29. passwordConfirmation: "",
  30. },
  31. });
  32. const onSubmit: SubmitHandler<IFormData> = (data) => {
  33. // TODO
  34. console.log(data);
  35. };
  36. return (
  37. <Layout
  38. logo={<LockOutlinedIcon />}
  39. title={intl.formatMessage({ id: "nut.install.title" })}
  40. handleSubmit={handleSubmit(onSubmit)}
  41. >
  42. <Grid item xs={12}>
  43. <Controller
  44. name="realName"
  45. control={control}
  46. rules={REAL_NAME_VALIDATOR}
  47. render={({ field }) => (
  48. <TextField
  49. required
  50. fullWidth
  51. label={intl.formatMessage({ id: "fields.real-name" })}
  52. error={errors.realName !== undefined}
  53. helperText={
  54. errors.realName &&
  55. intl.formatMessage({ id: "helpers.real-name" })
  56. }
  57. {...field}
  58. />
  59. )}
  60. />
  61. </Grid>
  62. <Grid item xs={12}>
  63. <Controller
  64. name="email"
  65. rules={EMAIL_VALIDATOR}
  66. control={control}
  67. render={({ field }) => (
  68. <TextField
  69. required
  70. fullWidth
  71. label={intl.formatMessage({ id: "fields.email" })}
  72. type="email"
  73. error={errors.email !== undefined}
  74. helperText={
  75. errors.email && intl.formatMessage({ id: "helpers.email" })
  76. }
  77. {...field}
  78. />
  79. )}
  80. />
  81. </Grid>
  82. <Grid item xs={12}>
  83. <Controller
  84. name="password"
  85. rules={PASSWORD_VALIDATOR}
  86. control={control}
  87. render={({ field }) => (
  88. <TextField
  89. required
  90. fullWidth
  91. label={intl.formatMessage({ id: "fields.password" })}
  92. type="password"
  93. error={errors.password !== undefined}
  94. helperText={
  95. errors.password &&
  96. intl.formatMessage({ id: "helpers.password" })
  97. }
  98. {...field}
  99. />
  100. )}
  101. />
  102. </Grid>
  103. <Grid item xs={12}>
  104. <Controller
  105. name="passwordConfirmation"
  106. control={control}
  107. render={({ field }) => (
  108. <TextField
  109. required
  110. fullWidth
  111. label={intl.formatMessage({ id: "fields.password-confirmation" })}
  112. type="password"
  113. error={errors.passwordConfirmation !== undefined}
  114. helperText={
  115. errors.passwordConfirmation &&
  116. intl.formatMessage({ id: "helpers.password-confirmation" })
  117. }
  118. {...field}
  119. />
  120. )}
  121. />
  122. </Grid>
  123. </Layout>
  124. );
  125. };
  126. export default Widget;