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