shift replcement works

This commit is contained in:
Dobromir Popov
2024-03-13 03:33:40 +02:00
parent c4e0ec9f46
commit 0853d95d91
2 changed files with 50 additions and 1 deletions

View File

@ -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;
}

View File

@ -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 (
<span key={index} className="inline-flex items-center mr-1 px-1 py-0.5 rounded-full text-sm font-medium ">
{a.publisher.firstName} {a.publisher.lastName}</span>
{a.publisher.firstName} {a.publisher.lastName}{a.isWithTransport && <LocalShippingIcon style={{ paddingLeft: '4px' }} />}
</span>
)
}
)}
@ -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}