(wip) schedle generation;

added confirmations on schedule  DELETE!!!
better reports page;
log every delete over API, more logging;
This commit is contained in:
Dobromir Popov
2024-05-24 12:53:17 +03:00
parent 73ac798a6d
commit 2202e8b1b4
9 changed files with 166 additions and 64 deletions

View File

@ -434,9 +434,8 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
setActiveButton(null);
}
}
const deleteShifts = async (buttonId, forDay: Boolean) => {
const deleteShifts = async (forDay: Boolean) => {
try {
setActiveButton(buttonId);
await axiosInstance.get(`/api/shiftgenerate?action=delete&date=${common.getISODateOnly(value)}&forDay=${forDay}`);
toast.success('Готово!', { autoClose: 1000 });
setIsMenuOpen(false);
@ -533,7 +532,29 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [isConfirmModalOpen, setConfirmModalOpen] = useState(false);
const [confirmModalProps, setConfirmModalProps] = useState({
isOpen: false,
message: '',
onConfirm: () => { }
});
const openConfirmModal = (message, action, actionName) => {
if (actionName) {
setActiveButton(actionName);
}
setConfirmModalProps({
isOpen: true,
message: message,
onConfirm: () => {
toast.info('Потвърдено!', { autoClose: 2000 });
setConfirmModalProps((prevProps) => ({ ...prevProps, isOpen: false }));
action();
},
});
};
//const [isConfirmModalDeletOpen, setConfirmModalDeleteOpen] = useState(false);
async function copyOldAvailabilities(event: MouseEvent<HTMLButtonElement, MouseEvent>): Promise<void> {
await axiosInstance.get(`/api/?action=copyOldAvailabilities&date=${common.getISODateOnly(value)}`);
}
@ -592,10 +613,16 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
<button className="button btn m-2 bg-blue-800" onClick={generateDOCX}>
{isLoading('generateDOCX') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fa fa-file-export"></i>)}Експорт в Word
</button>
<button className="button btn m-2 bg-yellow-500 hover:bg-yellow-600 text-white" onClick={() => { setActiveButton("sendEmails"); setConfirmModalOpen(true) }}>
<button className="button btn m-2 bg-yellow-500 hover:bg-yellow-600 text-white"
onClick={() => openConfirmModal(
'Това ще изпрати имейли до всички участници за смените им през избрания месец. Сигурни ли сте?',
() => sendMails(),
"sendEmails"
)}
>
{isLoading('sendEmails') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-envelope mr-2"></i>)} изпрати мейли!
</button>
<ConfirmationModal
{/* <ConfirmationModal
isOpen={isConfirmModalOpen}
onClose={() => setConfirmModalOpen(false)}
onConfirm={() => {
@ -604,7 +631,14 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
sendMails()
}}
message="Това ще изпрати имейли до всички участници за смените им през избрания месец. Сигурни ли сте?"
/> */}
<ConfirmationModal
isOpen={confirmModalProps.isOpen}
onClose={() => setConfirmModalProps((prevProps) => ({ ...prevProps, isOpen: false }))}
onConfirm={confirmModalProps.onConfirm}
message={confirmModalProps.message}
/>
<button
className={`button btn m-2 ${isPublished ? 'hover:bg-gray-500 bg-yellow-500' : 'hover:bg-red-300 bg-blue-400'}`}
onClick={togglePublished}>
@ -627,7 +661,13 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
<button className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" onClick={() => generateShifts("genDay", false, true, true)}>
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
Генерирай смени ({value.getDate()}-ти) </button>
<button className="block px-4 py-2 text-sm text-red-500 hover:bg-gray-100" onClick={() => { deleteShifts("deleteShiftsDay", true) }}>
<button className="block px-4 py-2 text-sm text-red-500 hover:bg-gray-100"
onClick={() => openConfirmModal(
'Сигурни ли сте че искате да изтриете смените и назначения на този ден?',
() => deleteShifts(true),
"deleteShiftsDay"
)}
>
{isLoading('deleteShiftsDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-trash-alt mr-2"></i>)}
изтрий смените ({value.getDate()}-ти)</button>
@ -641,11 +681,16 @@ export default function CalendarPage({ initialEvents, initialShifts }) {
<button className="block w-full px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center" onClick={() => generateShifts("genDay", true, true)}>
{isLoading('genDay') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-cogs mr-2"></i>)}
Генерирай смени </button>
<button className="block px-4 py-2 text-sm text-red-500 hover:bg-gray-100" onClick={() => { deleteShifts("deleteShifts", false) }}>
<button className="block px-4 py-2 text-sm text-red-500 hover:bg-gray-100"
onClick={() => openConfirmModal(
'Сигурни ли сте че искате да изтриете ВСИЧКИ смени и назначения за месеца?',
() => deleteShifts(false),
"deleteShifts"
)}
>
{isLoading('deleteShifts') ? (<i className="fas fa-sync-alt fa-spin mr-2"></i>) : (<i className="fas fa-trash-alt mr-2"></i>)}
изтрий смените</button>
<hr className="my-1" />
<button className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" onClick={generateXLS}><i className="fas fa-file-excel mr-2"></i> Генерирай XLSX</button>