@@ -15,6 +15,10 @@ import { CATEGORY } from "../../constants";
15
15
import { usePostWritable } from "../../hooks" ;
16
16
import { PostDetailParamsProps } from "../../types/@props" ;
17
17
18
+ type PostCategoryType = {
19
+ [ key in keyof typeof CATEGORY ] ?: JSX . Element ;
20
+ } ;
21
+
18
22
const PostEditPage = ( { id } : PostDetailParamsProps ) => {
19
23
const { post } = usePostQuery ( id ) ;
20
24
const {
@@ -24,6 +28,44 @@ const PostEditPage = ({ id }: PostDetailParamsProps) => {
24
28
handlePostEditButtonClick,
25
29
handleInputPostDataChange,
26
30
} = usePostWritable ( post ) ;
31
+
32
+ const PostCategory : PostCategoryType = {
33
+ PROJECT : (
34
+ < ProjectInputBox
35
+ handleChange = { handleInputPostDataChange }
36
+ postData = { postData }
37
+ />
38
+ ) ,
39
+ CODE_REVIEW : (
40
+ < CodeReviewInputBox
41
+ handleChange = { handleInputPostDataChange }
42
+ postData = { postData }
43
+ />
44
+ ) ,
45
+ LOST : (
46
+ < LostFoundInputBox
47
+ handleChange = { handleInputPostDataChange }
48
+ handleFileSelect = { handleImageFileSelect }
49
+ postData = { postData }
50
+ lostImageUrl = { lostImageUrl }
51
+ />
52
+ ) ,
53
+ FOUND : (
54
+ < >
55
+ < LostFoundInputBox
56
+ handleChange = { handleInputPostDataChange }
57
+ handleFileSelect = { handleImageFileSelect }
58
+ postData = { postData }
59
+ lostImageUrl = { lostImageUrl }
60
+ />
61
+ < FoundInputBox
62
+ handleChange = { handleInputPostDataChange }
63
+ postData = { postData }
64
+ />
65
+ </ >
66
+ ) ,
67
+ } ;
68
+
27
69
return (
28
70
< >
29
71
< Layout >
@@ -34,33 +76,7 @@ const PostEditPage = ({ id }: PostDetailParamsProps) => {
34
76
handleChange = { handleInputPostDataChange }
35
77
postData = { postData }
36
78
/>
37
- { postData . category === CATEGORY . PROJECT && (
38
- < ProjectInputBox
39
- handleChange = { handleInputPostDataChange }
40
- postData = { postData }
41
- />
42
- ) }
43
- { postData . category === CATEGORY . CODE_REVIEW && (
44
- < CodeReviewInputBox
45
- handleChange = { handleInputPostDataChange }
46
- postData = { postData }
47
- />
48
- ) }
49
- { ( postData . category === CATEGORY . LOST ||
50
- postData . category === CATEGORY . FOUND ) && (
51
- < LostFoundInputBox
52
- handleChange = { handleInputPostDataChange }
53
- handleFileSelect = { handleImageFileSelect }
54
- postData = { postData }
55
- lostImageUrl = { lostImageUrl }
56
- />
57
- ) }
58
- { postData . category === CATEGORY . FOUND && (
59
- < FoundInputBox
60
- handleChange = { handleInputPostDataChange }
61
- postData = { postData }
62
- />
63
- ) }
79
+ { PostCategory [ postData . category ] }
64
80
< ContentInputBox
65
81
handleChange = { handleInputPostDataChange }
66
82
postData = { postData }
0 commit comments