Skip to content

Commit 4b7517f

Browse files
Merge pull request #74 from SingularityNET-Archive:development
Development
2 parents 8e2bc59 + 0056fbe commit 4b7517f

12 files changed

+525
-405
lines changed

components/ArchiveSummaries.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,44 @@ const ArchiveSummaries = () => {
5656
}
5757
};
5858

59-
async function handleSubmit(e: any) {
59+
async function handleSubmit(e: React.FormEvent) {
6060
e.preventDefault();
6161
setLoading(true);
62-
if (myVariable.summary.confirmed == false) {
62+
63+
// Check if there are any confirmed summaries with the same date
64+
const isDuplicateConfirmedSummary = myVariable.summaries.some((summary: any) => {
65+
// Convert both dates to Date objects to strip off the time part
66+
const summaryDate = new Date(summary.date).toDateString();
67+
const formDataDate = new Date(formData.date).toDateString();
68+
//console.log(summaryDate, formDataDate, summaryDate === formDataDate && summary.confirmed); // For debugging purposes
69+
// Compare the date strings
70+
return summaryDate === formDataDate && summary.confirmed;
71+
});
72+
73+
if (isDuplicateConfirmedSummary) {
74+
alert('A confirmed summary for this date already exists.');
75+
setLoading(false);
76+
return; // Exit the function early
77+
}
78+
79+
if (!myVariable.summary.confirmed) {
6380
const data = await updateGitbook(formData);
64-
//console.log("returned from util function", formData)
6581
if (data) {
66-
setMyVariable({
67-
...myVariable,
82+
setMyVariable(prevState => ({
83+
...prevState,
6884
summary: {
69-
...myVariable.summary,
85+
...prevState.summary,
7086
confirmed: true,
7187
},
72-
});
88+
}));
7389
}
74-
//console.log(myVariable)
7590
await sendDiscordMessage(myVariable, renderedMarkdown);
76-
//console.log(myVariable, "renderedMarkdown", renderedMarkdown)
7791
} else {
78-
alert('Summary already archived')
92+
alert('Summary already archived');
7993
}
8094

8195
setLoading(false);
82-
}
96+
}
8397

8498
return (
8599
<div>

components/SubmitMissingSummary.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,52 @@ import { saveMissingSummary } from '../utils/saveMissingSummaries';
55
function 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

Comments
 (0)