restore deleted by accident source
This commit is contained in:
@ -14,12 +14,9 @@ const common = require('src/helpers/common');
|
|||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
import ProtectedRoute from '../../../components/protectedRoute';
|
import ProtectedRoute from '../../../components/protectedRoute';
|
||||||
import ConfirmationModal from '../../../components/ConfirmationModal';
|
import ConfirmationModal from '../../../components/ConfirmationModal';
|
||||||
import axiosServer from '../../../src/axiosServer';
|
|
||||||
|
|
||||||
|
|
||||||
// import { FaPlus, FaCogs, FaTrashAlt, FaSpinner } from 'react-icons/fa'; // Import FontAwesome icons
|
|
||||||
import LocalShippingIcon from '@mui/icons-material/LocalShipping';
|
import LocalShippingIcon from '@mui/icons-material/LocalShipping';
|
||||||
|
|
||||||
|
// import { FaPlus, FaCogs, FaTrashAlt, FaSpinner } from 'react-icons/fa'; // Import FontAwesome icons
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -112,12 +109,6 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
const { data: shiftsForDate } = await axiosInstance.get(`/api/?action=getShiftsForDay&date=${dateStr}`);
|
const { data: shiftsForDate } = await axiosInstance.get(`/api/?action=getShiftsForDay&date=${dateStr}`);
|
||||||
setShifts(shiftsForDate);
|
setShifts(shiftsForDate);
|
||||||
let { data: availablePubsForDate } = await axiosInstance.get(`/api/?action=filterPublishers&assignments=true&availabilities=true&date=${dateStr}&select=id,firstName,lastName,isactive,desiredShiftsPerMonth`);
|
let { data: availablePubsForDate } = await axiosInstance.get(`/api/?action=filterPublishers&assignments=true&availabilities=true&date=${dateStr}&select=id,firstName,lastName,isactive,desiredShiftsPerMonth`);
|
||||||
availablePubsForDate.forEach(pub => {
|
|
||||||
pub.canTransport = pub.availabilities.some(av =>
|
|
||||||
av.isWithTransportIn || av.isWithTransportOut
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
//remove availabilities that are isFromPreviousAssignment or from previous month for each publisher
|
//remove availabilities that are isFromPreviousAssignment or from previous month for each publisher
|
||||||
// availablePubsForDate = availablePubsForDate.map(pub => {
|
// availablePubsForDate = availablePubsForDate.map(pub => {
|
||||||
// pub.availabilities = pub.availabilities.filter(avail => avail.isFromPreviousAssignment == false);
|
// pub.availabilities = pub.availabilities.filter(avail => avail.isFromPreviousAssignment == false);
|
||||||
@ -150,6 +141,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
);
|
);
|
||||||
if (av) {
|
if (av) {
|
||||||
pub.isAvailableForShift = true;
|
pub.isAvailableForShift = true;
|
||||||
|
pub.canTransport = av.isWithTransportIn || av.isWithTransportOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const isAvailableForShift = pub.availabilities.some(avail =>
|
// const isAvailableForShift = pub.availabilities.some(avail =>
|
||||||
@ -335,7 +327,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
var classname = "";
|
var classname = "";
|
||||||
|
|
||||||
if (events == null) {
|
if (events == null) {
|
||||||
return <div>{" - "}</div>;
|
return <div>{" "}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = events.find((event) => {
|
const event = events.find((event) => {
|
||||||
@ -682,7 +674,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
>
|
>
|
||||||
<span className={`text-gray-700 ${pub.isAvailableForShift ? 'font-bold' : 'font-medium'} `}>
|
<span className={`text-gray-700 ${pub.isAvailableForShift ? 'font-bold' : 'font-medium'} `}>
|
||||||
{pub.firstName} {pub.lastName}
|
{pub.firstName} {pub.lastName}
|
||||||
{pub.canTransport && (<LocalShippingIcon className="mx-1 text-gray-500" />)}
|
{pub.canTransport && (<LocalShippingIcon className="mx-2 text-gray-500" />)}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex space-x-1 overflow-hidden">
|
<div className="flex space-x-1 overflow-hidden">
|
||||||
<span title="Възможност: часове | дни" className={`badge py-1 px-2 rounded-md text-xs ${pub.currentMonthAvailabilityHoursCount || pub.currentMonthAvailabilityDaysCount ? 'bg-teal-500 text-white' : 'bg-teal-200 text-gray-300'} hover:underline`} >
|
<span title="Възможност: часове | дни" className={`badge py-1 px-2 rounded-md text-xs ${pub.currentMonthAvailabilityHoursCount || pub.currentMonthAvailabilityDaysCount ? 'bg-teal-500 text-white' : 'bg-teal-200 text-gray-300'} hover:underline`} >
|
||||||
@ -713,6 +705,10 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{/* <CustomCalendar date={value} shifts={shifts} /> */}
|
||||||
|
</div>
|
||||||
{isModalOpen && <PublisherShiftsModal publisher={modalPub} shifts={allShifts} onClose={() => setIsModalOpen(false)} />}
|
{isModalOpen && <PublisherShiftsModal publisher={modalPub} shifts={allShifts} onClose={() => setIsModalOpen(false)} />}
|
||||||
</ProtectedRoute >
|
</ProtectedRoute >
|
||||||
</Layout >
|
</Layout >
|
||||||
@ -859,3 +855,69 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import axiosServer from '../../../src/axiosServer';
|
||||||
|
import { start } from 'repl';
|
||||||
|
export const getServerSideProps = async (context) => {
|
||||||
|
const axios = await axiosServer(context);
|
||||||
|
const baseUrl = common.getBaseUrl();
|
||||||
|
console.log('runtime BaseUrl: ' + baseUrl);
|
||||||
|
console.log('runtime NEXTAUTH_URL: ' + process.env.NEXTAUTH_URL);
|
||||||
|
console.log('Runtime Axios Base URL:', axios.defaults.baseURL);
|
||||||
|
|
||||||
|
const currentDate = new Date();
|
||||||
|
const firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() - 3, 1);
|
||||||
|
const lastDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0); // 0th day of the next month gives the last day of the current month
|
||||||
|
|
||||||
|
const url = `/api/data/shifts?where={"startTime":{"$and":[{"$gte":"${common.getISODateOnly(firstDayOfMonth)}","$lt":"${common.getISODateOnly(lastDayOfMonth)}"}]}}`;
|
||||||
|
|
||||||
|
const prismaClient = common.getPrismaClient();
|
||||||
|
// let events = await prismaClient.cartEvent.findMany({ where: { isactive: true } });
|
||||||
|
// events = events.map(event => ({
|
||||||
|
// ...event,
|
||||||
|
// // Convert Date objects to ISO strings
|
||||||
|
// startTime: event.startTime.toISOString(),
|
||||||
|
// endTime: event.endTime.toISOString(),
|
||||||
|
// }));
|
||||||
|
const { data: events } = await axios.get(`/api/data/cartevents?where={"isactive":true}`);
|
||||||
|
//const { data: shifts } = await axios.get(url);
|
||||||
|
|
||||||
|
// get all shifts for the month, including assigments
|
||||||
|
let shifts = await prismaClient.shift.findMany({
|
||||||
|
where: {
|
||||||
|
isactive: true,
|
||||||
|
startTime: {
|
||||||
|
gte: firstDayOfMonth,
|
||||||
|
//lt: lastDayOfMonth
|
||||||
|
}
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
assignments: {
|
||||||
|
include: {
|
||||||
|
publisher: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//calculate assCount for each shift
|
||||||
|
shifts = shifts.map(shift => ({
|
||||||
|
...shift,
|
||||||
|
assignedCount: shift.assignments.length,
|
||||||
|
startTime: shift.startTime.toISOString(),
|
||||||
|
endTime: shift.endTime.toISOString(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
initialEvents: events,
|
||||||
|
initialShifts: shifts,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user