| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import TextField from "@mui/material/TextField";
- import Grid from "@mui/material/Grid";
- import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
- import { useForm, Controller, SubmitHandler } from "react-hook-form";
- import { useIntl } from "react-intl";
- import Layout from "./users/NonSignInLayout";
- import {
- REAL_NAME_VALIDATOR,
- EMAIL_VALIDATOR,
- PASSWORD_VALIDATOR,
- } from "../../components/form";
- interface IFormData {
- realName: string;
- email: string;
- password: string;
- passwordConfirmation: string;
- }
- const Widget = () => {
- const intl = useIntl();
- const {
- control,
- formState: { errors },
- handleSubmit,
- } = useForm<IFormData>({
- defaultValues: {
- realName: "",
- email: "",
- password: "",
- passwordConfirmation: "",
- },
- });
- const onSubmit: SubmitHandler<IFormData> = (data) => {
- // TODO
- console.log(data);
- };
- return (
- <Layout
- logo={<LockOutlinedIcon />}
- title={intl.formatMessage({ id: "nut.install.title" })}
- handleSubmit={handleSubmit(onSubmit)}
- >
- <Grid item xs={12}>
- <Controller
- name="realName"
- control={control}
- rules={REAL_NAME_VALIDATOR}
- render={({ field }) => (
- <TextField
- required
- fullWidth
- label={intl.formatMessage({ id: "fields.real-name" })}
- error={errors.realName !== undefined}
- helperText={
- errors.realName &&
- intl.formatMessage({ id: "helpers.real-name" })
- }
- {...field}
- />
- )}
- />
- </Grid>
- <Grid item xs={12}>
- <Controller
- name="email"
- rules={EMAIL_VALIDATOR}
- control={control}
- render={({ field }) => (
- <TextField
- required
- fullWidth
- label={intl.formatMessage({ id: "fields.email" })}
- type="email"
- error={errors.email !== undefined}
- helperText={
- errors.email && intl.formatMessage({ id: "helpers.email" })
- }
- {...field}
- />
- )}
- />
- </Grid>
- <Grid item xs={12}>
- <Controller
- name="password"
- rules={PASSWORD_VALIDATOR}
- control={control}
- render={({ field }) => (
- <TextField
- required
- fullWidth
- label={intl.formatMessage({ id: "fields.password" })}
- type="password"
- error={errors.password !== undefined}
- helperText={
- errors.password &&
- intl.formatMessage({ id: "helpers.password" })
- }
- {...field}
- />
- )}
- />
- </Grid>
- <Grid item xs={12}>
- <Controller
- name="passwordConfirmation"
- control={control}
- render={({ field }) => (
- <TextField
- required
- fullWidth
- label={intl.formatMessage({ id: "fields.password-confirmation" })}
- type="password"
- error={errors.passwordConfirmation !== undefined}
- helperText={
- errors.passwordConfirmation &&
- intl.formatMessage({ id: "helpers.password-confirmation" })
- }
- {...field}
- />
- )}
- />
- </Grid>
- </Layout>
- );
- };
- export default Widget;
|