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}