From 1fb9bae1302349d51f72a1c763d4f5d0c4b56621 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 12:23:22 +0200 Subject: [PATCH 1/2] disable add to calendar button --- pages/api/shiftgenerate.ts | 2 +- pages/cart/publishers/myschedule.tsx | 7 ++++--- src/helpers/calendar.js | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pages/api/shiftgenerate.ts b/pages/api/shiftgenerate.ts index c1bc139..64b2104 100644 --- a/pages/api/shiftgenerate.ts +++ b/pages/api/shiftgenerate.ts @@ -560,7 +560,7 @@ async function DeleteSchedule(axios: Axios, date: Date, forDay: Boolean | undefi async function CreateCalendarForUser(eventId: string | string[] | undefined) { try { - CAL.authorizeNew(); + //CAL.authorizeNew(); CAL.createEvent(eventId); } catch (error) { console.log(error); diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 2d82068..54fb87a 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -87,8 +87,10 @@ export default function MySchedulePage({ assignments }) {
Действия
@@ -128,7 +130,6 @@ export default function MySchedulePage({ assignments }) { onChange={(publisher) => { setIsConfirmModalOpen(true); setNewPublisher(publisher); - }} showAllAuto={true} showSearch={true} diff --git a/src/helpers/calendar.js b/src/helpers/calendar.js index b98581b..4d4541a 100644 --- a/src/helpers/calendar.js +++ b/src/helpers/calendar.js @@ -474,7 +474,24 @@ createEvent = async (event) => { } }; +SaveEventsInGoogleCalendar = async function SaveEventsInGoogleCalendar(events) { + // Load client secrets from a local file. + try { + const content = await fs.readFile(CREDENTIALS_PATH); + // Authorize a client with credentials, then call the Google Calendar API. + authorize(JSON.parse(content), createEvent); + + + } catch (err) { + console.log("Error loading client secret file:", err); + } +}; + + + exports.GenerateICS = GenerateICS; exports.createEvent = createEvent; +exports.SaveEventsInGoogleCalendar = SaveEventsInGoogleCalendar; -createEvent(); + +//createEvent(); From aff13c631d269cd9e1393fb5512755dc09b6ceed Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 13:34:13 +0200 Subject: [PATCH 2/2] fix myschedule start date to be first day of the month --- pages/cart/publishers/myschedule.tsx | 10 +++++++--- src/helpers/common.js | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 54fb87a..273dc56 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -165,14 +165,18 @@ export const getServerSideProps = async (context) => { } const prisma = common.getPrismaClient(); - const publisher = await prisma.publisher.findMany({ + const monthInfo = common.getMonthInfo(new Date()); + //minus 1 day from the firstMonday to get the last Sunday + const lastSunday = new Date(monthInfo.firstMonday); + lastSunday.setDate(lastSunday.getDate() - 1); + const publisher = await prisma.publisher.findUnique({ where: { id: session.user.id, assignments: { some: { shift: { startTime: { - gte: new Date(), + gte: lastSunday, }, }, }, @@ -201,7 +205,7 @@ export const getServerSideProps = async (context) => { }, }); - const assignments = publisher[0]?.assignments || []; + const assignments = publisher?.assignments || []; const transformedAssignments = assignments?.map(assignment => { if (assignment.shift && assignment.shift.startTime) { diff --git a/src/helpers/common.js b/src/helpers/common.js index c1508e1..4cc84e7 100644 --- a/src/helpers/common.js +++ b/src/helpers/common.js @@ -288,6 +288,7 @@ exports.getMonthDatesInfo = function (date) { nrOfWeeks: Math.ceil((lastMonday.getDate() - firstMonday.getDate()) / 7) }; }; +exports.getMonthInfo = exports.getMonthDatesInfo; exports.getMonthlyScheduleRange = function (date) { let info = exports.getMonthDatesInfo(date);