@@ -47,7 +47,7 @@ type DiaryRegisterReqWithCats = Omit<DiaryRegisterReqObj, 'taggedCats'> & {
4747
4848interface DiaryWriteModalProps {
4949 onClose : ( ) => void ;
50- id : number ;
50+ id ? : number ;
5151 diaryDetail ?: DiaryRegisterReqWithCats ;
5252}
5353
@@ -97,7 +97,8 @@ const DiaryWriteModal = ({
9797 setValue,
9898 formState : { errors, isSubmitting } ,
9999 handleSubmit,
100- reset
100+ reset,
101+ trigger
101102 } = form ;
102103
103104 const watchedData = watch ( ) ;
@@ -177,21 +178,29 @@ const DiaryWriteModal = ({
177178
178179 const formattedDate = formatDateToISO ( data . caredDate ) ;
179180
181+ const catIds = data . taggedCats . map ( cat => Number ( cat . id ) ) ;
182+
180183 return {
181184 isGivenWater : data . isGivenWater ,
182185 isFeed : data . isFeed ,
183186 content : data . content ,
184187 caredDate : formattedDate ,
185188 caredTime : displayTime ( ) ,
186- taggedCats : data . taggedCats . map ( cat => Number ( cat . id ) ) ,
189+ catIds : catIds ,
187190 images : processedImages
188191 } ;
189192 } ;
190193
191194 const onSubmit = ( data : DiaryFormData ) => {
192195 if ( isSubmitting ) return ;
193196
194- // 내용이 없을 때 알림
197+ if ( ! data . taggedCats || data . taggedCats . length === 0 ) {
198+ toast ( {
199+ description : '고양이를 선택해주세요'
200+ } ) ;
201+ return ;
202+ }
203+
195204 if ( ! data . content . trim ( ) ) {
196205 toast ( {
197206 description : '간단한 돌봄 기록이라도 남겨보세요!'
@@ -215,9 +224,7 @@ const DiaryWriteModal = ({
215224 const onError = ( errors : any ) => {
216225 if ( errors . taggedCats ) {
217226 toast ( {
218- title : '고양이 선택 필요' ,
219- description :
220- errors . taggedCats . message || '고양이를 최소 1마리 이상 선택해주세요.'
227+ description : '고양이를 선택해주세요'
221228 } ) ;
222229 } else if ( errors . images ) {
223230 toast ( {
@@ -255,6 +262,9 @@ const DiaryWriteModal = ({
255262 editDiaryOnServer ( reqObj ) ,
256263 onSuccess : ( ) => {
257264 queryClient . invalidateQueries ( { queryKey : [ 'diaryDetail' ] } ) ;
265+ toast ( {
266+ description : '일지가 성공적으로 수정되었습니다.'
267+ } ) ;
258268 onClose ( ) ;
259269 } ,
260270 onError : error => {
@@ -295,14 +305,23 @@ const DiaryWriteModal = ({
295305 }
296306 } ;
297307
298- const handleAddCats = (
308+ const handleAddCats = async (
299309 cats : CatType [ ] | ( ( prev : CatType [ ] ) => CatType [ ] )
300310 ) => {
311+ let newCats : CatType [ ] ;
312+
301313 if ( typeof cats === 'function' ) {
302- setValue ( 'taggedCats' , cats ( taggedCats ) ) ;
314+ newCats = cats ( taggedCats ) ;
303315 } else {
304- setValue ( 'taggedCats' , cats ) ;
316+ newCats = cats ;
305317 }
318+
319+ setValue ( 'taggedCats' , newCats , {
320+ shouldValidate : true ,
321+ shouldDirty : true
322+ } ) ;
323+
324+ await trigger ( 'taggedCats' ) ;
306325 } ;
307326
308327 const chipObjList = [
@@ -312,7 +331,7 @@ const DiaryWriteModal = ({
312331
313332 return (
314333 < >
315- < div className = "h-screen w- full max-w-[640px] overflow-y-auto" >
334+ < div className = "h-full w-full overflow-y-auto" >
316335 < Topbar type = "three" >
317336 < Topbar . Back onClick = { onClose } />
318337 < Topbar . Title title = "일지쓰기" />
0 commit comments