fix and consolidate calendar dates usage and format
This commit is contained in:
@ -4,11 +4,11 @@ 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 ShiftsList from '../../../components/publisher/ShiftsList';
|
||||
|
||||
import { useSession, getSession } from 'next-auth/react';
|
||||
|
||||
export default function MySchedulePage({ shifts }) {
|
||||
export default function MySchedulePage({ assignments }) {
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
if (status === "loading") {
|
||||
@ -20,7 +20,7 @@ export default function MySchedulePage({ shifts }) {
|
||||
<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()} />
|
||||
<ShiftsList assignments={assignments} selectedtab={common.getCurrentYearMonth()} />
|
||||
</div>
|
||||
</ProtectedRoute>
|
||||
</Layout>
|
||||
@ -67,6 +67,7 @@ export const getServerSideProps = async (context) => {
|
||||
});
|
||||
|
||||
const assignments = publisher[0]?.assignments;
|
||||
|
||||
const transformedAssignments = assignments.map(assignment => {
|
||||
if (assignment.shift && assignment.shift.startTime) {
|
||||
return {
|
||||
@ -81,10 +82,26 @@ export const getServerSideProps = async (context) => {
|
||||
return assignment;
|
||||
});
|
||||
|
||||
const singleKey = "all";
|
||||
const assignmentsStructure = {
|
||||
assignments: {
|
||||
items: {
|
||||
[singleKey]: [],
|
||||
},
|
||||
keys: [singleKey],
|
||||
months: {
|
||||
[singleKey]: "Всички смени",
|
||||
},
|
||||
},
|
||||
selectedtab: singleKey,
|
||||
};
|
||||
|
||||
transformedAssignments.forEach(assignment => {
|
||||
assignmentsStructure.assignments.items[singleKey].push(assignment);
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
assignments: transformedAssignments,
|
||||
},
|
||||
};
|
||||
};
|
||||
props: assignmentsStructure
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user