add data to form create lesson
This commit is contained in:
@@ -51,11 +51,11 @@ export const api = createApi({
|
||||
query: (courseId) => `/lesson/list/${courseId}`,
|
||||
providesTags: ['LessonList']
|
||||
}),
|
||||
createLesson: builder.mutation<BaseResponse<Lesson>, Pick<Lesson, 'name'> & { courseId: string }>({
|
||||
query: ({ name, courseId }) => ({
|
||||
createLesson: builder.mutation<BaseResponse<Lesson>, Pick<Lesson, 'name' | 'date'> & { courseId: string }>({
|
||||
query: ({ name, courseId, date }) => ({
|
||||
url: '/lesson',
|
||||
method: 'POST',
|
||||
body: { name, courseId },
|
||||
body: { name, courseId, date },
|
||||
}),
|
||||
invalidatesTags: ['LessonList']
|
||||
}),
|
||||
|
||||
@@ -38,6 +38,7 @@ import { isTeacher } from '../utils/user'
|
||||
|
||||
interface NewLessonForm {
|
||||
name: string
|
||||
date: string
|
||||
}
|
||||
|
||||
const LessonList = () => {
|
||||
@@ -56,6 +57,7 @@ const LessonList = () => {
|
||||
} = useForm<NewLessonForm>({
|
||||
defaultValues: {
|
||||
name: '',
|
||||
date: '',
|
||||
},
|
||||
})
|
||||
const toast = useToast()
|
||||
@@ -67,13 +69,13 @@ const LessonList = () => {
|
||||
},
|
||||
[setValue],
|
||||
)
|
||||
const onSubmit = ({ name }) => {
|
||||
const onSubmit = ({ name, date }) => {
|
||||
toastRef.current = toast({
|
||||
title: 'Отправляем',
|
||||
status: 'loading',
|
||||
duration: 9000,
|
||||
})
|
||||
createLesson({ name, courseId })
|
||||
createLesson({ name, courseId, date })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
@@ -119,6 +121,33 @@ const LessonList = () => {
|
||||
<CardBody>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<VStack spacing="10" align="left">
|
||||
<Controller
|
||||
control={control}
|
||||
name="date"
|
||||
rules={{ required: 'Обязательное поле' }}
|
||||
render={({ field }) => (
|
||||
<FormControl>
|
||||
<FormLabel>Дата</FormLabel>
|
||||
<Input
|
||||
{...field}
|
||||
required={false}
|
||||
placeholder="Укажите дату лекции"
|
||||
size="md"
|
||||
type="datetime-local"
|
||||
/>
|
||||
{errors.date ? (
|
||||
<FormErrorMessage>
|
||||
{errors.date?.message}
|
||||
</FormErrorMessage>
|
||||
) : (
|
||||
<FormHelperText>
|
||||
Укажите дату и время лекции
|
||||
</FormHelperText>
|
||||
)}
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="name"
|
||||
|
||||
Reference in New Issue
Block a user