Skip to content

Commit

Permalink
Added navigate for buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurenko committed Sep 14, 2023
1 parent a87e842 commit 6817eeb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/question-editor/QuestionEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeEvent, MouseEvent, FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import Box from '@mui/material/Box'
import Divider from '@mui/material/Divider'
import IconButton from '@mui/material/IconButton'
Expand Down Expand Up @@ -39,6 +40,7 @@ interface QuestionEditorProps {

const QuestionEditor: FC<QuestionEditorProps> = ({ fetchData, loading }) => {
const { t } = useTranslation()
const navigate = useNavigate()

const { data, handleInputChange, handleNonInputValueChange, handleSubmit } =
useForm<QuestionForm>({
Expand Down Expand Up @@ -161,7 +163,7 @@ const QuestionEditor: FC<QuestionEditorProps> = ({ fetchData, loading }) => {

const buttons = (
<Box sx={styles.buttons}>
<AppButton variant={ButtonVariantEnum.Tonal}>
<AppButton onClick={() => navigate(-1)} variant={ButtonVariantEnum.Tonal}>
{t('common.cancel')}
</AppButton>
<AppButton
Expand Down
3 changes: 3 additions & 0 deletions src/pages/create-or-edit-question/CreateOrEditQuestion.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from 'react'
import { useNavigate } from 'react-router-dom'

import PageWrapper from '~/components/page-wrapper/PageWrapper'
import QuestionEditor from '~/components/question-editor/QuestionEditor'
Expand All @@ -10,6 +11,7 @@ import { defaultResponses, snackbarVariants } from '~/constants'
import { ErrorResponse, QuestionForm } from '~/types'

const CreateOrEditQuestion = () => {
const navigate = useNavigate()
const { setAlert } = useSnackBarContext()

const createQuestion = useCallback(
Expand All @@ -22,6 +24,7 @@ const CreateOrEditQuestion = () => {
severity: snackbarVariants.success,
message: 'categoriesPage.newSubject.successMessage'
})
navigate(-1)
}

const handleResponseError = (error: ErrorResponse) => {
Expand Down

0 comments on commit 6817eeb

Please sign in to comment.