my schedule - (wip)
This commit is contained in:
@ -15,6 +15,11 @@ const sidemenu = [
|
||||
text: "График",
|
||||
url: "/cart/calendar/schedule",
|
||||
},
|
||||
// {
|
||||
// id: "myshedule",
|
||||
// text: "Моя График",
|
||||
// url: "/cart/publishers/myschedule",
|
||||
// },
|
||||
{
|
||||
id: "locations",
|
||||
text: "Местоположения",
|
||||
|
90
pages/cart/publishers/myschedule.tsx
Normal file
90
pages/cart/publishers/myschedule.tsx
Normal file
@ -0,0 +1,90 @@
|
||||
import { useState } from 'react';
|
||||
import Layout from "../../../components/layout";
|
||||
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 { useSession, getSession } from 'next-auth/react';
|
||||
|
||||
export default function MySchedulePage({ shifts }) {
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
if (status === "loading") {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER, UserRole.USER]}>
|
||||
<div className="container mx-auto p-4">
|
||||
<h1 className="text-xl font-semibold mb-4">Моите смени</h1>
|
||||
<ShiftsList assignments={shifts} selectedtab={common.getCurrentYearMonth()} />
|
||||
</div>
|
||||
</ProtectedRoute>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
//get future assignmenrs for the current user (session.user.id)
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
const session = await getSession(context);
|
||||
|
||||
context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
|
||||
|
||||
if (!session) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/auth/login', // Adjust the login path as needed
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const prisma = common.getPrismaClient();
|
||||
const publisher = await prisma.publisher.findMany({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
assignments: {
|
||||
some: {
|
||||
shift: {
|
||||
startTime: {
|
||||
gte: new Date(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
assignments: {
|
||||
include: {
|
||||
shift: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const assignments = publisher[0]?.assignments;
|
||||
const transformedAssignments = assignments.map(assignment => {
|
||||
if (assignment.shift && assignment.shift.startTime) {
|
||||
return {
|
||||
...assignment,
|
||||
shift: {
|
||||
...assignment.shift,
|
||||
startTime: assignment.shift.startTime.toISOString(),
|
||||
endTime: assignment.shift.endTime.toISOString(),
|
||||
},
|
||||
};
|
||||
}
|
||||
return assignment;
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
props: {
|
||||
assignments: transformedAssignments,
|
||||
},
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user