Skip to content

Commit 42d2e4b

Browse files
authored
Исправил баг который не перекидывал на главную страницу после создания вопроса (#335)
1 parent 13dc07b commit 42d2e4b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/features/questions/create-question/CreateQuestionPage.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useState, useCallback, useEffect, useRef } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
3-
import { Link, Redirect } from 'react-router-dom';
3+
import { Link, Redirect, useHistory } from 'react-router-dom';
44
import styled from 'styled-components';
55
import { Editor } from '@toast-ui/react-editor';
66
import { PlusOutlined } from '@ant-design/icons';
7-
import { Button, Tag, Input, Alert, Typography } from 'antd';
7+
import { Button, Tag, Input, Alert, Typography, notification } from 'antd';
88
import { Title } from 'app/Title/Title';
99
import { Paper } from 'components/layout/Paper';
1010
import { addQuestion } from 'features/questions/questionsSlice';
@@ -93,6 +93,7 @@ CancelLinkLabel.propTypes = {
9393

9494
const CreateQuestion = () => {
9595
const dispatch = useDispatch();
96+
const history = useHistory();
9697
const editorRef = useRef();
9798

9899
const profile = useSelector(selectProfile);
@@ -141,10 +142,17 @@ const CreateQuestion = () => {
141142
tags,
142143
userId: profile._id,
143144
})
144-
);
145-
setQuestion('');
146-
setFullDescription('');
147-
editorRef.current.getInstance().reset();
145+
)
146+
.unwrap()
147+
.then(() => {
148+
notification.success({
149+
message: 'Вопрос успешно опубликован',
150+
});
151+
history.push('/');
152+
setQuestion('');
153+
setFullDescription('');
154+
editorRef.current.getInstance().reset();
155+
});
148156
};
149157

150158
const handleChange = () => {

0 commit comments

Comments
 (0)