diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx
index 2918f7b..b96a76c 100644
--- a/pages/cart/publishers/myschedule.tsx
+++ b/pages/cart/publishers/myschedule.tsx
@@ -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
Loading...
;
}
+ 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 (
@@ -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}
/>
+
+ { setIsConfirmModalOpen(false); setNewPublisher(null); }}
+ onConfirm={handleReplaceInAssignment}
+ message="Това действие ще те замести в назначената ти смяна. Погвърждаваш ли, че заместника знае за тази промяна."
+ />
);