add data to form create lesson
All checks were successful
platform/bro/pipeline/head This commit looks good
platform/bro/pipeline/pr-master This commit looks good

This commit is contained in:
2024-03-31 18:20:09 +10:00
parent 0f796fd9bc
commit cf32ba103e
3 changed files with 185 additions and 6 deletions

View File

@@ -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']
}),

View File

@@ -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"