From c64c4e417bb48608d6a6b6bc3e5018a82d44fc26 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 12 Mar 2024 23:14:38 +0200 Subject: [PATCH 1/7] misc --- _doc/notes.mb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/_doc/notes.mb b/_doc/notes.mb index bd38d8e..7b8ee37 100644 --- a/_doc/notes.mb +++ b/_doc/notes.mb @@ -153,8 +153,13 @@ Remove-Item package-lock.json npm install -# -- mysql -# fix +# ---------------------------------- mysql ----------------------------------- # +#backup: (--no-data to skip data) +mysqldump -h mariadb -P 3306 -ujwpwsofia -p"dwxhns9p9vp248V39xJyRthUsZ2gR9" jwpwsofia --skip-add-locks > /backup/manual-$(date +\%Y-\%m-\%d-\%H\%M\%S)-$MYSQL_DATABASE.sql + + + +# fix++ mysql -u root -pi4966cWBtP3xJ7BLsbsgo93C8Q5262 -- mysqld_safe --skip-grant-tables & From 8fa48b3682090a396a4806c8f9982b12bca89d4b Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 01:15:55 +0200 Subject: [PATCH 2/7] fix myschedule --- pages/cart/publishers/myschedule.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 1d33c12..8348491 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -58,6 +58,7 @@ export default function MySchedulePage({ assignments }) { ))} + ); @@ -102,9 +103,9 @@ export const getServerSideProps = async (context) => { }, }); - const assignments = publisher[0]?.assignments; + const assignments = publisher[0]?.assignments || []; - const transformedAssignments = assignments.map(assignment => { + const transformedAssignments = assignments?.map(assignment => { if (assignment.shift && assignment.shift.startTime) { return { ...assignment, From 604532761580c2306f7103e38ee51dcf9e822ed9 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 01:16:30 +0200 Subject: [PATCH 3/7] modal extracted to separate file --- components/Modal.tsx | 43 ++++++++++++++++++++++++++ components/calendar/ShiftComponent.tsx | 40 +----------------------- components/sidemenuData.js | 10 +++--- 3 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 components/Modal.tsx diff --git a/components/Modal.tsx b/components/Modal.tsx new file mode 100644 index 0000000..f52839b --- /dev/null +++ b/components/Modal.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import common from '../src/helpers/common'; // Ensure this path is correct + +interface ModalProps { + children: React.ReactNode; + isOpen: boolean; + onClose: () => void; + forDate: Date; + useFilterDate: boolean; + onUseFilterDateChange: (value: boolean) => void; +} + +function Modal({ children, isOpen, onClose, forDate, useFilterDate, onUseFilterDateChange }: ModalProps) { + if (!isOpen) return null; + const isValidDate = forDate instanceof Date && !isNaN(forDate.getTime()); + console.log("forDate", forDate, isValidDate); + + return ( +
+
+ {isValidDate && ( +

+ +

+ )} + {children} + +
+
+
+ ); +} + +export default Modal; diff --git a/components/calendar/ShiftComponent.tsx b/components/calendar/ShiftComponent.tsx index c6c5ec2..0802bc8 100644 --- a/components/calendar/ShiftComponent.tsx +++ b/components/calendar/ShiftComponent.tsx @@ -1,51 +1,13 @@ import React, { useState, useEffect } from 'react'; import axiosInstance from '../../src/axiosSecure'; import PublisherSearchBox from '../publisher/PublisherSearchBox'; // Update the path +import Modal from '../Modal'; import LocalShippingIcon from '@mui/icons-material/LocalShipping'; const common = require('src/helpers/common'); -interface ModalProps { - children: React.ReactNode; - isOpen: boolean; - onClose: () => void; - forDate: Date; - useFilterDate: boolean; - onUseFilterDateChange: (value: boolean) => void; -} - -function Modal({ children, isOpen, onClose, forDate, useFilterDate, onUseFilterDateChange }: ModalProps) { - if (!isOpen) return null; - const isValidDate = forDate instanceof Date && !isNaN(forDate.getTime()); - console.log("forDate", forDate, isValidDate); - - return ( -
-
- {isValidDate && ( -

- -

- )} - {children} - -
-
-
- ); -} - function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, allPublishersInfo }) { diff --git a/components/sidemenuData.js b/components/sidemenuData.js index 7c7053f..56e9119 100644 --- a/components/sidemenuData.js +++ b/components/sidemenuData.js @@ -15,11 +15,11 @@ const sidemenu = [ text: "График", url: "/cart/calendar/schedule", }, - // { - // id: "myshedule", - // text: "Моя График", - // url: "/cart/publishers/myschedule", - // }, + { + id: "myshedule", + text: "Моя График", + url: "/cart/publishers/myschedule", + }, { id: "locations", text: "Местоположения", From c4e0ec9f46cb4a83ad7a7719420b1ef3e787c3eb Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 03:02:40 +0200 Subject: [PATCH 4/7] show shifts attendees in myshifts --- pages/cart/publishers/myschedule.tsx | 70 ++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 8348491..1e8d5b8 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -4,13 +4,18 @@ import ProtectedRoute from '../../../components/protectedRoute'; import { UserRole } from '@prisma/client'; import axiosServer from '../../../src/axiosServer'; import common from '../../../src/helpers/common'; -import ShiftsList from '../../../components/publisher/ShiftsList'; +import Modal from 'components/Modal'; +import PublisherSearchBox from '../../../components/publisher/PublisherSearchBox'; // Update the path import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const" import { useSession, getSession } from 'next-auth/react'; export default function MySchedulePage({ assignments }) { + const [isModalOpen, setIsModalOpen] = useState(false); + const [useFilterDate, setUseFilterDate] = useState(true); + const [assignment, setАssignment] = useState(null); + const { data: session, status } = useSession(); if (status === "loading") { return
Loading...
; @@ -23,7 +28,7 @@ export default function MySchedulePage({ assignments }) {

Моите смени

{assignments && assignments.map((assignment) => ( -
+

{assignment.dateStr}

@@ -31,10 +36,22 @@ export default function MySchedulePage({ assignments }) {
Час
-
+
{GetTimeFormat(assignment.shift.startTime)} - {GetTimeFormat(assignment.shift.endTime)}
+
+
Смяна
+
+ {assignment.shift.assignments.map((a, index) => { + return ( + + {a.publisher.firstName} {a.publisher.lastName} + ) + } + )} +
+
Действия
@@ -45,11 +62,20 @@ export default function MySchedulePage({ assignments }) { Добави в календар + {/* + */}
@@ -58,7 +84,27 @@ export default function MySchedulePage({ assignments }) { ))}
+ setIsModalOpen(false)} + forDate={new Date(assignment?.shift.startTime)} + useFilterDate={useFilterDate} + onUseFilterDateChange={(value) => setUseFilterDate(value)}> + { + // Add publisher as assignment logic + setIsModalOpen(false); + console.log("publisher", publisher.firstName, " ", publisher.lastName, " set to shift ", assignment.shift.id); + //addAssignment(publisher, shift.id); + }} + showAllAuto={true} + showSearch={true} + showList={false} + /> + ); @@ -97,7 +143,21 @@ export const getServerSideProps = async (context) => { include: { assignments: { include: { - shift: true, + shift: { + include: { + assignments: { + include: { + publisher: { + select: { + id: true, + firstName: true, + lastName: true, + } + } + } + } + }, + }, }, }, }, From 0853d95d9196adb2481cdad70ce15642940ffe16 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 03:33:40 +0200 Subject: [PATCH 5/7] shift replcement works --- pages/api/index.ts | 25 +++++++++++++++++++++++++ pages/cart/publishers/myschedule.tsx | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/pages/api/index.ts b/pages/api/index.ts index 563bda8..260bc92 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -210,6 +210,12 @@ export default async function handler(req, res) { res.status(200).json(shiftsForDate); break; + case "replaceInAssignment": + const { oldPublisherId, newPublisherId, shiftId } = req.method === "POST" ? req.body : req.query; + const prisma = common.getPrismaClient(); + const result = await replaceInAssignment(oldPublisherId, newPublisherId, shiftId); + res.status(200).json(result); + break; default: res.status(200).json({ @@ -224,6 +230,7 @@ export default async function handler(req, res) { } + export async function getMonthlyStatistics(selectFields, filterDate) { let publishers = []; @@ -670,4 +677,22 @@ async function getCalendarEvents(publisherId, date, availabilities = true, assig } } return result; +} + + +async function replaceInAssignment(oldPublisherId, newPublisherId, shiftId) { + const prisma = common.getPrismaClient(); + const result = await prisma.assignment.updateMany({ + where: { + publisherId: oldPublisherId, + shiftId: shiftId + }, + data: { + publisherId: newPublisherId, + isConfirmed: false, + isTentative: true, + isMailSent: false + } + }); + return result; } \ No newline at end of file diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 1e8d5b8..8c52bec 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -9,6 +9,9 @@ import PublisherSearchBox from '../../../components/publisher/PublisherSearchBox import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const" import { useSession, getSession } from 'next-auth/react'; +import axiosInstance from 'src/axiosSecure'; +import { toast } from 'react-toastify'; +import LocalShippingIcon from '@mui/icons-material/LocalShipping'; export default function MySchedulePage({ assignments }) { @@ -46,7 +49,8 @@ export default function MySchedulePage({ assignments }) { {assignment.shift.assignments.map((a, index) => { return ( - {a.publisher.firstName} {a.publisher.lastName} + {a.publisher.firstName} {a.publisher.lastName}{a.isWithTransport && } + ) } )} @@ -98,6 +102,26 @@ export default function MySchedulePage({ assignments }) { // Add publisher as assignment logic setIsModalOpen(false); console.log("publisher", publisher.firstName, " ", publisher.lastName, " set to shift ", assignment.shift.id); + //api.replaceInAssignment() + axiosInstance.post('/api/?action=replaceInAssignment', { + oldPublisherId: session.user.id, + newPublisherId: publisher.id, + shiftId: assignment.shift.id, + }).then(response => { + console.log("response", response); + //toast success and confirm the change + toast.success("Промяната е записана!", { + position: "top-right", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + }); + }).catch(error => { + console.log("error", error); + }); //addAssignment(publisher, shift.id); }} showAllAuto={true} From 2be337c5ddc2a2eb59f12f2dfa9be08aa49c7af2 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 03:37:11 +0200 Subject: [PATCH 6/7] refresh UI on close --- pages/cart/publishers/myschedule.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 8c52bec..2918f7b 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -110,14 +110,12 @@ export default function MySchedulePage({ assignments }) { }).then(response => { console.log("response", response); //toast success and confirm the change + // refresh the page after toast is closed toast.success("Промяната е записана!", { - position: "top-right", - autoClose: 5000, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: true, - draggable: true, - progress: undefined, + onClose: () => { + window.location.reload(); + + } }); }).catch(error => { console.log("error", error); From 203701281eac019dcc8eb42631b5e7893f5dfede Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 03:52:52 +0200 Subject: [PATCH 7/7] replacement confrmation --- pages/cart/publishers/myschedule.tsx | 57 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 2918f7b..b96a76c 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -5,6 +5,7 @@ import { UserRole } from '@prisma/client'; import axiosServer from '../../../src/axiosServer'; import common from '../../../src/helpers/common'; import Modal from 'components/Modal'; +import ConfirmationModal from 'components/ConfirmationModal'; import PublisherSearchBox from '../../../components/publisher/PublisherSearchBox'; // Update the path import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const" @@ -16,14 +17,40 @@ import LocalShippingIcon from '@mui/icons-material/LocalShipping'; export default function MySchedulePage({ assignments }) { const [isModalOpen, setIsModalOpen] = useState(false); + const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false); const [useFilterDate, setUseFilterDate] = useState(true); const [assignment, setАssignment] = useState(null); + const [newPublisher, setNewPublisher] = useState(null); const { data: session, status } = useSession(); if (status === "loading") { return
Loading...
; } + const handleReplaceInAssignment = () => { + // Add publisher as assignment logic + setIsModalOpen(false); + setIsConfirmModalOpen(false); + console.log("publisher", newPublisher.firstName, " ", newPublisher.lastName, " set to shift ", assignment.shift.id); + //api.replaceInAssignment() + axiosInstance.post('/api/?action=replaceInAssignment', { + oldPublisherId: session.user.id, + newPublisherId: newPublisher.id, + shiftId: assignment.shift.id, + }).then(response => { + console.log("response", response); + //toast success and confirm the change + // refresh the page after toast is closed + toast.success("Промяната е записана!", { + onClose: () => { + window.location.reload(); + + } + }); + }).catch(error => { + console.log("error", error); + }); + }; return ( @@ -99,34 +126,22 @@ export default function MySchedulePage({ assignments }) { isFocused={isModalOpen} filterDate={useFilterDate && assignment ? new Date(assignment.shift.startTime) : null} onChange={(publisher) => { - // Add publisher as assignment logic - setIsModalOpen(false); - console.log("publisher", publisher.firstName, " ", publisher.lastName, " set to shift ", assignment.shift.id); - //api.replaceInAssignment() - axiosInstance.post('/api/?action=replaceInAssignment', { - oldPublisherId: session.user.id, - newPublisherId: publisher.id, - shiftId: assignment.shift.id, - }).then(response => { - console.log("response", response); - //toast success and confirm the change - // refresh the page after toast is closed - toast.success("Промяната е записана!", { - onClose: () => { - window.location.reload(); + setIsConfirmModalOpen(true); + setNewPublisher(publisher); - } - }); - }).catch(error => { - console.log("error", error); - }); - //addAssignment(publisher, shift.id); }} showAllAuto={true} showSearch={true} showList={false} /> + + { setIsConfirmModalOpen(false); setNewPublisher(null); }} + onConfirm={handleReplaceInAssignment} + message="Това действие ще те замести в назначената ти смяна. Погвърждаваш ли, че заместника знае за тази промяна." + /> );