1- import { FormProvider , useForm } from 'react-hook-form' ;
1+ import { FormProvider , useForm , useWatch } from 'react-hook-form' ;
22
33import Fieldset from '~/components/form/Fieldset' ;
44import Form from '~/components/form/Form' ;
@@ -13,7 +13,11 @@ export interface NoticeFormData {
1313 tags : string [ ] ;
1414 isPrivate : boolean ;
1515 isPinned : boolean ;
16+ pinnedUntil : Date | null ;
17+ hasPinnedUntilDeadline : boolean ;
1618 isImportant : boolean ;
19+ importantUntil : Date | null ;
20+ hasImportantUntilDeadline : boolean ;
1721}
1822
1923interface Props {
@@ -38,11 +42,17 @@ export default function NoticeEditor({
3842 tags : [ ] ,
3943 isPrivate : false ,
4044 isPinned : false ,
45+ pinnedUntil : null ,
4146 isImportant : false ,
47+ importantUntil : null ,
4248 } ,
4349 shouldFocusError : false ,
4450 } ) ;
4551 const { handleSubmit, setValue } = formMethods ;
52+ const [ isPinned , pinnedUntil , isImportant , importantUntil ] = useWatch ( {
53+ name : [ 'isPinned' , 'pinnedUntil' , 'isImportant' , 'importantUntil' ] ,
54+ control : formMethods . control ,
55+ } ) ;
4656
4757 return (
4858 < FormProvider { ...formMethods } >
@@ -97,15 +107,71 @@ export default function NoticeEditor({
97107 name = "isPinned"
98108 onChange = { ( isPinned ) => {
99109 if ( isPinned ) setValue ( 'isPrivate' , false ) ;
110+ setValue ( 'pinnedUntil' , null ) ;
111+ setValue ( 'hasPinnedUntilDeadline' , false ) ;
100112 } }
101113 />
114+ { isPinned && (
115+ < div className = "ml-6 flex flex-col gap-2" >
116+ < Form . Checkbox
117+ label = "만료일 설정"
118+ name = "hasPinnedUntilDeadline"
119+ onChange = { ( checked ) => {
120+ if ( checked ) {
121+ const tomorrow = new Date ( ) ;
122+ tomorrow . setDate ( tomorrow . getDate ( ) + 1 ) ;
123+ tomorrow . setHours ( 0 , 0 , 0 , 0 ) ;
124+ setValue ( 'pinnedUntil' , tomorrow ) ;
125+ } else {
126+ setValue ( 'pinnedUntil' , null ) ;
127+ }
128+ } }
129+ />
130+ { pinnedUntil && (
131+ < div className = "ml-6" >
132+ < Form . Date name = "pinnedUntil" hideTime disablePast />
133+ </ div >
134+ ) }
135+ < p className = "text-xs font-light tracking-wide text-neutral-700" >
136+ * 만료일 설정 시 해당 날짜까지만 상단에 고정됩니다.
137+ </ p >
138+ </ div >
139+ ) }
102140 < Form . Checkbox
103141 label = "메인-중요 안내에 표시"
104142 name = "isImportant"
105143 onChange = { ( isImportant ) => {
106144 if ( isImportant ) setValue ( 'isPrivate' , false ) ;
145+ setValue ( 'importantUntil' , null ) ;
146+ setValue ( 'hasImportantUntilDeadline' , false ) ;
107147 } }
108148 />
149+ { isImportant && (
150+ < div className = "ml-6 flex flex-col gap-2" >
151+ < Form . Checkbox
152+ label = "만료일 설정"
153+ name = "hasImportantUntilDeadline"
154+ onChange = { ( checked ) => {
155+ if ( checked ) {
156+ const tomorrow = new Date ( ) ;
157+ tomorrow . setDate ( tomorrow . getDate ( ) + 1 ) ;
158+ tomorrow . setHours ( 0 , 0 , 0 , 0 ) ;
159+ setValue ( 'importantUntil' , tomorrow ) ;
160+ } else {
161+ setValue ( 'importantUntil' , null ) ;
162+ }
163+ } }
164+ />
165+ { importantUntil && (
166+ < div className = "ml-6" >
167+ < Form . Date name = "importantUntil" hideTime disablePast />
168+ </ div >
169+ ) }
170+ < p className = "text-xs font-light tracking-wide text-neutral-700" >
171+ * 만료일 설정 시 해당 날짜까지만 중요 안내로 표시됩니다.
172+ </ p >
173+ </ div >
174+ ) }
109175 </ div >
110176 </ Fieldset >
111177 < Form . Action
0 commit comments