Merge branch 'main' into production

This commit is contained in:
Dobromir Popov
2024-04-20 14:06:06 +03:00
3 changed files with 36 additions and 3 deletions

View File

@ -201,8 +201,8 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
{/* //if shift.isWithTransport, add trnsport button toggle, which sets ass.isWithTransportIn */}
{shift.requiresTransport && (
<span
onClick={ass.canTransport ? () => toggleTransport(ass) : undefined}
className={`material-icons ${ass.isWithTransport ? 'text-green-500 font-bold' : (transportProvided ? 'text-gray-400 ' : 'text-orange-400 font-bold')} ${ass.canTransport ? ' cursor-pointer' : 'cursor-not-allowed'} px-3 py-1 ml-2 rounded-md`}
onClick={ass.canTransport || true ? () => toggleTransport(ass) : undefined}
className={`material-icons ${ass.isWithTransport ? 'text-green-500 font-bold' : (transportProvided ? 'text-gray-400 ' : 'text-orange-400 font-bold')} ${ass.canTransport || ass.isWithTransport || true ? ' cursor-pointer' : 'cursor-not-allowed'} px-3 py-1 ml-2 rounded-md`}
>
{ass.isWithTransport ? "транспорт" : ass.canTransport ? "може транспорт" : "без транспорт"} <LocalShippingIcon />
</span>

View File

@ -134,12 +134,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
groupedShifts[day][time] = [];
}
let { notes, notes_bold } = splitNotes(shift.notes);//.substring(Math.max(shift.notes.lastIndexOf("-"), shift.notes.lastIndexOf("")) + 1).trim() || "";
// let { notes, notes_bold } = splitNotes(shift.notes);//.substring(Math.max(shift.notes.lastIndexOf("-"), shift.notes.lastIndexOf("")) + 1).trim() || "";
let notes = "", notes_bold = "";
if (shift.assignments.some(a => a.isWithTransport)) {
if (shift.requiresTransport) {
notes = "Транспорт: ";
notes_bold = " " + shift.assignments.filter(a => a.isWithTransport).map(a => common.getInitials(a.publisher.firstName + " " + a.publisher.lastName)).join(", ");
}
}
let shiftSchedule = {
date: date,
placeOfEvent: shift.cartEvent.location.name,
time: time,
requiresTransport: shift.requiresTransport,
//bold the text after - in the notes
notes: notes,
notes_bold: notes_bold,
@ -162,6 +171,24 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log(err + " " + JSON.stringify(shifts[i]));
}
for (const day in groupedShifts) {
const times = Object.keys(groupedShifts[day]);
for (const time of times) {
const shift = groupedShifts[day][time][0];
if (shift) {
// Determine the first shift of the day if it requires transport
if (time === times[0] && shift.requiresTransport) { // Check if this is the first time slot of the day
shift.notes = "Докарва количка от Люлин -"; // Update the first shift in the first time slot
}
// Determine the last shift of the day if it requires transport
if (time === times[times.length - 1] && shift.requiresTransport) { // Check if this is the last time slot of the day
shift.notes = "Прибира количка в Люлин -"; // Update the last shift in the last time slot
}
}
}
}
// Create the output object in the format of the second JSON file
const monthlySchedule = {
month: common.getMonthName(shifts[0].startTime.getMonth()),
@ -179,6 +206,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log("shift is null");
continue;
}
let weekday = common.getDayOfWeekName(shift.date);
let monthName = common.getMonthName(shift.date.getMonth());
weekday = weekday.charAt(0).toUpperCase() + weekday.slice(1);

View File

@ -746,3 +746,8 @@ exports.getLocalStorage = function (key, defaultValue) {
exports.root = function (req) {
return process.env.NEXT_PUBLIC_PUBLIC_URL;
}
exports.getInitials = function (names) {
const parts = names.split(' ');
return parts.map(part => part[0] + ".").join('');
}