1- import { useState } from 'react' ;
1+ import { useState , useEffect } from 'react' ;
22import { FunnelState } from '../model/FunnelContext' ;
33import AddButton from '../../../../public/assets/event-manage/creation/AddBtn.svg' ;
44import CloseButton from '../../../../public/assets/event-manage/creation/CloseBtn.svg' ;
@@ -14,9 +14,10 @@ interface LinkInputProps {
1414 onChange ?: ( value : Link [ ] ) => void ;
1515 eventState ?: FunnelState [ 'eventState' ] ;
1616 setEventState ?: React . Dispatch < React . SetStateAction < FunnelState [ 'eventState' ] > > ;
17+ onValidationChange ?: ( isValid : boolean ) => void ;
1718}
1819
19- const LinkInput = ( { value, onChange, eventState, setEventState } : LinkInputProps ) => {
20+ const LinkInput = ( { value, onChange, eventState, setEventState, onValidationChange } : LinkInputProps ) => {
2021 const links = value ?? eventState ?. referenceLinks ?? [ ] ;
2122
2223 const [ activeInput , setActiveInput ] = useState < { field : 'title' | 'url' | null } > ( {
@@ -26,6 +27,11 @@ const LinkInput = ({ value, onChange, eventState, setEventState }: LinkInputProp
2627 field : null ,
2728 } ) ;
2829
30+ const validateLinks = ( linkArray : Link [ ] ) => {
31+ if ( linkArray . length === 0 ) return true ;
32+ return linkArray . every ( link => link . title . trim ( ) !== '' && link . url . trim ( ) !== '' ) ;
33+ } ;
34+
2935 const updateAll = ( newLinks : Link [ ] ) => {
3036 onChange ?.( newLinks ) ;
3137 setEventState ?.( prev => ( { ...prev , referenceLinks : newLinks } ) ) ;
@@ -44,9 +50,20 @@ const LinkInput = ({ value, onChange, eventState, setEventState }: LinkInputProp
4450 updateAll ( newLinks ) ;
4551 } ;
4652
53+ useEffect ( ( ) => {
54+ const isValid = validateLinks ( links ) ;
55+ onValidationChange ?.( isValid ) ;
56+ } , [ links , onValidationChange ] ) ;
57+
4758 return (
4859 < div className = "flex flex-col gap-1" >
49- < h1 className = "font-bold text-black text-lg" > 관련 링크</ h1 >
60+ < div className = "flex flex-row gap-2 items-center" >
61+ < h1 className = "font-bold text-black text-lg" > 관련 링크</ h1 >
62+ { links . length > 0 && ( < p className = "text-placeholderText text-12" >
63+ 링크 추가 시 하이퍼링크와 URL을 모두 입력해주세요
64+ </ p > ) }
65+
66+ </ div >
5067
5168 { links . map ( ( link , index ) => (
5269 < div key = { index } className = "mb-2" >
@@ -64,7 +81,7 @@ const LinkInput = ({ value, onChange, eventState, setEventState }: LinkInputProp
6481 value = { link . title }
6582 onChange = { e => updateLink ( index , 'title' , e . target . value ) }
6683 className = "w-full min-w-[3rem] md:min-w-[6rem] h-8 text-placeholderText ml-1 outline-none bg-transparent text-sm md:text-base"
67- placeholder = "참조링크 "
84+ placeholder = "하이퍼링크 "
6885 autoFocus = { activeInput . field === link . title && activeInput . field === 'title' }
6986 />
7087 </ div >
0 commit comments