Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions components/ArchiveSummaries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,44 @@ const ArchiveSummaries = () => {
}
};

async function handleSubmit(e: any) {
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setLoading(true);
if (myVariable.summary.confirmed == false) {

// Check if there are any confirmed summaries with the same date
const isDuplicateConfirmedSummary = myVariable.summaries.some((summary: any) => {
// Convert both dates to Date objects to strip off the time part
const summaryDate = new Date(summary.date).toDateString();
const formDataDate = new Date(formData.date).toDateString();
//console.log(summaryDate, formDataDate, summaryDate === formDataDate && summary.confirmed); // For debugging purposes
// Compare the date strings
return summaryDate === formDataDate && summary.confirmed;
});

if (isDuplicateConfirmedSummary) {
alert('A confirmed summary for this date already exists.');
setLoading(false);
return; // Exit the function early
}

if (!myVariable.summary.confirmed) {
const data = await updateGitbook(formData);
//console.log("returned from util function", formData)
if (data) {
setMyVariable({
...myVariable,
setMyVariable(prevState => ({
...prevState,
summary: {
...myVariable.summary,
...prevState.summary,
confirmed: true,
},
});
}));
}
//console.log(myVariable)
await sendDiscordMessage(myVariable, renderedMarkdown);
//console.log(myVariable, "renderedMarkdown", renderedMarkdown)
} else {
alert('Summary already archived')
alert('Summary already archived');
}

setLoading(false);
}
}

return (
<div>
Expand Down
4 changes: 4 additions & 0 deletions utils/filterFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
type AnyObj = { [key: string]: any };

export function filterFormData(data: AnyObj): AnyObj {

if (data === null || data === undefined || Object.keys(data).length === 0) {
return {}; // Return an empty object or some default value as appropriate
}
if (!data.confirmed) {
return data; // Return the original data unmodified if not confirmed
}
Expand Down
19 changes: 10 additions & 9 deletions utils/getsummaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import { supabase } from "../lib/supabaseClient";
export async function getSummaries(workgroup_id) {
let summaries = []; // Initialize an array to hold the summaries
let summary = {};
let lastConfirmedDate = null;
let lastUpdatedAt = null;
let lastConfirmedMeeting = null;
let confirmedDates = new Set();

async function getMeetingSummaries() {
try {
Expand All @@ -41,17 +40,19 @@ export async function getSummaries(workgroup_id) {
if (summaryData) {
// Find the last confirmed meeting
lastConfirmedMeeting = summaryData.find(data => data.confirmed === true);
if (lastConfirmedMeeting) {
lastConfirmedDate = lastConfirmedMeeting.date;
lastUpdatedAt = lastConfirmedMeeting.updated_at;
}

summaryData.forEach(data => {
if (data.confirmed) confirmedDates.add(data.date);
});
// Fetch the user details for each summary
for (const data of summaryData) {
// Exclude meetings where confirmed == true and all meetings with an earlier date and updated_at date than the last meeting where confirmed == true
/*if (data.confirmed === true || new Date(data.date) < new Date(lastConfirmedDate)) { //Might have to add this back in later - || new Date(data.updated_at) < new Date(lastUpdatedAt)
const isSameDateAsLastConfirmed = lastConfirmedMeeting && new Date(data.date).getTime() === new Date(lastConfirmedMeeting.date).getTime();
const isDateWithOtherConfirmed = confirmedDates.has(data.date) && (!lastConfirmedMeeting || (lastConfirmedMeeting && !isSameDateAsLastConfirmed));

// Skip if it's not the last confirmed and it's a date with another confirmed summary
if (data.confirmed && !isSameDateAsLastConfirmed || isDateWithOtherConfirmed) {
continue;
}*/
}

const { data: userData, error: userError } = await supabase
.from('users')
Expand Down