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 &
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: "Местоположения",
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 1d33c12..b96a76c 100644
--- a/pages/cart/publishers/myschedule.tsx
+++ b/pages/cart/publishers/myschedule.tsx
@@ -4,18 +4,53 @@ 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 ConfirmationModal from 'components/ConfirmationModal';
+import PublisherSearchBox from '../../../components/publisher/PublisherSearchBox'; // Update the path
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 }) {
+ 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 (
@@ -23,7 +58,7 @@ export default function MySchedulePage({ assignments }) {
Моите смени
{assignments && assignments.map((assignment) => (
-
+
{assignment.dateStr}
@@ -31,10 +66,23 @@ 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}{a.isWithTransport && }
+
+ )
+ }
+ )}
+
+
- Действия
-
@@ -45,11 +93,20 @@ export default function MySchedulePage({ assignments }) {
Добави в календар
+ {/*
+ */}
@@ -58,6 +115,33 @@ export default function MySchedulePage({ assignments }) {
))}
+
setIsModalOpen(false)}
+ forDate={new Date(assignment?.shift.startTime)}
+ useFilterDate={useFilterDate}
+ onUseFilterDateChange={(value) => setUseFilterDate(value)}>
+
+ {
+ setIsConfirmModalOpen(true);
+ setNewPublisher(publisher);
+
+ }}
+ showAllAuto={true}
+ showSearch={true}
+ showList={false}
+ />
+
+
+
{ setIsConfirmModalOpen(false); setNewPublisher(null); }}
+ onConfirm={handleReplaceInAssignment}
+ message="Това действие ще те замести в назначената ти смяна. Погвърждаваш ли, че заместника знае за тази промяна."
+ />
);
@@ -96,15 +180,29 @@ export const getServerSideProps = async (context) => {
include: {
assignments: {
include: {
- shift: true,
+ shift: {
+ include: {
+ assignments: {
+ include: {
+ publisher: {
+ select: {
+ id: true,
+ firstName: true,
+ lastName: true,
+ }
+ }
+ }
+ }
+ },
+ },
},
},
},
});
- 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,