@@ -5,50 +5,52 @@ import { saveMissingSummary } from '../utils/saveMissingSummaries';
55function formatDate ( dateString : any ) {
66 const options = { year : 'numeric' , month : 'long' , day : 'numeric' } ;
77 const date = new Date ( dateString ) ;
8- // Manually construct the date string to ensure it's in "DD MMMM YYYY" format
98 const formattedDate = `${ date . getDate ( ) } ${ date . toLocaleString ( 'en-US' , { month : 'long' } ) } ${ date . getFullYear ( ) } ` ;
109 return formattedDate ;
11- }
10+ }
1211
13- const SubmitMissingSummary = ( { workgroups, allSummaries } : any ) => {
12+ const SubmitMissingSummary = ( { workgroups, allSummaries, allArchivedSummaries } : any ) => {
1413 const [ selectedWorkgroup , setSelectedWorkgroup ] = useState < { workgroup : string ; workgroup_id : string ; } | null > ( null ) ;
1514 const [ meetingDate , setMeetingDate ] = useState ( '' ) ;
1615
17- //console.log("allSummaries", allSummaries)
1816 const handleSubmit = async ( e : any ) => {
1917 e . preventDefault ( ) ;
2018 if ( selectedWorkgroup && meetingDate ) {
2119 const missingSummaryData = {
2220 workgroup : selectedWorkgroup . workgroup ,
2321 workgroupId : selectedWorkgroup . workgroup_id ,
24- meetingDate : formatDate ( meetingDate ) , // Assuming you want the formatted date here
22+ meetingDate : formatDate ( meetingDate ) ,
2523 status : "Missing" ,
2624 type : "weekly"
2725 } ;
26+
27+ // Combine allSummaries and allArchivedSummaries, considering all as "Done" for conflict checking
28+ const combinedSummaries = [ ...allSummaries , ...allArchivedSummaries . map ( ( summary : any ) => ( { ...summary , status : "Done" } ) ) ] ;
29+
2830 const newRow = {
2931 meetingDate : formatDate ( meetingDate ) ,
3032 workgroup : selectedWorkgroup . workgroup ,
3133 status : "Missing"
3234 } ;
3335
34- const conflictSummary = allSummaries . find ( ( summary : any ) =>
36+ const conflictSummary = combinedSummaries . find ( ( summary : any ) =>
3537 summary . meetingDate === newRow . meetingDate && summary . workgroup === newRow . workgroup
3638 ) ;
3739
38- // If a "Done" summary exists for the same meetingDate and workgroup, alert the user
39- if ( conflictSummary && conflictSummary . status === "Done" ) {
40- alert ( " This meeting is already marked as Done." ) ;
40+ // If a summary exists for the same meetingDate and workgroup, alert the user
41+ if ( conflictSummary ) {
42+ alert ( ` This meeting is already marked as ${ conflictSummary . status } .` ) ;
4143 return ; // Prevent the submission
4244 }
4345
44- const summariesToUpdate = newRow ? [ ...allSummaries , newRow ] : allSummaries ;
46+ const summariesToUpdate = [ ...combinedSummaries , newRow ] ;
4547
4648 try {
47- // First, save the missing summary through your existing utility function
49+ // Save the missing summary
4850 const saveResponse = await saveMissingSummary ( missingSummaryData ) ;
4951 console . log ( 'Save missing summary response:' , saveResponse ) ;
5052
51- // If the save operation is successful, then update the CSV in GitHub
53+ // Update the CSV in GitHub
5254 const response = await fetch ( '/api/updateCSV' , {
5355 method : 'POST' ,
5456 headers : { 'Content-Type' : 'application/json' } ,
@@ -67,15 +69,13 @@ const SubmitMissingSummary = ({ workgroups, allSummaries }: any) => {
6769 const responseData = await response . json ( ) ;
6870 console . log ( 'CSV updated successfully:' , responseData ) ;
6971
70- // Reset form state here
7172 setSelectedWorkgroup ( null ) ;
7273 setMeetingDate ( '' ) ;
7374 } catch ( error ) {
7475 console . error ( 'Error:' , error ) ;
75- // Handle error, e.g., showing an error message
7676 }
7777 }
78- } ;
78+ } ;
7979
8080 return (
8181 < form className = { styles . container } onSubmit = { handleSubmit } >
0 commit comments