feat: redirect user after updating lesson

This commit is contained in:
Sergey Yarkov 2022-01-17 23:46:20 +03:00
parent 3971043ad8
commit 8b8651bda8

View File

@ -2,6 +2,7 @@ import React from 'react';
import { yupResolver } from '@hookform/resolvers/yup'; import { yupResolver } from '@hookform/resolvers/yup';
import { SubmitHandler, useForm } from 'react-hook-form'; import { SubmitHandler, useForm } from 'react-hook-form';
import type { InputFields } from './LessonForm'; import type { InputFields } from './LessonForm';
import { ILesson } from '@educt/interfaces';
import { LessonForm } from '.'; import { LessonForm } from '.';
/** /**
@ -12,8 +13,7 @@ import { EditLessonFormSchema } from './LessonForm.validator';
/** /**
* Hooks * Hooks
*/ */
import { useParams } from 'react-router-dom'; import { useHistory, useParams } from 'react-router-dom';
import { ILesson } from '@educt/interfaces';
import { useUpdateLesson } from '@educt/hooks/queries'; import { useUpdateLesson } from '@educt/hooks/queries';
type EditLessonFormPropsType = { type EditLessonFormPropsType = {
@ -33,6 +33,7 @@ const EditLessonForm: React.FC<EditLessonFormPropsType> = ({ lesson }) => {
}); });
const { updateLesson, isLoading } = useUpdateLesson(); const { updateLesson, isLoading } = useUpdateLesson();
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
const history = useHistory();
const onSubmit: SubmitHandler<InputFields> = async data => { const onSubmit: SubmitHandler<InputFields> = async data => {
await updateLesson(id, { await updateLesson(id, {
@ -42,6 +43,8 @@ const EditLessonForm: React.FC<EditLessonFormPropsType> = ({ lesson }) => {
duration: data.duration, duration: data.duration,
materials: data.materials?.length !== 0 ? Array.from(data.materials || []) : null, materials: data.materials?.length !== 0 ? Array.from(data.materials || []) : null,
}); });
history.push(`/lesson/${id}`);
}; };
return ( return (