replacement confrmation
This commit is contained in:
@ -5,6 +5,7 @@ import { UserRole } from '@prisma/client';
|
||||
import axiosServer from '../../../src/axiosServer';
|
||||
import common from '../../../src/helpers/common';
|
||||
import Modal from 'components/Modal';
|
||||
import ConfirmationModal from 'components/ConfirmationModal';
|
||||
import PublisherSearchBox from '../../../components/publisher/PublisherSearchBox'; // Update the path
|
||||
|
||||
import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const"
|
||||
@ -16,14 +17,40 @@ import LocalShippingIcon from '@mui/icons-material/LocalShipping';
|
||||
export default function MySchedulePage({ assignments }) {
|
||||
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false);
|
||||
const [useFilterDate, setUseFilterDate] = useState(true);
|
||||
const [assignment, setАssignment] = useState(null);
|
||||
const [newPublisher, setNewPublisher] = useState(null);
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
if (status === "loading") {
|
||||
return <div className="flex justify-center items-center h-screen">Loading...</div>;
|
||||
}
|
||||
|
||||
const handleReplaceInAssignment = () => {
|
||||
// Add publisher as assignment logic
|
||||
setIsModalOpen(false);
|
||||
setIsConfirmModalOpen(false);
|
||||
console.log("publisher", newPublisher.firstName, " ", newPublisher.lastName, " set to shift ", assignment.shift.id);
|
||||
//api.replaceInAssignment()
|
||||
axiosInstance.post('/api/?action=replaceInAssignment', {
|
||||
oldPublisherId: session.user.id,
|
||||
newPublisherId: newPublisher.id,
|
||||
shiftId: assignment.shift.id,
|
||||
}).then(response => {
|
||||
console.log("response", response);
|
||||
//toast success and confirm the change
|
||||
// refresh the page after toast is closed
|
||||
toast.success("Промяната е записана!", {
|
||||
onClose: () => {
|
||||
window.location.reload();
|
||||
|
||||
}
|
||||
});
|
||||
}).catch(error => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER, UserRole.USER]}>
|
||||
@ -99,34 +126,22 @@ export default function MySchedulePage({ assignments }) {
|
||||
isFocused={isModalOpen}
|
||||
filterDate={useFilterDate && assignment ? new Date(assignment.shift.startTime) : null}
|
||||
onChange={(publisher) => {
|
||||
// Add publisher as assignment logic
|
||||
setIsModalOpen(false);
|
||||
console.log("publisher", publisher.firstName, " ", publisher.lastName, " set to shift ", assignment.shift.id);
|
||||
//api.replaceInAssignment()
|
||||
axiosInstance.post('/api/?action=replaceInAssignment', {
|
||||
oldPublisherId: session.user.id,
|
||||
newPublisherId: publisher.id,
|
||||
shiftId: assignment.shift.id,
|
||||
}).then(response => {
|
||||
console.log("response", response);
|
||||
//toast success and confirm the change
|
||||
// refresh the page after toast is closed
|
||||
toast.success("Промяната е записана!", {
|
||||
onClose: () => {
|
||||
window.location.reload();
|
||||
setIsConfirmModalOpen(true);
|
||||
setNewPublisher(publisher);
|
||||
|
||||
}
|
||||
});
|
||||
}).catch(error => {
|
||||
console.log("error", error);
|
||||
});
|
||||
//addAssignment(publisher, shift.id);
|
||||
}}
|
||||
showAllAuto={true}
|
||||
showSearch={true}
|
||||
showList={false}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
<ConfirmationModal
|
||||
isOpen={isConfirmModalOpen}
|
||||
onClose={() => { setIsConfirmModalOpen(false); setNewPublisher(null); }}
|
||||
onConfirm={handleReplaceInAssignment}
|
||||
message="Това действие ще те замести в назначената ти смяна. Погвърждаваш ли, че заместника знае за тази промяна."
|
||||
/>
|
||||
</ProtectedRoute>
|
||||
</Layout>
|
||||
);
|
||||
|
Reference in New Issue
Block a user