schedule is now published to be visible to the public
This commit is contained in:
@ -7,6 +7,7 @@ const subq = require('../../prisma/bl/subqueries');
|
|||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { all } from "axios";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -29,7 +30,7 @@ export default async function handler(req, res) {
|
|||||||
|
|
||||||
var action = req.query.action;
|
var action = req.query.action;
|
||||||
var filter = req.query.filter;
|
var filter = req.query.filter;
|
||||||
let date: Date;
|
let date: Date, monthInfo: any;
|
||||||
if (req.query.date) {
|
if (req.query.date) {
|
||||||
date = new Date(req.query.date);
|
date = new Date(req.query.date);
|
||||||
//date.setDate(date.getDate()); // Subtract one day to get the correct date, as calendar sends wrong date (one day ahead)
|
//date.setDate(date.getDate()); // Subtract one day to get the correct date, as calendar sends wrong date (one day ahead)
|
||||||
@ -77,7 +78,7 @@ export default async function handler(req, res) {
|
|||||||
//gets publisher by names with availabilities and assignments
|
//gets publisher by names with availabilities and assignments
|
||||||
case "deleteAvailabilityForPublisher":
|
case "deleteAvailabilityForPublisher":
|
||||||
let publisherId = req.query.publisherId;
|
let publisherId = req.query.publisherId;
|
||||||
let dateFor, monthInfo;
|
let dateFor;
|
||||||
if (req.query.date) {
|
if (req.query.date) {
|
||||||
dateFor = new Date(req.query.date);
|
dateFor = new Date(req.query.date);
|
||||||
//get month info from date
|
//get month info from date
|
||||||
@ -212,11 +213,31 @@ export default async function handler(req, res) {
|
|||||||
|
|
||||||
case "replaceInAssignment":
|
case "replaceInAssignment":
|
||||||
const { oldPublisherId, newPublisherId, shiftId } = req.method === "POST" ? req.body : req.query;
|
const { oldPublisherId, newPublisherId, shiftId } = req.method === "POST" ? req.body : req.query;
|
||||||
const prisma = common.getPrismaClient();
|
|
||||||
const result = await replaceInAssignment(oldPublisherId, newPublisherId, shiftId);
|
const result = await replaceInAssignment(oldPublisherId, newPublisherId, shiftId);
|
||||||
res.status(200).json(result);
|
res.status(200).json(result);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "updateShifts":
|
||||||
|
//get all shifts for the month and publish them (we pass date )
|
||||||
|
let monthInfo = common.getMonthDatesInfo(date);
|
||||||
|
let isPublished = common.parseBool(req.query.isPublished);
|
||||||
|
let updated = await prisma.shift.updateMany({
|
||||||
|
where: {
|
||||||
|
startTime: {
|
||||||
|
gte: new Date(monthInfo.firstMonday.getFullYear(), monthInfo.firstMonday.getMonth(), 1),
|
||||||
|
lt: new Date(monthInfo.lastSunday.getFullYear(), monthInfo.lastSunday.getMonth() + 1, 1),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isPublished: isPublished
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log("Updated shifts: " + updated.count);
|
||||||
|
res.status(200).json({ "message": "ok" });
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
"message": "no action '" + action + "' found"
|
"message": "no action '" + action + "' found"
|
||||||
|
@ -90,6 +90,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const shifts = await prisma.shift.findMany({
|
const shifts = await prisma.shift.findMany({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
isPublished: true,
|
||||||
startTime: {
|
startTime: {
|
||||||
gte: fromDate,
|
gte: fromDate,
|
||||||
lt: toDate,
|
lt: toDate,
|
||||||
|
@ -57,7 +57,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
|
|
||||||
|
|
||||||
const [allShifts, setAllShifts] = useState(initialShifts);
|
const [allShifts, setAllShifts] = useState(initialShifts);
|
||||||
const [value, onChange] = useState<Date>(new Date());
|
const [isPublished, setIsPublished] = useState(() => initialShifts.some(shift => shift.isPublished)); const [value, onChange] = useState<Date>(new Date());
|
||||||
const [shifts, setShifts] = React.useState([]);
|
const [shifts, setShifts] = React.useState([]);
|
||||||
const [error, setError] = React.useState(null);
|
const [error, setError] = React.useState(null);
|
||||||
const [availablePubs, setAvailablePubs] = React.useState([]);
|
const [availablePubs, setAvailablePubs] = React.useState([]);
|
||||||
@ -108,6 +108,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
try {
|
try {
|
||||||
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);
|
||||||
|
setIsPublished(shiftsForDate.some(shift => shift.isPublished));
|
||||||
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 => {
|
availablePubsForDate.forEach(pub => {
|
||||||
@ -511,6 +512,18 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const togglePublished = async () => {
|
||||||
|
try {
|
||||||
|
const publishState = !isPublished; // Toggle the state
|
||||||
|
const isPublishedParam = publishState ? 'true' : 'fasle';
|
||||||
|
await axiosInstance.get(`/api/?action=updateShifts&isPublished=${isPublishedParam}&date=${common.getISODateOnly(value)}`);
|
||||||
|
setIsPublished(publishState); // Update state based on the action
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
@ -550,6 +563,12 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
|
|||||||
}}
|
}}
|
||||||
message="Това ще изпрати имейли до всички участници за смените им през избрания месец. Сигурни ли сте?"
|
message="Това ще изпрати имейли до всички участници за смените им през избрания месец. Сигурни ли сте?"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
|
className={`button btn m-2 ${isPublished ? 'hover:bg-gray-100 bg-yellow-500' : 'hover:bg-red-300 bg-blue-400'}`}
|
||||||
|
onClick={togglePublished}>
|
||||||
|
<i className={`fas ${isPublished ? 'fa-check' : 'fa-close'} mr-2`}></i>
|
||||||
|
{isPublished ? "Скрий" : "Публикувай"} графика (м.)
|
||||||
|
</button>
|
||||||
<div className="relative inline-block text-left">
|
<div className="relative inline-block text-left">
|
||||||
<button
|
<button
|
||||||
className={`button m-2 ${isMenuOpen ? 'bg-gray-400 border border-blue-500' : 'bg-gray-300'} hover:bg-gray-400`}
|
className={`button m-2 ${isMenuOpen ? 'bg-gray-400 border border-blue-500' : 'bg-gray-300'} hover:bg-gray-400`}
|
||||||
|
@ -41,7 +41,7 @@ function ContactsPage({ publishers }) {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{filteredPublishers.map((pub) => (
|
{filteredPublishers.map((pub) => (
|
||||||
<tr key={pub.id}>
|
<tr key={pub.id}>
|
||||||
<td className="border-b p-4 pl-8">{pub.firstName} {pub.lastName}</td>
|
<td className="border-b p-4 pl-8" title={pub.lastUpdate}>{pub.firstName} {pub.lastName}</td>
|
||||||
<td className="border-b p-4">
|
<td className="border-b p-4">
|
||||||
<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`} >
|
||||||
{pub.currentMonthAvailabilityDaysCount || 0} | {pub.currentMonthAvailabilityHoursCount || 0}
|
{pub.currentMonthAvailabilityDaysCount || 0} | {pub.currentMonthAvailabilityHoursCount || 0}
|
||||||
@ -84,6 +84,13 @@ export const getServerSideProps = async (context) => {
|
|||||||
publisher.desiredShiftsPerMonth = publisher.desiredShiftsPerMonth || 0;
|
publisher.desiredShiftsPerMonth = publisher.desiredShiftsPerMonth || 0;
|
||||||
publisher.assignments = publisher.assignments || [];
|
publisher.assignments = publisher.assignments || [];
|
||||||
publisher.availabilities = publisher.availabilities || [];
|
publisher.availabilities = publisher.availabilities || [];
|
||||||
|
publisher.lastUpdate = publisher.availabilities.reduce((acc, curr) => curr.dateOfEntry > acc ? curr.dateOfEntry : acc, null);
|
||||||
|
if (publisher.lastUpdate) {
|
||||||
|
publisher.lastUpdate = common.getDateFormated(publisher.lastUpdate);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
publisher.lastUpdate = "Няма данни";
|
||||||
|
}
|
||||||
//serialize dates in publisher.assignments and publisher.availabilities
|
//serialize dates in publisher.assignments and publisher.availabilities
|
||||||
publisher.assignments.forEach(assignment => {
|
publisher.assignments.forEach(assignment => {
|
||||||
if (assignment.shift && assignment.shift.startTime) {
|
if (assignment.shift && assignment.shift.startTime) {
|
||||||
|
Reference in New Issue
Block a user