|
1 | 1 | import React, { useState, useCallback, useEffect, useRef } from 'react'; |
2 | 2 | import { useDispatch, useSelector } from 'react-redux'; |
3 | | -import { Link, Redirect } from 'react-router-dom'; |
| 3 | +import { Link, Redirect, useHistory } from 'react-router-dom'; |
4 | 4 | import styled from 'styled-components'; |
5 | 5 | import { Editor } from '@toast-ui/react-editor'; |
6 | 6 | 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'; |
8 | 8 | import { Title } from 'app/Title/Title'; |
9 | 9 | import { Paper } from 'components/layout/Paper'; |
10 | 10 | import { addQuestion } from 'features/questions/questionsSlice'; |
@@ -93,6 +93,7 @@ CancelLinkLabel.propTypes = { |
93 | 93 |
|
94 | 94 | const CreateQuestion = () => { |
95 | 95 | const dispatch = useDispatch(); |
| 96 | + const history = useHistory(); |
96 | 97 | const editorRef = useRef(); |
97 | 98 |
|
98 | 99 | const profile = useSelector(selectProfile); |
@@ -141,10 +142,17 @@ const CreateQuestion = () => { |
141 | 142 | tags, |
142 | 143 | userId: profile._id, |
143 | 144 | }) |
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 | + }); |
148 | 156 | }; |
149 | 157 |
|
150 | 158 | const handleChange = () => { |
|
0 commit comments