1
- /* eslint-disable */
2
1
import React , { useState , useEffect } from "react" ;
3
2
import styled from "styled-components" ;
4
3
import StarRating from "./StarRating" ;
5
4
import { useReviewInfo } from "../../contexts/useReviewInfo" ;
6
5
7
6
const ReviewForm = ( { onClose, initialData } ) => {
8
- const [ review , setReview ] = useState ( initialData || { } ) ;
7
+ const isEditing = initialData ;
8
+ const [ reviewId , setReviewId ] = useState ( Date . now ( ) ) ;
9
9
const [ starPoint , setStarPoint ] = useState ( 0 ) ;
10
10
const [ content , setContent ] = useState ( "" ) ;
11
11
const [ reviewCount , setReviewCount ] = useState ( 1 ) ;
12
12
const [ reviewDate , setReviewDate ] = useState ( new Date ( ) ) ;
13
13
const [ selectedStore , setSelectedStore ] = useState ( "" ) ;
14
14
const [ selectedAlba , setSelectedAlba ] = useState ( "" ) ;
15
15
const [ selectedTag , setSelectedTag ] = useState ( [ ] ) ;
16
- const [ reviewTag , setReviewTag ] = useState ( [
16
+ const [ reviewTag ] = useState ( [
17
17
"일을 잘해요" ,
18
18
"시간 엄수를 잘해요" ,
19
19
"일이 서툴러요" ,
@@ -35,7 +35,7 @@ const ReviewForm = ({ onClose, initialData }) => {
35
35
36
36
useEffect ( ( ) => {
37
37
if ( initialData ) {
38
- setReview ( initialData ) ;
38
+ setReviewId ( initialData . id || Date . now ( ) ) ;
39
39
setStarPoint ( initialData . starPoint || 0 ) ;
40
40
setContent ( initialData . content || "" ) ;
41
41
setReviewCount ( initialData . reviewCount || 1 ) ;
@@ -48,7 +48,7 @@ const ReviewForm = ({ onClose, initialData }) => {
48
48
49
49
const handleSubmit = ( ) => {
50
50
const newReview = {
51
- id : Date . now ( ) ,
51
+ id : reviewId ,
52
52
storeID : selectedStore ,
53
53
albaID : selectedAlba ,
54
54
starPoint : starPoint ,
@@ -58,8 +58,20 @@ const ReviewForm = ({ onClose, initialData }) => {
58
58
tags : selectedTag ,
59
59
} ;
60
60
61
+ if ( ! selectedStore || ! selectedAlba || ! starPoint || ! content ) {
62
+ let missingFields = [ ] ;
63
+
64
+ if ( ! selectedStore ) missingFields . push ( "가게" ) ;
65
+ if ( ! selectedAlba ) missingFields . push ( "알바생" ) ;
66
+ if ( ! starPoint ) missingFields . push ( "평점" ) ;
67
+ if ( ! content ) missingFields . push ( "한줄평" ) ;
68
+
69
+ alert ( `${ missingFields . join ( ", " ) } 을(를) 입력해 주세요.` ) ;
70
+ return ; // 입력 받지 않은 항목에 대해 alert 메시지
71
+ }
72
+
61
73
if ( initialData ) {
62
- editReview ( newReview ) ; // 수정 시 editReview 사용(아직 수정 기능 미구현)
74
+ editReview ( newReview ) ;
63
75
} else {
64
76
addReview ( newReview ) ;
65
77
}
@@ -91,7 +103,9 @@ const ReviewForm = ({ onClose, initialData }) => {
91
103
< FieldContainer >
92
104
< Field >
93
105
< Label > 가게</ Label >
94
- < Select value = { selectedStore } onChange = { handleStoreChange } >
106
+ < Select value = { selectedStore }
107
+ onChange = { handleStoreChange }
108
+ disabled = { isEditing } >
95
109
< option value = "" disabled >
96
110
선택하세요
97
111
</ option >
@@ -108,7 +122,7 @@ const ReviewForm = ({ onClose, initialData }) => {
108
122
< Select
109
123
value = { selectedAlba }
110
124
onChange = { ( e ) => setSelectedAlba ( e . target . value ) }
111
- disabled = { ! selectedStore }
125
+ disabled = { ! selectedStore || isEditing }
112
126
>
113
127
< option value = "" disabled >
114
128
선택하세요
0 commit comments