11import  {  AddIcon ,  DeleteIcon  }  from  'app/FeatherIcons' 
22import  formStyles  from  'app/Form.module.css' 
3+ import  {  SessionName  }  from  'app/SessionName' 
34import  tableStyles  from  'app/Table.module.css' 
45import  {  formatEventTime ,  toEventTime  }  from  'app/time' 
56import  {  useRef ,  useState  }  from  'react' 
@@ -8,6 +9,7 @@ type AddSession = {
89	name : string 
910	hour : string 
1011	minute : string 
12+ 	url : string 
1113} 
1214
1315const  toNumber  =  ( n : string )  =>  { 
@@ -18,6 +20,9 @@ const toNumber = (n: string) => {
1820	} 
1921} 
2022
23+ const  urlRegex  = 
24+ 	/ ^ h t t p s ? : \/ \/ ( w w w \. ) ? [ - a - z A - Z 0 - 9 @ : % . _ + ~ # = ] { 1 , 256 } \. [ a - z A - Z 0 - 9 ( ) ] { 1 , 6 } \b ( [ - a - z A - Z 0 - 9 ( ) @ : % _ + . ~ # ? & / / = ] * ) $ / 
25+ 
2126export  const  Editor  =  ( { 
2227	conferenceDate, 
2328	sessions, 
@@ -34,19 +39,22 @@ export const Editor = ({
3439		name : '' , 
3540		hour : '19' , 
3641		minute : '45' , 
42+ 		url : '' , 
3743	} ) 
3844	const  inputRef  =  useRef < HTMLInputElement > ( null ) 
3945	const  isInputValid  =  ( )  =>  { 
4046		const  hour  =  toNumber ( add . hour ) 
4147		const  minute  =  toNumber ( add . minute ) 
48+ 		const  urlIsValid  =  add . url  !==  ''  ? urlRegex . test ( add . url )  : true 
4249		return  ( 
4350			add . name . length  >  0  && 
4451			hour  !==  null  && 
4552			hour  >=  0  && 
4653			hour  <=  23  && 
4754			minute  !==  null  && 
4855			minute  >=  0  && 
49- 			minute  <=  59 
56+ 			minute  <=  59  && 
57+ 			urlIsValid 
5058		) 
5159	} 
5260
@@ -58,6 +66,7 @@ export const Editor = ({
5866		updateAdd ( { 
5967			...add , 
6068			name : '' , 
69+ 			url : '' , 
6170		} ) 
6271		inputRef . current ?. focus ( ) 
6372	} 
@@ -114,25 +123,58 @@ export const Editor = ({
114123							/> 
115124						</ td > 
116125						< td > 
117- 							< input 
118- 								className = { formStyles . Input } 
119- 								type = "text" 
120- 								value = { add . name } 
121- 								onKeyUp = { ( {  key } )  =>  { 
122- 									if  ( key  ===  'Enter' )  { 
123- 										if  ( isInputValid ( ) )  { 
124- 											addAction ( add ) 
125- 											onAdd ( add ) 
126+ 							< form  className = { formStyles . Form } > 
127+ 								< fieldset > 
128+ 									< label  htmlFor = "name" > Session name</ label > 
129+ 									< input 
130+ 										className = { formStyles . TextInput } 
131+ 										type = "text" 
132+ 										value = { add . name } 
133+ 										id = { 'name' } 
134+ 										onKeyUp = { ( {  key } )  =>  { 
135+ 											if  ( key  ===  'Enter' )  { 
136+ 												if  ( isInputValid ( ) )  { 
137+ 													addAction ( add ) 
138+ 													onAdd ( add ) 
139+ 												} 
140+ 											} 
141+ 										} } 
142+ 										onChange = { ( {  target : {  value }  } )  => 
143+ 											updateAdd ( { 
144+ 												...add , 
145+ 												name : value , 
146+ 											} ) 
126147										} 
127- 									} 
128- 								} } 
129- 								onChange = { ( {  target : {  value }  } )  => 
130- 									updateAdd ( { 
131- 										...add , 
132- 										name : value , 
133- 									} ) 
134- 								} 
135- 							/> 
148+ 										placeholder = 'e.g. "Intro Session"' 
149+ 									/> 
150+ 								</ fieldset > 
151+ 								< fieldset > 
152+ 									< label  htmlFor = "url" > 
153+ 										Optional: URL to use as a hyperlink.
154+ 									</ label > 
155+ 									< input 
156+ 										className = { formStyles . TextInput } 
157+ 										type = "url" 
158+ 										id = "url" 
159+ 										value = { add . url  ??  '' } 
160+ 										onChange = { ( {  target : {  value }  } )  => 
161+ 											updateAdd ( { 
162+ 												...add , 
163+ 												url : value , 
164+ 											} ) 
165+ 										} 
166+ 										onKeyUp = { ( {  key } )  =>  { 
167+ 											if  ( key  ===  'Enter' )  { 
168+ 												if  ( isInputValid ( ) )  { 
169+ 													addAction ( add ) 
170+ 													onAdd ( add ) 
171+ 												} 
172+ 											} 
173+ 										} } 
174+ 										placeholder = 'e.g. "https://example.com/"' 
175+ 									/> 
176+ 								</ fieldset > 
177+ 							</ form > 
136178						</ td > 
137179					</ tr > 
138180					{ Object . entries ( sessions ) . map ( ( [ time ,  name ] )  =>  ( 
@@ -150,7 +192,9 @@ export const Editor = ({
150192							< td  className = { 'time' } > 
151193								{ formatEventTime ( eventTime ( time  as  unknown  as  number ) ) } 
152194							</ td > 
153- 							< td > { name } </ td > 
195+ 							< td > 
196+ 								< SessionName  name = { name }  /> 
197+ 							</ td > 
154198						</ tr > 
155199					) ) } 
156200				</ tbody > 
0 commit comments