This commit is contained in:
Dobromir Popov
2024-05-28 16:42:24 +03:00
parent 3e6d898f78
commit 9ad77bec38
2 changed files with 34 additions and 38 deletions

View File

@ -151,49 +151,45 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
let borderStyles = '';
let canTransport = false;
if (selectedPublisher && selectedPublisher.id === ass.publisher.id) {
borderStyles += 'border-2 border-blue-300'; // Bottom border for selected publishers
borderStyles += 'bg-blue-200 font-bold '; // Bottom border for selected publishers
}
else {
if (publisherInfo.availabilityCount == 0) //user has never the form
{
borderStyles = 'border-2 border-orange-300 ';
if (publisherInfo.availabilityCount == 0 || !publisherInfo.availabilities || publisherInfo.availabilities.length == 0)
//user has never the filled the avalabilities form or if there is no publisherInfo - draw red border - publisher is no longer available for the day!
{
borderStyles += 'border-2 border-red-500 ';
} else {
// checkig if the publisher is available for this assignment
//ToDo: verify if that check is correct
const av = publisherInfo.availabilities?.find(av =>
av.startTime <= shift.startTime && av.endTime >= shift.endTime
);
if (av) {
borderStyles += 'border-b-2 border-blue-500 '; // Left border for specific availability conditions
ass.canTransport = av.isWithTransportIn || av.isWithTransportOut;
// console.log(publisherInfo.firstName, "available for shift", shift.id, "at", common.getDateFormattedShort(new Date(shift.startTime)), "av-" + av.id, ": a." + common.getTimeFormatted(av.startTime), "<=", common.getTimeFormatted(shift.startTime), "; a." + common.getTimeFormatted(av.endTime), ">=", common.getTimeFormatted(shift.endTime));
}
else {
borderStyles += 'border-l-4 border-red-500 ';
}
else
//if there is no publisherInfo - draw red border - publisher is no longer available for the day!
if (!publisherInfo.availabilities || publisherInfo.availabilities.length == 0) {
borderStyles = 'border-2 border-red-500 ';
}
else {
// checkig if the publisher is available for this assignment
const av = publisherInfo.availabilities?.find(av =>
av.startTime <= shift.startTime && av.endTime >= shift.endTime
);
if (av) {
borderStyles += 'border-l-2 border-blue-500 '; // Left border for specific availability conditions
ass.canTransport = av.isWithTransportIn || av.isWithTransportOut;
}
else {
borderStyles += 'border-l-4 border-red-500 ';
}
if (publisherInfo.hasUpToDateAvailabilities) {
//add green right border
borderStyles += 'border-r-2 border-green-300';
}
if (publisherInfo.hasUpToDateAvailabilities) {
//add green right border
borderStyles += 'border-r-2 border-green-300';
}
//the pub is the same time as last month
// if (publisherInfo.availabilities?.some(av =>
// (!av.dayOfMonth || av.isFromPreviousMonth) &&
// av.startTime <= ass.startTime &&
// av.endTime >= ass.endTime)) {
// borderStyles += 'border-t-2 border-yellow-500 '; // Left border for specific availability conditions
// }
}
//the pub is the same time as last month
// if (publisherInfo.availabilities?.some(av =>
// (!av.dayOfMonth || av.isFromPreviousMonth) &&
// av.startTime <= ass.startTime &&
// av.endTime >= ass.endTime)) {
// borderStyles += 'border-t-2 border-yellow-500 '; // Left border for specific availability conditions
// }
}
return (
<div key={index}
className={`flow rounded-md px-2 py-1 sm:py-0.5 my-1 ${(ass.isConfirmed && !ass.isBySystem) ? 'bg-green-100' : 'bg-gray-100'} ${borderStyles}`}

View File

@ -31,7 +31,7 @@ export default function DashboardPage({ initialItems, initialUserId, cartEvents,
const router = useRouter();
const { newLogin } = router.query;
const { data: session } = useSession();
const [userName, setUserName] = useState(session?.user?.name);
const [userName, setUserName] = useState('');
const [userId, setUserId] = useState(initialUserId);
const [events, setEvents] = useState(initialItems?.map(item => ({
...item,
@ -43,7 +43,7 @@ export default function DashboardPage({ initialItems, initialUserId, cartEvents,
})));
useEffect(() => {
if (session) {
if (session && userName === '' && session.user.name) {
setUserName(session.user.name);
setUserId(session.user.id);
//handleUserSelection({ id: session.user.id, firstName: session.user.name, lastName: '' });