|
1 | 1 | import { useEffect, useState } from 'react'; |
2 | 2 | import { FieldErrors, useForm } from 'react-hook-form'; |
3 | | -import { useParams } from 'react-router-dom'; |
| 3 | +import { useNavigate, useParams } from 'react-router-dom'; |
4 | 4 |
|
5 | 5 | import { Box, useDisclosure, VStack } from '@chakra-ui/react'; |
6 | 6 |
|
7 | 7 | import { getPostDetail, getPostTags } from '@pages/post-detail/apis'; |
8 | 8 |
|
9 | 9 | import { PostTitle, PostTag, PostContent, PostButtons, Form } from '@shared/components'; |
| 10 | +import { RouterPath } from '@shared/constants'; |
10 | 11 | import { useCustomToast } from '@shared/hooks'; |
11 | 12 | import { PostFormData } from '@shared/types'; |
12 | 13 |
|
13 | 14 | import { PostModal } from '@widgets/modals'; |
14 | | -import { LoadingView } from '@widgets/view'; |
15 | 15 |
|
16 | 16 | import { updatePost, updatePostTags } from '../apis'; |
| 17 | +import { SkeletonPostEditPage } from './SkeletonPostEditPage'; |
17 | 18 | import { useQuery } from '@tanstack/react-query'; |
18 | 19 |
|
19 | 20 | export const PostEditPage = () => { |
20 | 21 | const { isOpen, onOpen, onClose } = useDisclosure(); |
21 | 22 | const { postId } = useParams<{ postId: string }>(); |
22 | 23 | const customToast = useCustomToast(); |
23 | 24 | const [hasErrorToastShown, setHasErrorToastShown] = useState(false); |
| 25 | + const navigate = useNavigate(); |
24 | 26 |
|
25 | 27 | const { |
26 | 28 | data: postDetail, |
@@ -80,28 +82,21 @@ export const PostEditPage = () => { |
80 | 82 | const onUpdatePostButton = async (modalData: { thumbnail: string; summary: string }) => { |
81 | 83 | try { |
82 | 84 | const data = form.getValues(); |
83 | | - console.log('게시글 데이터 제출:', data); |
84 | | - |
85 | | - const updatedPost = await updatePost(Number(postId), { |
| 85 | + await updatePost(Number(postId), { |
86 | 86 | title: data.title, |
87 | 87 | contents: data.content, |
88 | 88 | thumbnail: modalData.thumbnail, |
89 | 89 | summary: modalData.summary, |
90 | 90 | }); |
91 | | - |
92 | | - console.log('게시글 수정 성공:', updatedPost); |
93 | | - |
94 | 91 | if (data.tag !== null && data.tag !== undefined) { |
95 | 92 | await updatePostTags(Number(postId), data.tag); |
96 | 93 | } |
97 | | - |
98 | 94 | customToast({ |
99 | 95 | toastStatus: 'success', |
100 | 96 | toastTitle: '게시글 수정 완료', |
101 | 97 | toastDescription: '게시글이 성공적으로 수정되었습니다!', |
102 | 98 | }); |
103 | | - |
104 | | - onClose(); |
| 99 | + navigate(RouterPath.MAIN); |
105 | 100 | } catch (error) { |
106 | 101 | console.error('게시글 수정 실패:', error); |
107 | 102 | customToast({ |
@@ -134,7 +129,7 @@ export const PostEditPage = () => { |
134 | 129 | } |
135 | 130 | }; |
136 | 131 |
|
137 | | - if (isPostLoading || isTagsLoading) return <LoadingView />; |
| 132 | + if (isPostLoading || isTagsLoading) return <SkeletonPostEditPage />; |
138 | 133 | if (!postDetail || !postTag) return <Box>데이터를 불러올 수 없습니다.</Box>; |
139 | 134 |
|
140 | 135 | return ( |
|
0 commit comments