diff --git a/src/templates/post/layouts/edit/index.tsx b/src/templates/post/layouts/edit/index.tsx index b07077ca..9d477742 100644 --- a/src/templates/post/layouts/edit/index.tsx +++ b/src/templates/post/layouts/edit/index.tsx @@ -15,6 +15,10 @@ import { CATEGORY } from "../../constants"; import { usePostWritable } from "../../hooks"; import { PostDetailParamsProps } from "../../types/@props"; +type PostCategoryType = { + [key in keyof typeof CATEGORY]?: JSX.Element; +}; + const PostEditPage = ({ id }: PostDetailParamsProps) => { const { post } = usePostQuery(id); const { @@ -24,6 +28,44 @@ const PostEditPage = ({ id }: PostDetailParamsProps) => { handlePostEditButtonClick, handleInputPostDataChange, } = usePostWritable(post); + + const PostCategory: PostCategoryType = { + PROJECT: ( + + ), + CODE_REVIEW: ( + + ), + LOST: ( + + ), + FOUND: ( + <> + + + + ), + }; + return ( <> @@ -34,33 +76,7 @@ const PostEditPage = ({ id }: PostDetailParamsProps) => { handleChange={handleInputPostDataChange} postData={postData} /> - {postData.category === CATEGORY.PROJECT && ( - - )} - {postData.category === CATEGORY.CODE_REVIEW && ( - - )} - {(postData.category === CATEGORY.LOST || - postData.category === CATEGORY.FOUND) && ( - - )} - {postData.category === CATEGORY.FOUND && ( - - )} + {PostCategory[postData.category]} { const { postData, @@ -23,6 +27,44 @@ const PostWritePage = () => { handlePostWriteButtonClick, handleInputPostDataChange, } = usePostWritable(); + + const PostCategory: PostCategoryType = { + PROJECT: ( + + ), + CODE_REVIEW: ( + + ), + LOST: ( + + ), + FOUND: ( + <> + + + + ), + }; + return ( <> @@ -37,33 +79,7 @@ const PostWritePage = () => { handleChange={handleInputPostDataChange} postData={postData} /> - {postData.category === CATEGORY.PROJECT && ( - - )} - {postData.category === CATEGORY.CODE_REVIEW && ( - - )} - {(postData.category === CATEGORY.LOST || - postData.category === CATEGORY.FOUND) && ( - - )} - {postData.category === CATEGORY.FOUND && ( - - )} + {PostCategory[postData.category]}