use material icon for transport;
transport icon on all available pubs for transport
This commit is contained in:
@ -14,8 +14,12 @@ const common = require('src/helpers/common');
|
||||
import { toast } from 'react-toastify';
|
||||
import ProtectedRoute from '../../../components/protectedRoute';
|
||||
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';
|
||||
|
||||
|
||||
|
||||
|
||||
@ -108,6 +112,12 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
const { data: shiftsForDate } = await axiosInstance.get(`/api/?action=getShiftsForDay&date=${dateStr}`);
|
||||
setShifts(shiftsForDate);
|
||||
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
|
||||
// availablePubsForDate = availablePubsForDate.map(pub => {
|
||||
// pub.availabilities = pub.availabilities.filter(avail => avail.isFromPreviousAssignment == false);
|
||||
@ -134,22 +144,30 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
const handleShiftSelection = (selectedShift) => {
|
||||
setSelectedShiftId(selectedShift.id);
|
||||
const updatedPubs = availablePubs.map(pub => {
|
||||
const isAvailableForShift = pub.availabilities.some(avail =>
|
||||
const av = pub.availabilities?.find(avail =>
|
||||
avail.startTime <= selectedShift.startTime
|
||||
&& avail.endTime >= selectedShift.endTime
|
||||
&& avail.isFromPreviousAssignment == false
|
||||
);
|
||||
if (av) {
|
||||
pub.isAvailableForShift = true;
|
||||
}
|
||||
|
||||
// const isAvailableForShift = pub.availabilities.some(avail =>
|
||||
// avail.startTime <= selectedShift.startTime
|
||||
// && avail.endTime >= selectedShift.endTime
|
||||
// && avail.isFromPreviousAssignment == false
|
||||
// );
|
||||
const isAvailableForShiftWithPrevious = pub.availabilities.some(avail =>
|
||||
avail.startTime <= selectedShift.startTime
|
||||
&& avail.endTime >= selectedShift.endTime
|
||||
);
|
||||
//! console.log(`Publisher ${pub.firstName} ${pub.lastName} is available for shift ${selectedShift.id}: ${isAvailableForShift}`);
|
||||
//// console.log(`Publisher ${pub.firstName} ${pub.lastName} has ${pub.availabilities.length} availabilities :` + pub.availabilities.map(avail => avail.startTime + " - " + avail.endTime));
|
||||
//// console.log(`Publisher ${pub.firstName} ${pub.lastName} has ${pub.availabilities.length} availabilities :` + stringify.join(', 'pub.availabilities.map(avail => avail.id)));
|
||||
// //! console.log(`Publisher ${pub.firstName} ${pub.lastName} is available for shift ${selectedShift.id}: ${isAvailableForShift}`);
|
||||
// //// console.log(`Publisher ${pub.firstName} ${pub.lastName} has ${pub.availabilities.length} availabilities :` + pub.availabilities.map(avail => avail.startTime + " - " + avail.endTime));
|
||||
// //// console.log(`Publisher ${pub.firstName} ${pub.lastName} has ${pub.availabilities.length} availabilities :` + stringify.join(', 'pub.availabilities.map(avail => avail.id)));
|
||||
|
||||
const availabilitiesIds = pub.availabilities.map(avail => avail.id).join(', ');
|
||||
//! console.log(`Publisher ${pub.firstName} ${pub.lastName} has ${pub.availabilities.length} availabilities with IDs: ${availabilitiesIds}`);
|
||||
return { ...pub, isAvailableForShift, isAvailableForShiftWithPrevious, isSelected: pub.id === selectedShift.selectedPublisher?.id };
|
||||
// const availabilitiesIds = pub.availabilities.map(avail => avail.id).join(', ');
|
||||
// //! console.log(`Publisher ${pub.firstName} ${pub.lastName} has ${pub.availabilities.length} availabilities with IDs: ${availabilitiesIds}`);
|
||||
return { ...pub, isAvailableForShiftWithPrevious, isSelected: pub.id === selectedShift.selectedPublisher?.id };
|
||||
});
|
||||
|
||||
// Sort publishers based on their availability state. use currentDayAssignments, currentWeekAssignments,
|
||||
@ -317,7 +335,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
var classname = "";
|
||||
|
||||
if (events == null) {
|
||||
return <div>{" "}</div>;
|
||||
return <div>{" - "}</div>;
|
||||
}
|
||||
|
||||
const event = events.find((event) => {
|
||||
@ -664,6 +682,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
>
|
||||
<span className={`text-gray-700 ${pub.isAvailableForShift ? 'font-bold' : 'font-medium'} `}>
|
||||
{pub.firstName} {pub.lastName}
|
||||
{pub.canTransport && (<LocalShippingIcon className="mx-1 text-gray-500" />)}
|
||||
</span>
|
||||
<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`} >
|
||||
@ -694,10 +713,6 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{/* <CustomCalendar date={value} shifts={shifts} /> */}
|
||||
</div>
|
||||
{isModalOpen && <PublisherShiftsModal publisher={modalPub} shifts={allShifts} onClose={() => setIsModalOpen(false)} />}
|
||||
</ProtectedRoute >
|
||||
</Layout >
|
||||
@ -844,69 +859,3 @@ 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