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.
 
 
 
robotop.krasnikov.pro/components/RegistrationForm.tsx

109 lines
4.2 KiB

import React,{useRef} from 'react';
import { useForm, SubmitHandler, FormProvider } from "react-hook-form";
import { Input, InputPass } from "./UX";
interface IFormInputs {
name_team_coach: string,
coach_telefon_number: string,
nominations: string,
city_team: string,
training_institution_team: string,
team_name: string,
name_first_participant: string,
first_partial_class: number,
name_second_participant: string,
second_class: number,
name_third_party: string,
third_part_class: number,
body?: string[] | number[]
}
const defaultValues = {
name_team_coach: '',
coach_telefon_number: '',
nominations: '0',
city_team: '',
training_institution_team: '',
team_name: '',
name_first_participant: '',
first_partial_class: 0,
name_second_participant: '',
second_class: 0,
name_third_party: 'нет',
third_part_class: 0,
};
export const RegistrationForm = (props): JSX.Element => {
const form = useRef(null);
const methods = useForm({ defaultValues });
const onSubmit: SubmitHandler<IFormInputs> = data => {
fetch('/api/registration', { method: 'POST', body: Object.values(data) as any})
.then((data) => {
props.updateData(data);
})
methods.reset(defaultValues);
}
return (
<>
<div className="mt-10 sm:mt-0">
<div className="md:gap-6">
<div className="md:col-span-1">
<div className="px-4 sm:px-0">
<h3 className="text-lg font-medium leading-6">Регистрация команд</h3>
</div>
</div>
<div className="mt-5 md:mt-0 md:col-span-2">
<FormProvider {...methods} >
<form ref={form} onSubmit={methods.handleSubmit(onSubmit)}>
<div className="shadow overflow-hidden sm:rounded-md">
<h3 className="m-2 text-lg font-medium leading-6"> Для регистрации команд тренеру необходимо зарегистрироваться в системе</h3>
<div className="px-4 py-5 bg-white sm:p-6">
<div className="grid grid-cols-6 gap-6">
<div className="col-span-6 sm:col-span-3">
<Input placeholder="Логин" name="login" text="Логин" additional={""}/>
</div>
<div className="col-span-6 sm:col-span-3">
<InputPass placeholder="Пароль" name="pass" text="Пароль" additional={""} />
</div>
<div className="col-span-6 sm:col-span-3">
<Input placeholder="Иванов Иван Иванович" name="name_team_coach" text="ФИО тренера" additional={""}/>
</div>
<div className="col-span-6 sm:col-span-3">
<Input placeholder="+79181234567" name="coach_telefon_number" text="Контактный телефон тренера" additional={"valueAsNumber: true"} />
</div>
<div className="col-span-6 sm:col-span-3">
<Input placeholder="ivan@mail.ru" name="city_team" text="E-mail тренера" additional={""} />
</div>
<div className="col-span-6 sm:col-span-3">
<Input placeholder="МАОУ СОШ 103" name="training_institution_team" text="Образовательное учреждение" additional={""} />
</div>
</div>
</div>
<div className="px-4 py-3 bg-gray-50 text-right sm:px-6">
<button
type="submit"
className="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
>
Регистрация
</button>
<p className="mt-1 text-sm">Регистрация открыта до 22.05.2023</p>
</div>
</div>
</form>
</FormProvider>
</div>
</div>
</div>
</>
);
};
export default RegistrationForm;