mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
feat: redirect user after updating lesson
This commit is contained in:
parent
3971043ad8
commit
8b8651bda8
@ -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<EditLessonFormPropsType> = ({ lesson }) => {
|
||||
});
|
||||
const { updateLesson, isLoading } = useUpdateLesson();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const history = useHistory();
|
||||
|
||||
const onSubmit: SubmitHandler<InputFields> = async data => {
|
||||
await updateLesson(id, {
|
||||
@ -42,6 +43,8 @@ const EditLessonForm: React.FC<EditLessonFormPropsType> = ({ lesson }) => {
|
||||
duration: data.duration,
|
||||
materials: data.materials?.length !== 0 ? Array.from(data.materials || []) : null,
|
||||
});
|
||||
|
||||
history.push(`/lesson/${id}`);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user