show shifts attendees in myshifts
This commit is contained in:
@ -4,13 +4,18 @@ import ProtectedRoute from '../../../components/protectedRoute';
|
||||
import { UserRole } from '@prisma/client';
|
||||
import axiosServer from '../../../src/axiosServer';
|
||||
import common from '../../../src/helpers/common';
|
||||
import ShiftsList from '../../../components/publisher/ShiftsList';
|
||||
import Modal from 'components/Modal';
|
||||
import PublisherSearchBox from '../../../components/publisher/PublisherSearchBox'; // Update the path
|
||||
|
||||
import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const"
|
||||
import { useSession, getSession } from 'next-auth/react';
|
||||
|
||||
export default function MySchedulePage({ assignments }) {
|
||||
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [useFilterDate, setUseFilterDate] = useState(true);
|
||||
const [assignment, setАssignment] = useState(null);
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
if (status === "loading") {
|
||||
return <div className="flex justify-center items-center h-screen">Loading...</div>;
|
||||
@ -23,7 +28,7 @@ export default function MySchedulePage({ assignments }) {
|
||||
<h1 className="text-2xl md:text-3xl font-bold text-center my-4">Моите смени</h1>
|
||||
<div className="space-y-4">
|
||||
{assignments && assignments.map((assignment) => (
|
||||
<div key={assignment.dateStr} className="bg-white shadow overflow-hidden rounded-lg">
|
||||
<div key={assignment.dateStr + assignments.indexOf(assignment)} className="bg-white shadow overflow-hidden rounded-lg">
|
||||
<div className="px-4 py-5 sm:px-6">
|
||||
<h3 className="text-lg leading-6 font-medium text-gray-900">{assignment.dateStr}</h3>
|
||||
</div>
|
||||
@ -31,10 +36,22 @@ export default function MySchedulePage({ assignments }) {
|
||||
<dl>
|
||||
<div className="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt className="text-sm font-medium text-gray-500">Час</dt>
|
||||
<dd className="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
<dd className="mt-1 text text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{GetTimeFormat(assignment.shift.startTime)} - {GetTimeFormat(assignment.shift.endTime)}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt className="text-sm font-medium text-gray-500">Смяна</dt>
|
||||
<dd className="mt-1 text text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{assignment.shift.assignments.map((a, index) => {
|
||||
return (
|
||||
<span key={index} className="inline-flex items-center mr-1 px-1 py-0.5 rounded-full text-sm font-medium ">
|
||||
{a.publisher.firstName} {a.publisher.lastName}</span>
|
||||
)
|
||||
}
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt className="text-sm font-medium text-gray-500">Действия</dt>
|
||||
<dd className="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
@ -45,11 +62,20 @@ export default function MySchedulePage({ assignments }) {
|
||||
Добави в календар
|
||||
</button>
|
||||
<button
|
||||
className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
|
||||
onClick={() => {
|
||||
setАssignment(assignment);
|
||||
setIsModalOpen(true)
|
||||
}}
|
||||
>
|
||||
Заместник
|
||||
</button>
|
||||
{/* <button
|
||||
className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
|
||||
onClick={() => searchReplacement(assignment.id)}
|
||||
>
|
||||
Търси заместник
|
||||
</button>
|
||||
</button> */}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
@ -58,7 +84,27 @@ export default function MySchedulePage({ assignments }) {
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<Modal isOpen={isModalOpen}
|
||||
onClose={() => setIsModalOpen(false)}
|
||||
forDate={new Date(assignment?.shift.startTime)}
|
||||
useFilterDate={useFilterDate}
|
||||
onUseFilterDateChange={(value) => setUseFilterDate(value)}>
|
||||
|
||||
<PublisherSearchBox
|
||||
selectedId={null}
|
||||
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);
|
||||
//addAssignment(publisher, shift.id);
|
||||
}}
|
||||
showAllAuto={true}
|
||||
showSearch={true}
|
||||
showList={false}
|
||||
/>
|
||||
</Modal>
|
||||
</ProtectedRoute>
|
||||
</Layout>
|
||||
);
|
||||
@ -97,7 +143,21 @@ export const getServerSideProps = async (context) => {
|
||||
include: {
|
||||
assignments: {
|
||||
include: {
|
||||
shift: true,
|
||||
shift: {
|
||||
include: {
|
||||
assignments: {
|
||||
include: {
|
||||
publisher: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user