Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aaa #1

Open
dk-morinibu opened this issue Oct 6, 2023 · 6 comments
Open

aaa #1

dk-morinibu opened this issue Oct 6, 2023 · 6 comments

Comments

@dk-morinibu
Copy link

https://confengine.com/conferences/regional-scrum-gathering-tokyo-2024/proposal/19280/10

@dk-morinibu
Copy link
Author

@dk-morinibu
Copy link
Author

IMG_0177

@NibuTake
Copy link
Owner

NibuTake commented Nov 2, 2023

@NibuTake
Copy link
Owner

import React from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import TextField from '@mui/material/TextField';

interface TextInputProps {
  name: string;
  label: string;
  defaultValue?: string;
}

const TextInput: React.FC<TextInputProps> = ({ name, label, defaultValue = '' }) => {
  const { control } = useFormContext();
  
  return (
    <Controller
      name={name}
      control={control}
      defaultValue={defaultValue}
      render={({ field, fieldState }) => (
        <TextField
          {...field}
          label={label}
          error={!!fieldState.error}
          helperText={fieldState.error ? fieldState.error.message : ''}
          variant="outlined"
          fullWidth
        />
      )}
    />
  );
};

export default TextInput;
import React from 'react';
import { useForm, FormProvider, SubmitHandler } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import TextInput from './TextInput';
import Button from '@mui/material/Button';

// Define a schema using Zod (optional)
const schema = z.object({
  firstName: z.string().nonempty({ message: "First name is required" }),
  lastName: z.string().nonempty({ message: "Last name is required" }),
});

type FormData = z.infer<typeof schema>;

const FeatureForm: React.FC = () => {
  const methods = useForm<FormData>({
    resolver: zodResolver(schema),
  });

  const onSubmit: SubmitHandler<FormData> = (data) => {
    console.log(data);
  };

  return (
    <FormProvider {...methods}>
      <form onSubmit={methods.handleSubmit(onSubmit)}>
        <TextInput name="firstName" label="First Name" />
        <TextInput name="lastName" label="Last Name" />
        <Button type="submit" variant="contained" color="primary">
          Submit
        </Button>
      </form>
    </FormProvider>
  );
};

export default FeatureForm;

@dk-morinibu
Copy link
Author

IMG_0076
IMG_0077
IMG_0064
IMG_0062
IMG_0063
IMG_0075

@NibuTake
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants