From 8b8651bda81fb5d8607c80cbc3338fd066ec54ba Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Mon, 17 Jan 2022 23:46:20 +0300 Subject: [PATCH] feat: redirect user after updating lesson --- src/components/Forms/LessonForm/EditLessonForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Forms/LessonForm/EditLessonForm.tsx b/src/components/Forms/LessonForm/EditLessonForm.tsx index ac843ef..537d4fe 100644 --- a/src/components/Forms/LessonForm/EditLessonForm.tsx +++ b/src/components/Forms/LessonForm/EditLessonForm.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { yupResolver } from '@hookform/resolvers/yup'; import { SubmitHandler, useForm } from 'react-hook-form'; import type { InputFields } from './LessonForm'; +import { ILesson } from '@educt/interfaces'; import { LessonForm } from '.'; /** @@ -12,8 +13,7 @@ import { EditLessonFormSchema } from './LessonForm.validator'; /** * Hooks */ -import { useParams } from 'react-router-dom'; -import { ILesson } from '@educt/interfaces'; +import { useHistory, useParams } from 'react-router-dom'; import { useUpdateLesson } from '@educt/hooks/queries'; type EditLessonFormPropsType = { @@ -33,6 +33,7 @@ const EditLessonForm: React.FC = ({ lesson }) => { }); const { updateLesson, isLoading } = useUpdateLesson(); const { id } = useParams<{ id: string }>(); + const history = useHistory(); const onSubmit: SubmitHandler = async data => { await updateLesson(id, { @@ -42,6 +43,8 @@ const EditLessonForm: React.FC = ({ lesson }) => { duration: data.duration, materials: data.materials?.length !== 0 ? Array.from(data.materials || []) : null, }); + + history.push(`/lesson/${id}`); }; return (