schedule is now published to be visible to the public

This commit is contained in:
Dobromir Popov
2024-03-27 09:05:17 +02:00
parent acd776e988
commit 3ccd9ad106
4 changed files with 53 additions and 5 deletions

View File

@ -57,7 +57,7 @@ export default function CalendarPage({ initialEvents, 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 [error, setError] = React.useState(null);
const [availablePubs, setAvailablePubs] = React.useState([]);
@ -108,6 +108,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
try {
const { data: shiftsForDate } = await axiosInstance.get(`/api/?action=getShiftsForDay&date=${dateStr}`);
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`);
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);
@ -550,6 +563,12 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
}}
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">
<button
className={`button m-2 ${isMenuOpen ? 'bg-gray-400 border border-blue-500' : 'bg-gray-300'} hover:bg-gray-400`}

View File

@ -41,7 +41,7 @@ function ContactsPage({ publishers }) {
<tbody>
{filteredPublishers.map((pub) => (
<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">
<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}
@ -84,6 +84,13 @@ export const getServerSideProps = async (context) => {
publisher.desiredShiftsPerMonth = publisher.desiredShiftsPerMonth || 0;
publisher.assignments = publisher.assignments || [];
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
publisher.assignments.forEach(assignment => {
if (assignment.shift && assignment.shift.startTime) {