-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| import ReactMarkdown from 'react-markdown'; | ||
| import remarkGfm from 'remark-gfm'; | ||
| import DeleteModal from '@/assets/components/modal/DeleteModal'; | ||
|
|
||
| interface PostDetailType { | ||
| id: number; | ||
|
|
@@ -61,6 +62,8 @@ | |
| const [comments, setComments] = useState<CommentType[]>([]); | ||
| const [isCommentLoading, setIsCommentLoading] = useState(false); | ||
|
|
||
| const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||
|
|
||
| const calculateTimeAgo = (createdAt: string) => { | ||
| const now = new Date(); | ||
| const created = new Date(createdAt); | ||
|
|
@@ -93,7 +96,7 @@ | |
| }; | ||
|
|
||
| fetchPostDetail(); | ||
| }, [postId]); | ||
|
|
||
| const handleLikeToggle = async () => { | ||
| if (!postId || !postData || isLikeLoading) return; | ||
|
|
@@ -186,23 +189,30 @@ | |
| const handleAdminDelete = async () => { | ||
| if (!postId) return; | ||
|
|
||
| const confirmDelete = window.confirm('κ²μκΈμ μμ νμκ² μ΅λκΉ?'); | ||
| if (!confirmDelete) return; | ||
|
|
||
| try { | ||
| await instance.delete(`/api/admin/post/${postId}`); | ||
|
|
||
| toast.success('κ²μκΈμ΄ μμ λμμ΅λλ€.'); | ||
| navigate(-1); | ||
| } catch (error: unknown) { | ||
| if (typeof error === 'object' && error !== null && 'response' in error) { | ||
| const status = (error as { response?: { status?: number } }).response | ||
| ?.status; | ||
|
|
||
| if (status === 401) toast.error('λ‘κ·ΈμΈμ΄ νμν©λλ€.'); | ||
| else if (status === 403) toast.error('κ΄λ¦¬μ κΆνμ΄ μμ΅λλ€.'); | ||
| else if (status === 404) toast.error('κ²μκΈμ μ°Ύμ μ μμ΅λλ€.'); | ||
| else toast.error('κ²μκΈ μμ μ μ€ν¨νμ΅λλ€.'); | ||
| if (status === 401) { | ||
| toast.error('λ‘κ·ΈμΈμ΄ νμν©λλ€.'); | ||
| } else if (status === 403) { | ||
| toast.error('κ΄λ¦¬μ κΆνμ΄ μμ΅λλ€.'); | ||
| } else if (status === 404) { | ||
| toast.error('κ²μκΈμ μ°Ύμ μ μμ΅λλ€.'); | ||
| } else { | ||
| toast.error('κ²μκΈ μμ μ μ€ν¨νμ΅λλ€.'); | ||
| } | ||
| } else { | ||
| toast.error('μλ²μ ν΅μ ν μ μμ΅λλ€.'); | ||
| } | ||
| } finally { | ||
| setIsDeleteModalOpen(false); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -231,29 +241,6 @@ | |
| } | ||
| }; | ||
|
|
||
| const isAdmin = () => { | ||
| try { | ||
| const token = localStorage.getItem('accessToken'); | ||
| if (!token) return false; | ||
|
|
||
| const payload = JSON.parse(atob(token.split('.')[1])); | ||
|
|
||
| console.log('JWT payload:', payload); | ||
|
|
||
| return ( | ||
| payload.role === 'ADMIN' || | ||
| payload.role === 'ROLE_ADMIN' || | ||
| payload.auth === 'ROLE_ADMIN' || | ||
| payload.authority === 'ADMIN' || | ||
| payload.roles?.includes('ADMIN') || | ||
| payload.roles?.includes('ROLE_ADMIN') | ||
| ); | ||
| } catch (e) { | ||
| console.error('isAdmin error', e); | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| if (isLoading || !postData) { | ||
| return ( | ||
| <> | ||
|
|
@@ -363,11 +350,12 @@ | |
| <Report /> | ||
| </button> | ||
|
|
||
| {isAdmin() && ( | ||
| <button onClick={handleAdminDelete} className="cursor-pointer"> | ||
| <Delete /> | ||
| </button> | ||
| )} | ||
| <button | ||
| onClick={() => setIsDeleteModalOpen(true)} | ||
| className="cursor-pointer" | ||
| > | ||
| <Delete /> | ||
| </button> | ||
|
Comment on lines
+353
to
+358
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ΄λ¦¬μ μ¬λΆλ₯Ό νμΈνλ μ‘°κ±΄λΆ λ λλ§μ΄ μ κ±°λμ΄ λͺ¨λ μ¬μ©μμκ² μμ λ²νΌμ΄ νμλ©λλ€. μ΄λ κ΄λ¦¬μκ° μλ μ¬μ©μμκ² νΌλμ μ€ μ μμΌλ©°, μμ μλλ₯Ό ν νμμΌ κΆν μμ μ€λ₯λ₯Ό λ³΄κ² λμ΄ μ¬μ©μ κ²½νμ μ ν΄ν©λλ€. μ΄μ μ²λΌ κ΄λ¦¬μμκ²λ§ μμ λ²νΌμ΄ 보μ΄λλ‘ μ‘°κ±΄λΆ λ λλ§μ λ€μ μΆκ°νλ κ²μ κ³ λ €ν΄ λ³΄μΈμ. μ¬μ©μ κΆνμ νμΈνλ λ‘μ§(μ: μ¬μ©μ μ 보λ₯Ό λ΄κ³ μλ contextλ store μ¬μ©)μ μ¬μ©νμ¬ λ²νΌμ λ ΈμΆ μ¬λΆλ₯Ό κ²°μ ν΄μΌ ν©λλ€. |
||
| </div> | ||
| </div> | ||
|
|
||
|
|
@@ -413,6 +401,13 @@ | |
| onReport={() => setIsModalOpen(false)} | ||
| /> | ||
| )} | ||
|
|
||
| {isDeleteModalOpen && ( | ||
| <DeleteModal | ||
| onClose={() => setIsDeleteModalOpen(false)} | ||
| onDelete={handleAdminDelete} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
axiosμΈν°μ ν°μμ ν ν° κ°±μ μ€ν¨ μTokenRefreshErrorλ₯Ό λ°μμν€λλ‘ κ΅¬νλμ΄ μμ΅λλ€. νμ¬catchλΈλ‘μμλ μ΄ νΉμ μ€λ₯λ₯Ό μ²λ¦¬νμ§ μκ³ μΌλ°μ μΈ μλ² ν΅μ μ€λ₯λ‘ μ²λ¦¬νκ³ μμ΅λλ€. ν ν° κ°±μ μ€ν¨λ μ¬μ©μκ° λ€μ λ‘κ·ΈμΈν΄μΌ νλ μ€μν μν©μ΄λ―λ‘,TokenRefreshErrorλ₯Ό λͺ μμ μΌλ‘ νμΈνμ¬ μ¬μ©μμκ² μ¬λ‘κ·ΈμΈμ΄ νμν¨μ μλ¦¬κ³ λ‘κ·ΈμΈ νμ΄μ§λ‘ 리λλ μ νλ λ±μ μ²λ¦¬λ₯Ό μΆκ°νλ κ²μ΄ μ’μ΅λλ€.TokenRefreshErrorλ₯Ό μ¬μ©νλ €λ©΄ νμΌ μλ¨μμ importν΄μΌ ν©λλ€:References