From d1d0ca667e0581ae32a285ca36e9c0ed9ddb4918 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 21 Jun 2024 14:51:08 +0300 Subject: [PATCH 01/12] fix form submit bug --- components/survey/SurveyForm.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/survey/SurveyForm.tsx b/components/survey/SurveyForm.tsx index 60c3ace..389ebda 100644 --- a/components/survey/SurveyForm.tsx +++ b/components/survey/SurveyForm.tsx @@ -62,8 +62,8 @@ const SurveyForm: React.FC = ({ existingItem }) => { ...existingItem, content: existingItem?.content || "Нова анкета", answers: existingItem?.answers.split(",") || [], - publicFrom: existingItem?.publicFrom ? dayjs(existingItem.publicFrom).toISOString() : new Date().toISOString(), - publicUntil: existingItem?.publicUntil ? dayjs(existingItem.publicUntil).toISOString() : new Date().toISOString(), + publicFrom: existingItem?.publicFrom ? dayjs(existingItem.publicFrom).toISOString() : '', + publicUntil: existingItem?.publicUntil ? dayjs(existingItem.publicUntil).toISOString() : null, }); @@ -104,7 +104,7 @@ const SurveyForm: React.FC = ({ existingItem }) => { } else { //get all publisherIds and create a message for each - const messages = pubs.data.map(pub => { + const messages = pubs.map(pub => { return { publisherId: pub.id, content: JSON.stringify({ message: item.content, options: item.answers }), From 784f95cc9f93824f2ed5f43b5c966d794503e127 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 21 Jun 2024 15:41:50 +0300 Subject: [PATCH 02/12] change content size --- prisma/migrations/20240621124135_/migration.sql | 5 +++++ prisma/schema.prisma | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 prisma/migrations/20240621124135_/migration.sql diff --git a/prisma/migrations/20240621124135_/migration.sql b/prisma/migrations/20240621124135_/migration.sql new file mode 100644 index 0000000..9063825 --- /dev/null +++ b/prisma/migrations/20240621124135_/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE `message` MODIFY `content` TEXT NOT NULL; + +-- AlterTable +ALTER TABLE `survey` MODIFY `content` TEXT NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 35996b6..91a0197 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -266,7 +266,7 @@ enum MessageType { model Survey { id Int @id @default(autoincrement()) - content String + content String @db.Text answers Json? messages Message[] publicFrom DateTime? @@ -278,7 +278,7 @@ model Message { publisher Publisher @relation(fields: [publisherId], references: [id]) publisherId String date DateTime - content String + content String @db.Text isRead Boolean @default(false) isPublic Boolean @default(false) type MessageType @default(Email) From 43809487a7b541381393afdd452220302fa8145b Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 21 Jun 2024 16:46:34 +0300 Subject: [PATCH 03/12] fix migration casing, UI improvements --- components/survey/SurveyForm.tsx | 7 +++++-- prisma/migrations/20240621124135_/migration.sql | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/survey/SurveyForm.tsx b/components/survey/SurveyForm.tsx index 389ebda..6d9e040 100644 --- a/components/survey/SurveyForm.tsx +++ b/components/survey/SurveyForm.tsx @@ -213,13 +213,16 @@ const SurveyForm: React.FC = ({ existingItem }) => { - handleDateChange('publicFrom', newDate)} value={dayjs(item?.publicFrom)} /> + handleDateChange('publicFrom', newDate)} + value={item && item.publicFrom ? dayjs(item.publicFrom) : null} />
- handleDateChange('publicUntil', newDate)} value={dayjs(item?.publicUntil)} /> + handleDateChange('publicUntil', newDate)} + value={item && item.publicUntil ? dayjs(item.publicUntil) : null} + />
+ {isAdmin &&
{/*
} - {notificationPermission !== "granted" && ( - - )} + { + notificationPermission !== "granted" && ( + + ) + } - {isAdmin &&
- } ); diff --git a/components/publisher/PublisherForm.js b/components/publisher/PublisherForm.js index 7d76de3..85cdb6f 100644 --- a/components/publisher/PublisherForm.js +++ b/components/publisher/PublisherForm.js @@ -303,7 +303,8 @@ export default function PublisherForm({ item, me }) { {/* In-App notifications group */}

Известия в приложението

- + +
diff --git a/components/publisher/PublisherShiftsModal.js b/components/publisher/PublisherShiftsModal.js new file mode 100644 index 0000000..55d31d6 --- /dev/null +++ b/components/publisher/PublisherShiftsModal.js @@ -0,0 +1,128 @@ +//Refactor ToDo: show the whole month instead of just the current week by showing the shift start time in front of the rows, and show all shifts in the month from the first to the last week in the cell where we show one shift now +function PublisherShiftsModal({ publisher, shifts, onClose }) { + const monthInfo = common.getMonthDatesInfo(new Date(value)); + const monthShifts = shifts.filter(shift => { + const shiftDate = new Date(shift.startTime); + return shiftDate > monthInfo.firstDay && shiftDate < monthInfo.lastDay; + }); + const weekShifts = monthShifts.filter(shift => { + const shiftDate = new Date(shift.startTime); + return common.getStartOfWeek(value) <= shiftDate && shiftDate <= common.getEndOfWeek(value); + }); + const dayShifts = weekShifts.map(shift => { + const isAvailable = publisher.availabilities?.some(avail => + avail.startTime <= shift.startTime && avail.endTime >= shift.endTime + ); + let color = isAvailable ? getColorForShift(shift) : 'bg-gray-300'; + if (shift.isFromPreviousMonth) { + color += ' border-l-4 border-orange-500 '; + } + if (shift.isFromPreviousAssignment) { + color += ' border-l-4 border-red-500 '; + } + return { ...shift, isAvailable, color }; + }).reduce((acc, shift) => { + const dayIndex = new Date(shift.startTime).getDay(); + acc[dayIndex] = acc[dayIndex] || []; + acc[dayIndex].push(shift); + return acc; + }, {}); + console.log("dayShifts:", dayShifts); + + const hasAssignment = (shiftId) => { + // return publisher.assignments.some(ass => ass.shift.id == shiftId); + return publisher.assignments?.some(ass => { + //console.log(`Comparing: ${ass.shift.id} to ${shiftId}: ${ass.shift.id === shiftId}`); + return ass.shift.id === shiftId; + }); + }; + + + useEffect(() => { + const handleKeyDown = (event) => { + if (event.key === 'Escape') { + console.log('ESC: closing modal.'); + onClose(); // Call the onClose function when ESC key is pressed + } + }; + + // Add event listener + window.addEventListener('keydown', handleKeyDown); + + // Remove event listener on cleanup + return () => { + window.removeEventListener('keydown', handleKeyDown); + }; + }, [onClose]); // Include onClose in the dependency array + + return ( +
+
+

График на + {publisher.firstName} {publisher.lastName} + {publisher.email} + тази седмица:

+ + {/* ... Display shifts in a calendar-like UI ... */} +
+ {Object.entries(dayShifts).map(([dayIndex, shiftsForDay]) => ( +
+ {/* Day header */} +
{new Date(shiftsForDay[0].startTime).getDate()}-ти
+ + {shiftsForDay.map((shift, index) => { + const assignmentExists = hasAssignment(shift.id); + const availability = publisher.availabilities.find(avail => + avail.startTime <= shift.startTime && avail.endTime >= shift.endTime + ); + const isFromPrevMonth = availability && availability.isFromPreviousMonth; + return ( +
+ {common.getTimeRange(shift.startTime, shift.endTime)} {shift.id} + + {!assignmentExists && shift.isAvailable && ( + + )} + {assignmentExists && ( + + )} +
+ ); + } + )} +
+ ))} +
+ + {/* Close button in the top right corner */} + + + {/* + + */} + {/* Edit button in the top right corner, next to the close button */} + + + + +
+
+ ); +} diff --git a/pages/api/schedule.ts b/pages/api/schedule.ts index d95b1e6..b723095 100644 --- a/pages/api/schedule.ts +++ b/pages/api/schedule.ts @@ -152,15 +152,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) //bold the text after - in the notes notes: notes, notes_bold: notes_bold, - names: shift.assignments - .map((assignment) => { - return ( - assignment.publisher.firstName + - " " + - assignment.publisher.lastName - ); - }) - .join(", "), + names: shift.assignments.length > 0 + ? shift.assignments + .map((assignment) => { + return ( + assignment.publisher.firstName + + " " + + assignment.publisher.lastName + ); + }) + .join(", ") + : shift.name, }; if (shiftSchedule.names.length > 0) { diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index fd55e48..0663bea 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -9,6 +9,7 @@ import Shift from '../../../components/calendar/ShiftComponent'; import { DayOfWeek, UserRole } from '@prisma/client'; import { env } from 'process' import ShiftComponent from '../../../components/calendar/ShiftComponent'; +import PublisherShiftsModal from '../../../components/publisher/PublisherShiftsModal'; //import { set } from 'date-fns'; const common = require('src/helpers/common'); import { toast } from 'react-toastify'; @@ -66,6 +67,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { const [shifts, setShifts] = React.useState([]); const [error, setError] = React.useState(null); const [availablePubs, setAvailablePubs] = React.useState([]); + const [selectedPublisher, setSelectedPublisher] = React.useState(null); const [selectedShiftId, setSelectedShiftId] = useState(null); @@ -214,8 +216,8 @@ export default function CalendarPage({ initialEvents, initialShifts }) { }; const handleSelectedPublisher = (publisher) => { - // Do something with the selected publisher console.log("handle pub clicked:", publisher); + setSelectedPublisher(publisher); } const handlePublisherModalOpen = async (publisher) => { // Do something with the selected publisher @@ -365,6 +367,10 @@ export default function CalendarPage({ initialEvents, initialShifts }) { isConfirmed: true }; const { data } = await axiosInstance.post("/api/data/assignments", newAssignment); + if (selectedShiftId == shiftId) { + handleShiftSelection(shifts.find(shift => shift.id === shiftId)); + } + // Update the 'publisher' property of the returned data with the full publisher object data.publisher = publisher; data.shift = shifts.find(shift => shift.id === shiftId); @@ -816,6 +822,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { ${bgAndBorderColorClass} ${selectedBorderClass} ${activeOpacityClass} ${pub.currentMonthAssignments >= pub.desiredShiftsPerMonth ? 'text-gray-400' : 'text-gray-800'}`} onDoubleClick={(handlePublisherModalOpen.bind(this, pub))} + onClick={handleSelectedPublisher.bind(this, pub)} > {pub.firstName} {pub.lastName} @@ -831,33 +838,8 @@ export default function CalendarPage({ initialEvents, initialShifts }) { @@ -905,133 +887,6 @@ export default function CalendarPage({ initialEvents, initialShifts }) { ); - function PublisherShiftsModal({ publisher, shifts, onClose }) { - const monthInfo = common.getMonthDatesInfo(new Date(value)); - const monthShifts = shifts.filter(shift => { - const shiftDate = new Date(shift.startTime); - return shiftDate > monthInfo.firstDay && shiftDate < monthInfo.lastDay; - }); - const weekShifts = monthShifts.filter(shift => { - const shiftDate = new Date(shift.startTime); - return common.getStartOfWeek(value) <= shiftDate && shiftDate <= common.getEndOfWeek(value); - }); - const dayShifts = weekShifts.map(shift => { - const isAvailable = publisher.availabilities?.some(avail => - avail.startTime <= shift.startTime && avail.endTime >= shift.endTime - ); - let color = isAvailable ? getColorForShift(shift) : 'bg-gray-300'; - if (shift.isFromPreviousMonth) { - color += ' border-l-4 border-orange-500 '; - } - if (shift.isFromPreviousAssignment) { - color += ' border-l-4 border-red-500 '; - } - return { ...shift, isAvailable, color }; - }).reduce((acc, shift) => { - const dayIndex = new Date(shift.startTime).getDay(); - acc[dayIndex] = acc[dayIndex] || []; - acc[dayIndex].push(shift); - return acc; - }, {}); - console.log("dayShifts:", dayShifts); - - const hasAssignment = (shiftId) => { - // return publisher.assignments.some(ass => ass.shift.id == shiftId); - return publisher.assignments?.some(ass => { - //console.log(`Comparing: ${ass.shift.id} to ${shiftId}: ${ass.shift.id === shiftId}`); - return ass.shift.id === shiftId; - }); - }; - - - useEffect(() => { - const handleKeyDown = (event) => { - if (event.key === 'Escape') { - console.log('ESC: closing modal.'); - onClose(); // Call the onClose function when ESC key is pressed - } - }; - - // Add event listener - window.addEventListener('keydown', handleKeyDown); - - // Remove event listener on cleanup - return () => { - window.removeEventListener('keydown', handleKeyDown); - }; - }, [onClose]); // Include onClose in the dependency array - - return ( -
-
-

График на - {publisher.firstName} {publisher.lastName} - {publisher.email} - тази седмица:

- - {/* ... Display shifts in a calendar-like UI ... */} -
- {Object.entries(dayShifts).map(([dayIndex, shiftsForDay]) => ( -
- {/* Day header */} -
{new Date(shiftsForDay[0].startTime).getDate()}-ти
- - {shiftsForDay.map((shift, index) => { - const assignmentExists = hasAssignment(shift.id); - const availability = publisher.availabilities.find(avail => - avail.startTime <= shift.startTime && avail.endTime >= shift.endTime - ); - const isFromPrevMonth = availability && availability.isFromPreviousMonth; - return ( -
- {common.getTimeRange(shift.startTime, shift.endTime)} {shift.id} - - {!assignmentExists && shift.isAvailable && ( - - )} - {assignmentExists && ( - - )} -
- ); - } - )} -
- ))} -
- - {/* Close button in the top right corner */} - - - {/* - - */} - {/* Edit button in the top right corner, next to the close button */} - - - - -
-
- ); - } function getColorForShift(shift) { const assignedCount = shift.assignedCount || 0; // Assuming each shift has an assignedCount property From 0d8d9bc4fda16ca4e7c86ee2781d68c26d556008 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 28 Jun 2024 19:57:59 +0300 Subject: [PATCH 05/12] pubs orange if overbooked --- pages/cart/calendar/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index 0663bea..5f0f117 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -785,7 +785,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { със стари предпочитания -
    +
      {Array.isArray(availablePubs) && availablePubs?.map((pub, index) => { // Determine background and border classes based on conditions let bgAndBorderColorClass; @@ -820,7 +820,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
    • = pub.desiredShiftsPerMonth ? 'text-gray-400' : 'text-gray-800'}`} + ${pub.currentMonthAssignments === pub.desiredShiftsPerMonth ? 'text-gray-400' : pub.currentMonthAssignments > pub.desiredShiftsPerMonth ? 'text-orange-300' : 'text-gray-800'}`} onDoubleClick={(handlePublisherModalOpen.bind(this, pub))} onClick={handleSelectedPublisher.bind(this, pub)} > From ca92c07d4d0c7a25a58c61bd437765e289e988ec Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 28 Jun 2024 20:10:34 +0300 Subject: [PATCH 06/12] fix message text --- components/ErrorBoundary.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/ErrorBoundary.tsx b/components/ErrorBoundary.tsx index 2dbbd89..87a148f 100644 --- a/components/ErrorBoundary.tsx +++ b/components/ErrorBoundary.tsx @@ -27,7 +27,7 @@ class ErrorBoundary extends React.Component { render() { if (this.state.hasError) { // Render any custom fallback UI - return

      Нещо се обърка при изтриването. Моля, опитай отново и се свържете с нас ако проблема продължи.

      ; + return

      Нещо се обърка. Моля, опитай отново и се свържете с нас ако проблема продължи.

      ; } return this.props.children; From 5dba87f3dd0f38568aa1dc14cd2e943b98c81459 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 28 Jun 2024 20:34:14 +0300 Subject: [PATCH 07/12] fix modal afrer refactoring --- components/publisher/PublisherShiftsModal.js | 34 ++++++++++++++++---- pages/api/schedule.ts | 5 ++- pages/cart/calendar/index.tsx | 29 +++++++---------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/components/publisher/PublisherShiftsModal.js b/components/publisher/PublisherShiftsModal.js index 55d31d6..9b61cff 100644 --- a/components/publisher/PublisherShiftsModal.js +++ b/components/publisher/PublisherShiftsModal.js @@ -1,16 +1,22 @@ -//Refactor ToDo: show the whole month instead of just the current week by showing the shift start time in front of the rows, and show all shifts in the month from the first to the last week in the cell where we show one shift now -function PublisherShiftsModal({ publisher, shifts, onClose }) { - const monthInfo = common.getMonthDatesInfo(new Date(value)); +import React, { useEffect } from 'react'; +import Link from 'next/link'; +import common from 'src/helpers/common'; + +const PublisherShiftsModal = ({ publisher, shifts, onClose, date }) => { + + //Refactor ToDo: show the whole month instead of just the current week by showing the shift start time in front of the rows, and show all shifts in the month from the first to the last week in the cell where we show one shift now + + const monthInfo = common.getMonthDatesInfo(new Date(date)); const monthShifts = shifts.filter(shift => { const shiftDate = new Date(shift.startTime); return shiftDate > monthInfo.firstDay && shiftDate < monthInfo.lastDay; }); const weekShifts = monthShifts.filter(shift => { const shiftDate = new Date(shift.startTime); - return common.getStartOfWeek(value) <= shiftDate && shiftDate <= common.getEndOfWeek(value); + return common.getStartOfWeek(date) <= shiftDate && shiftDate <= common.getEndOfWeek(date); }); const dayShifts = weekShifts.map(shift => { - const isAvailable = publisher.availabilities?.some(avail => + const isAvailable = publisher?.availabilities?.some(avail => avail.startTime <= shift.startTime && avail.endTime >= shift.endTime ); let color = isAvailable ? getColorForShift(shift) : 'bg-gray-300'; @@ -113,12 +119,12 @@ function PublisherShiftsModal({ publisher, shifts, onClose }) { × - {/* */} {/* Edit button in the top right corner, next to the close button */} - + @@ -126,3 +132,17 @@ function PublisherShiftsModal({ publisher, shifts, onClose }) { ); } + +function getColorForShift(shift) { + const assignedCount = shift.assignedCount || 0; // Assuming each shift has an assignedCount property + switch (assignedCount) { + case 0: return 'bg-blue-300'; + case 1: return 'bg-green-300'; + case 2: return 'bg-yellow-300'; + case 3: return 'bg-orange-300'; + case 4: return 'bg-red-200'; + default: return 'bg-gray-300'; + } +} + +export default PublisherShiftsModal; \ No newline at end of file diff --git a/pages/api/schedule.ts b/pages/api/schedule.ts index b723095..51d5c50 100644 --- a/pages/api/schedule.ts +++ b/pages/api/schedule.ts @@ -93,7 +93,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const shifts = await prisma.shift.findMany({ where: { isActive: true, - isPublished: true, + OR: [ + { isPublished: true }, + { user: { role: 'admin' } } // Todo: example. fix this + ], startTime: { gte: fromDate, //lt: toDate, diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index 5f0f117..38b2948 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -821,8 +821,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { className={`flex justify-between items-center p-4 sm:py-2 rounded-lg shadow-sm mb-2 ${bgAndBorderColorClass} ${selectedBorderClass} ${activeOpacityClass} ${pub.currentMonthAssignments === pub.desiredShiftsPerMonth ? 'text-gray-400' : pub.currentMonthAssignments > pub.desiredShiftsPerMonth ? 'text-orange-300' : 'text-gray-800'}`} - onDoubleClick={(handlePublisherModalOpen.bind(this, pub))} - onClick={handleSelectedPublisher.bind(this, pub)} + onDoubleClick={() => handlePublisherModalOpen(pub)} > {pub.firstName} {pub.lastName} @@ -838,11 +837,10 @@ export default function CalendarPage({ initialEvents, initialShifts }) { -
    • ); @@ -881,24 +879,21 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
      {/* */}
      - {isModalOpen && setIsModalOpen(false)} />} + {isModalOpen && ( + setIsModalOpen(false)} + date={value} + /> + )} ); - function getColorForShift(shift) { - const assignedCount = shift.assignedCount || 0; // Assuming each shift has an assignedCount property - switch (assignedCount) { - case 0: return 'bg-blue-300'; - case 1: return 'bg-green-300'; - case 2: return 'bg-yellow-300'; - case 3: return 'bg-orange-300'; - case 4: return 'bg-red-200'; - default: return 'bg-gray-300'; - } - } + } import axiosServer from '../../../src/axiosServer'; From 8b2cdc517e859822dfa6c2d1cb83a2cbaffeb07c Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 28 Jun 2024 20:43:45 +0300 Subject: [PATCH 08/12] fix modal add/remove --- components/publisher/PublisherShiftsModal.js | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/components/publisher/PublisherShiftsModal.js b/components/publisher/PublisherShiftsModal.js index 9b61cff..04968ff 100644 --- a/components/publisher/PublisherShiftsModal.js +++ b/components/publisher/PublisherShiftsModal.js @@ -145,4 +145,41 @@ function getColorForShift(shift) { } } +//ToDo: DRY - move to common +const addAssignment = async (publisher, shiftId) => { + try { + console.log(`calendar.idx: new assignment for publisher ${publisher.id} - ${publisher.firstName} ${publisher.lastName}`); + const newAssignment = { + publisher: { connect: { id: publisher.id } }, + shift: { connect: { id: shiftId } }, + isConfirmed: true + }; + const { data } = await axiosInstance.post("/api/data/assignments", newAssignment); + if (selectedShiftId == shiftId) { + handleShiftSelection(shifts.find(shift => shift.id === shiftId)); + } + + // Update the 'publisher' property of the returned data with the full publisher object + data.publisher = publisher; + data.shift = shifts.find(shift => shift.id === shiftId); + publisher.assignments = [...publisher.assignments, data]; + handleAssignmentChange(publisher.id, 'add'); + } catch (error) { + console.error("Error adding assignment:", error); + } +}; +const removeAssignment = async (publisher, shiftId) => { + try { + const assignment = publisher.assignments.find(ass => ass.shift.id === shiftId); + console.log(`calendar.idx: remove assignment for shift ${shiftId}`); + const { data } = await axiosInstance.delete(`/api/data/assignments/${assignment.id}`); + //remove from local assignments: + publisher.assignments = publisher.assignments.filter(a => a.id !== assignment.id) + // + handleAssignmentChange(publisher.id, 'remove') + } catch (error) { + console.error("Error removing assignment:", error); + } +} + export default PublisherShiftsModal; \ No newline at end of file From 330783eca7fb834dace3d34f977fb461024797c3 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 28 Jun 2024 20:44:00 +0300 Subject: [PATCH 09/12] comment --- pages/cart/calendar/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index 38b2948..5db48b7 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -357,7 +357,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { } return
      {" "}
      ; }; - + //ToDo: DRY - move to common const addAssignment = async (publisher, shiftId) => { try { console.log(`calendar.idx: new assignment for publisher ${publisher.id} - ${publisher.firstName} ${publisher.lastName}`); From 75faedee078176fc1b633a7b7b003732fa1e26f5 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 28 Jun 2024 21:07:42 +0300 Subject: [PATCH 10/12] bugfix --- components/publisher/PublisherShiftsModal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/components/publisher/PublisherShiftsModal.js b/components/publisher/PublisherShiftsModal.js index 04968ff..fd9d031 100644 --- a/components/publisher/PublisherShiftsModal.js +++ b/components/publisher/PublisherShiftsModal.js @@ -1,6 +1,7 @@ import React, { useEffect } from 'react'; import Link from 'next/link'; import common from 'src/helpers/common'; +import axiosInstance from 'src/axiosSecure'; const PublisherShiftsModal = ({ publisher, shifts, onClose, date }) => { From aefc4c6ceb6a7b5abd2624297341b84f8c4087da Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Sat, 29 Jun 2024 11:37:42 +0300 Subject: [PATCH 11/12] fix schedule --- pages/api/schedule.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pages/api/schedule.ts b/pages/api/schedule.ts index 51d5c50..0672c76 100644 --- a/pages/api/schedule.ts +++ b/pages/api/schedule.ts @@ -93,10 +93,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const shifts = await prisma.shift.findMany({ where: { isActive: true, - OR: [ - { isPublished: true }, - { user: { role: 'admin' } } // Todo: example. fix this - ], + isPublished: true, + // OR: [ + // { isPublished: true }, + // { user: { role: 'admin' } } // Todo: example. fix this + // ], startTime: { gte: fromDate, //lt: toDate, @@ -251,6 +252,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ); } catch (error) { + console.log(error); res.status(500).json({ error: "Internal Server Error" }); } } else { From 5c78e561ee97f2b4b644a7e34c8a0025400ced20 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 5 Jul 2024 18:15:50 +0300 Subject: [PATCH 12/12] change entrypoint script to avoid wiping uploads folder everytime --- _deploy/deoloy.azure.production.yml | 11 ++++++----- _deploy/entrypoint.sh | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/_deploy/deoloy.azure.production.yml b/_deploy/deoloy.azure.production.yml index 55a11d4..c91c26e 100644 --- a/_deploy/deoloy.azure.production.yml +++ b/_deploy/deoloy.azure.production.yml @@ -9,6 +9,7 @@ services: # - "3000:3000" volumes: - /mnt/docker_volumes/pw/app/public/content/uploads/:/app/public/content/uploads + - /mnt/docker_volumes/pw/app/logs:/app/logs environment: - NODE_ENV=production - TZ=Europe/Sofia @@ -19,7 +20,7 @@ services: - GIT_USERNAME=deploy - GIT_PASSWORD=L3Kr2R438u4F7 - ADMIN_PASSWORD=changeme - command: sh -c " cd /app && npm install && npm run prod; tail -f /dev/null" + command: sh -c " cd /app && npm install && npx next build && npm run prod; tail -f /dev/null" #command: sh -c " cd /app && tail -f /dev/null" tty: true stdin_open: true @@ -56,15 +57,15 @@ services: networks: - infrastructure_default command: | - apk update && \ + "apk update && \ apk add --no-cache mariadb-client mariadb-connector-c && \ echo '0 2 * * * mysqldump -h $$MYSQL_HOST -P 3306 -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql' > /etc/crontabs/root && \ - echo '0 7 * * * rclone sync /backup nextcloud:/mwitnessing' >> /etc/crontabs/root && \ - crond -f -d 8 + crond -f -d 8" # wget -q https://github.com/prasmussen/gdrive/releases/download/2.1.0/gdrive-linux-x64 -O /usr/bin/gdrive && \ # chmod +x /usr/bin/gdrive && \ # gdrive about --service-account /root/.gdrive_service_account.json && \ - # echo '0 * * * * /usr/bin/mysqldump -h $$MYSQL_HOST -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE | gzip > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz && gdrive upload --parent $$GOOGLE_DRIVE_FOLDER_ID --service-account /root/.gdrive_service_account.json /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz' > /etc/crontabs/root && crond -f -d 8" + # echo '0 * * * * /usr/bin/mysqldump -h $$MYSQL_HOST -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE | gzip > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz && gdrive upload --parent $$GOOGLE_DRIVE_FOLDER_ID --service-account /root/.gdrive_service_account.json /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz' > /etc/crontabs/root && crond -f -d 8 \ + # echo '0 7 * * * rclone sync /backup nextcloud:/mwitnessing' >> /etc/crontabs/root && \" networks: infrastructure_default: external: true diff --git a/_deploy/entrypoint.sh b/_deploy/entrypoint.sh index db16b09..fa78e35 100644 --- a/_deploy/entrypoint.sh +++ b/_deploy/entrypoint.sh @@ -12,8 +12,9 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then # Clone the repository git clone -b ${GIT_BRANCH:-main} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/mwitnessing.git /tmp/clone || exit 1 - # Synchronize all files except package.json and package-lock.json to /app - rsync -av --delete --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files" + # Synchronize all files except package.json and package-lock.json to /app. alo exclude '/app/public/content/uploads' to avoid deleting uploaded files + rsync -av --delete --exclude 'package.json' --exclude 'package-lock.json' --exclude '/app/public/content/uploads' + /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files" # Determine if package.json or package-lock.json has changed PACKAGE_CHANGE=0