@@ -56,13 +56,40 @@ export function MorningMeetingForm({
5656 return entry . replace ( / < i m g [ ^ > ] * s r c = [ " ' ] i m a g e - r e f : \/ \/ [ ^ " ' ] * [ " ' ] [ ^ > ] * > / gi, '' ) ;
5757 } ;
5858
59+ // Format date to YYYY-MM-DD for input field
60+ const formatDateForInput = ( dateValue : any ) : string => {
61+ if ( ! dateValue ) return new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
62+
63+ if ( typeof dateValue === 'string' ) {
64+ // If it's already in YYYY-MM-DD format, return it
65+ if ( dateValue . match ( / ^ \d { 4 } - \d { 2 } - \d { 2 } $ / ) ) {
66+ return dateValue ;
67+ }
68+ // If it's ISO format (with time), extract just the date part
69+ if ( dateValue . includes ( 'T' ) ) {
70+ return dateValue . split ( 'T' ) [ 0 ] ;
71+ }
72+ // Try to parse and reformat
73+ const parsed = new Date ( dateValue ) ;
74+ if ( ! isNaN ( parsed . getTime ( ) ) ) {
75+ return parsed . toISOString ( ) . split ( 'T' ) [ 0 ] ;
76+ }
77+ }
78+
79+ if ( dateValue instanceof Date ) {
80+ return dateValue . toISOString ( ) . split ( 'T' ) [ 0 ] ;
81+ }
82+
83+ return new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
84+ } ;
85+
5986 const [ formData , setFormData ] = useState < MorningMeetingEntry > ( {
6087 category : initialData ?. category || '' ,
6188 priority : initialData ?. priority || 'situational-awareness' ,
6289 region : initialData ?. region || '' ,
6390 country : initialData ?. country || '' ,
6491 headline : initialData ?. headline || '' ,
65- date : initialData ?. date || new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
92+ date : formatDateForInput ( initialData ?. date ) ,
6693 entry : cleanEntry ( initialData ?. entry || '' ) ,
6794 sourceUrl : initialData ?. sourceUrl || '' ,
6895 puNote : initialData ?. puNote || '' ,
@@ -75,14 +102,36 @@ export function MorningMeetingForm({
75102 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
76103 const [ availableCountries , setAvailableCountries ] = useState < string [ ] > ( [ ] ) ;
77104
105+ // Initialize available countries from initialData region on mount
106+ useEffect ( ( ) => {
107+ if ( initialData ?. region && COUNTRIES_BY_REGION [ initialData . region ] ) {
108+ const countries = COUNTRIES_BY_REGION [ initialData . region ] ;
109+ // Ensure existing country is included even if not in the region list
110+ if ( initialData ?. country && ! countries . includes ( initialData . country ) ) {
111+ setAvailableCountries ( [ initialData . country , ...countries ] ) ;
112+ } else {
113+ setAvailableCountries ( countries ) ;
114+ }
115+ }
116+ } , [ initialData ?. region , initialData ?. country ] ) ;
117+
78118 // Update available countries when region changes
79119 useEffect ( ( ) => {
80120 if ( formData . region && COUNTRIES_BY_REGION [ formData . region ] ) {
81- setAvailableCountries ( COUNTRIES_BY_REGION [ formData . region ] ) ;
121+ const countries = COUNTRIES_BY_REGION [ formData . region ] ;
122+ // Ensure existing country is included
123+ if ( formData . country && ! countries . includes ( formData . country ) ) {
124+ setAvailableCountries ( [ formData . country , ...countries ] ) ;
125+ } else {
126+ setAvailableCountries ( countries ) ;
127+ }
128+ } else if ( formData . country ) {
129+ // If no region selected but country exists, still show it
130+ setAvailableCountries ( [ formData . country ] ) ;
82131 } else {
83132 setAvailableCountries ( [ ] ) ;
84133 }
85- } , [ formData . region ] ) ;
134+ } , [ formData . region , formData . country ] ) ;
86135
87136 // Update country if it's not available in the new region
88137 useEffect ( ( ) => {
@@ -288,12 +337,9 @@ export function MorningMeetingForm({
288337 < Card className = "rounded-t-none" >
289338 < CardContent className = "pt-6" >
290339 < form onSubmit = { handleSubmit } className = "space-y-6" >
291- { /* Classification Section */ }
340+ { /* Classification & Location Section */ }
292341 < section className = "space-y-4 border-b pb-6" >
293- < h2 className = "text-xs font-semibold uppercase tracking-wider text-slate-700" >
294- Classification
295- </ h2 >
296- < div className = "grid gap-4 md:grid-cols-2" >
342+ < div className = "grid gap-4 md:grid-cols-4" >
297343 { /* Category */ }
298344 < div className = "space-y-2" >
299345 < label className = "text-sm font-medium text-slate-700" >
@@ -355,15 +401,7 @@ export function MorningMeetingForm({
355401 </ div >
356402 ) }
357403 </ div >
358- </ div >
359- </ section >
360404
361- { /* Location Section */ }
362- < section className = "space-y-4 border-b pb-6" >
363- < h2 className = "text-xs font-semibold uppercase tracking-wider text-slate-700" >
364- Location
365- </ h2 >
366- < div className = "grid gap-4 md:grid-cols-2" >
367405 { /* Region */ }
368406 < div className = "space-y-2" >
369407 < label className = "text-sm font-medium text-slate-700" >
@@ -402,11 +440,11 @@ export function MorningMeetingForm({
402440 < Select
403441 value = { formData . country }
404442 onValueChange = { ( value ) => handleSelectChange ( 'country' , value ) }
405- disabled = { availableCountries . length === 0 }
443+ disabled = { availableCountries . length === 0 && ! formData . country }
406444 >
407445 < SelectTrigger
408446 className = {
409- availableCountries . length === 0
447+ availableCountries . length === 0 && ! formData . country
410448 ? 'opacity-50'
411449 : errors . country
412450 ? 'border-red-500 bg-red-50'
@@ -416,7 +454,7 @@ export function MorningMeetingForm({
416454 < SelectValue placeholder = "Select country..." />
417455 </ SelectTrigger >
418456 < SelectContent >
419- { availableCountries . length === 0 ? (
457+ { availableCountries . length === 0 && ! formData . country ? (
420458 < div className = "p-2 text-sm text-slate-500" > Select region first</ div >
421459 ) : (
422460 availableCountries . map ( ( country ) => (
0 commit comments