diff --git a/_doc/ToDo.md b/_doc/ToDo.md index fe76dd6..123edcb 100644 --- a/_doc/ToDo.md +++ b/_doc/ToDo.md @@ -228,3 +228,8 @@ last login. pubs. otchet - za denq делете цонфирм статистика - фкс (янка) + posledno vlizane + +заместник, предпочитание в миналото - да не може. +Да иска потвърждение преди да заместиш някой +да не се виждат непубликуваните смени в Моите смени +да не се виждат старите предпочитания ако не си админ в публишерс \ No newline at end of file diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index ce2ce5f..839b55e 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -286,7 +286,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o const slots = []; let currentTime = start; - const baseDate = new Date(2000, 0, 1); // Use a constant date for all time comparisons + const baseDate = new Date(Date.UTC(2000, 0, 1, 0, 0, 0)); while (isBefore(currentTime, end)) { let slotStart = normalizeTime(currentTime, baseDate); diff --git a/components/availability/AvailabilityList.js b/components/availability/AvailabilityList.js index cb9cc56..99bd3b0 100644 --- a/components/availability/AvailabilityList.js +++ b/components/availability/AvailabilityList.js @@ -9,6 +9,7 @@ const common = require('src/helpers/common'); import AvailabilityForm from "../availability/AvailabilityForm"; import { TrashIcon, PencilSquareIcon } from "@heroicons/react/24/outline"; +import { Availability, AvailabilityType } from "@prisma/client"; @@ -58,7 +59,10 @@ export default function AvailabilityList({ publisher, showNew }) { {items?.sort((a, b) => new Date(a.startTime) - new Date(b.startTime)).map(item => ( - {item.dayOfMonth ? `${common.getDateFormated(new Date(item.startTime))}` : `Всеки(Всяка) ${common.getDayOfWeekName(new Date(item.startTime))}`} + {item.type == AvailabilityType.OneTime ? `${common.getDateFormated(new Date(item.startTime))}` : + item.type == AvailabilityType.Weekly ? `Всеки(Всяка) ${common.getDayOfWeekName(new Date(item.startTime))}` : "месечно" + + } {/* {common.getDateFormated(new Date(item.startTime))} */} @@ -118,14 +122,14 @@ export default function AvailabilityList({ publisher, showNew }) { } -export const getServerSideProps = async () => { - const { data: items } = await axiosInstance.get( - common.getBaseUrl("/api/data/availabilities") - ); +// export const getServerSideProps = async () => { +// const { data: items } = await axiosInstance.get( +// common.getBaseUrl("/api/data/availabilities") +// ); - return { - props: { - items, - }, - }; -}; \ No newline at end of file +// return { +// props: { +// items, +// }, +// }; +// }; \ No newline at end of file diff --git a/components/calendar/avcalendar.tsx b/components/calendar/avcalendar.tsx index b77c138..258463c 100644 --- a/components/calendar/avcalendar.tsx +++ b/components/calendar/avcalendar.tsx @@ -211,7 +211,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { if (!start || !end) return; //readonly for past dates (ToDo: if not admin) - //if (startdate < new Date() || end < new Date() || startdate > end) return; + if (startdate < new Date() || end < new Date() || startdate > end) return; // Check if start and end are on the same day if (startdate.toDateString() !== enddate.toDateString()) { @@ -275,6 +275,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { }; + // REDRAW (PAGING) STYLES FOR THE EVENT DEFINED HERE const eventStyleGetter = (event, start, end, isSelected) => { //console.log("eventStyleGetter: " + event); @@ -296,10 +297,13 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { //gray backgroundColor = '#a0aec0'; } + + if (event.isActive) { switch (event.type) { case 'assignment': - backgroundColor = event.isConfirmed ? '#48bb78' : '#f6e05e'; // green-500 and yellow-300 from Tailwind CSS + // backgroundColor = '#48bb78' // always green-500 as we don't pass isConfirmed correctly + //backgroundColor = event.isConfirmed ? '#48bb78' : '#f6e05e'; // green-500 and yellow-300 from Tailwind CSS break; case 'recurring': backgroundColor = '#63b3ed'; // blue-300 from Tailwind CSS @@ -315,7 +319,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { return { style: { backgroundColor, - opacity: 0.8, + opacity: event.startTime < new Date() ? 0.5 : 1, color: 'white', border: '0px', display: 'block', @@ -323,7 +327,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { }; } - // Custom Components + // INITIAL STYLE FOR THE EVENT DEFINED HERE const EventWrapper = ({ event, style }) => { const [isHovered, setIsHovered] = useState(false); let eventStyle = { @@ -342,7 +346,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { // bgColor = "bg-orange-500"; // } if (event.type === "assignment") { - bgColor = event.isBySystem ? "bg-red-500" : (event.isConfirmed ? "bg-green-500" : "bg-yellow-500"); + bgColor = event.isBySystem ? "bg-red-500" : (event.isConfirmed || true ? "bg-green-500" : "bg-yellow-500"); //event.title = event.publisher.name; //ToDo: add other publishers names //event.title = common.getTimeFomatted(event.startTime) + " - " + common.getTimeFomatted(event.endTime); @@ -365,6 +369,7 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { } } + eventStyle = { ...style, // backgroundColor: bgColorClass, @@ -376,7 +381,9 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => { overflow: 'hidden', // Hide overflowed content textOverflow: 'ellipsis' // Add ellipsis to text that's too long to fit }; - + if (event.date < new Date()) { + eventStyle.opacity = 0.5; + } } const onDelete = (event) => { diff --git a/pages/cart/publishers/edit/[id].tsx b/pages/cart/publishers/edit/[id].tsx index 0e93b9a..aca5b00 100644 --- a/pages/cart/publishers/edit/[id].tsx +++ b/pages/cart/publishers/edit/[id].tsx @@ -2,7 +2,7 @@ import axiosServer from '../../../../src/axiosServer'; import NewPubPage from "../new"; export default NewPubPage; -import { Assignment, Shift, UserRole } from "prisma/prisma-client"; +import { Assignment, Shift, UserRole, AvailabilityType } from "prisma/prisma-client"; // import { monthNamesBG } from "~/src/helpers/const" import { monthNamesBG } from "src/helpers/const"; @@ -55,6 +55,7 @@ export const getServerSideProps = async (context) => { // item.availabilities = item.availabilities // .sort((a, b) => b.startTime - a.startTime); + item.availabilities = item.availabilities.filter((a) => new Date(a.startTime) >= new Date() || a.type == AvailabilityType.Weekly); item.assignments = item.assignments .sort((a, b) => b.startTime - a.startTime) .reduce((acc, assignment: Assignment) => { diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 7fd01b3..d994f9a 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -87,30 +87,33 @@ export default function MySchedulePage({ assignments }) { )} -
-
Действия
-
- - + {!assignment.isOld && - -
-
+
+
Действия
+
+ + + + +
+
+ } @@ -205,22 +208,25 @@ export const getServerSideProps = async (context) => { }, }); - const assignments = publisher?.assignments.filter(assignment => assignment.shift.startTime >= lastSunday) || []; + const assignments = publisher?.assignments.filter(a => a.shift.startTime >= lastSunday && a.shift.isPublished) || []; - const transformedAssignments = assignments?.map(assignment => { - if (assignment.shift && assignment.shift.startTime) { - return { - ...assignment, - dateStr: assignment.shift.startTime.toLocaleDateString("bg-BG", { day: "numeric", month: "long" }), - shift: { - ...assignment.shift, - startTime: assignment.shift.startTime.toISOString(), - endTime: assignment.shift.endTime.toISOString(), - }, - }; - } - return assignment; - }); + + const transformedAssignments = assignments?.sort((a, b) => a.shift.startTime - b.shift.startTime) + .map(assignment => { + if (assignment.shift && assignment.shift.startTime) { + return { + ...assignment, + isOld: assignment.shift.startTime < new Date(), + dateStr: assignment.shift.startTime.toLocaleDateString("bg-BG", { day: "numeric", month: "long" }), + shift: { + ...assignment.shift, + startTime: assignment.shift.startTime.toISOString(), + endTime: assignment.shift.endTime.toISOString(), + }, + }; + } + return assignment; + }); diff --git a/pages/cart/publishers/new.tsx b/pages/cart/publishers/new.tsx index c0b1988..14e5dad 100644 --- a/pages/cart/publishers/new.tsx +++ b/pages/cart/publishers/new.tsx @@ -38,22 +38,24 @@ export default function NewPubPage(item: Publisher) { //------------------pages\cart\publishers\edit\[id].tsx------------------ -export const getServerSideProps = async (context) => { - const axios = await axiosServer(context); +// export const getServerSideProps = async (context) => { +// const axios = await axiosServer(context); - context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate"); - if (!context.query || !context.query.id) { - return { - props: {} - }; - } - var url = process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/publishers/" + context.query.id + "?include=availabilities,shifts"; - console.log("GET PUBLISHER FROM:" + url) - const { data } = await axios.get(url); +// context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate"); +// if (!context.query || !context.query.id) { +// return { +// props: {} +// }; +// } +// var url = process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/publishers/" + context.query.id + "?include=availabilities,shifts"; +// console.log("GET PUBLISHER FROM:" + url) +// const { data } = await axios.get(url); - return { - props: { - data - }, - }; -}; +// //filter old availabilities +// data.availabilities = data.availabilities.filter((a) => new Date(a.startTime) >= new Date()); +// return { +// props: { +// data +// }, +// }; +// };