From 95ae307dcc7c34de60950650bcdda2a8f8d66763 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 4 Mar 2024 14:00:02 +0200 Subject: [PATCH] fix myschedule - code copied instead of using existing component due to different data structure --- components/publisher/ShiftsList.tsx | 2 +- components/sidemenuData.js | 10 +++--- pages/cart/publishers/myschedule.tsx | 47 ++++++++++++++++------------ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/components/publisher/ShiftsList.tsx b/components/publisher/ShiftsList.tsx index 07d176c..49cc71a 100644 --- a/components/publisher/ShiftsList.tsx +++ b/components/publisher/ShiftsList.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import toast from "react-hot-toast"; import { useRouter } from "next/router"; import Link from "next/link"; diff --git a/components/sidemenuData.js b/components/sidemenuData.js index 7c7053f..56e9119 100644 --- a/components/sidemenuData.js +++ b/components/sidemenuData.js @@ -15,11 +15,11 @@ const sidemenu = [ text: "График", url: "/cart/calendar/schedule", }, - // { - // id: "myshedule", - // text: "Моя График", - // url: "/cart/publishers/myschedule", - // }, + { + id: "myshedule", + text: "Моя График", + url: "/cart/publishers/myschedule", + }, { id: "locations", text: "Местоположения", diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index e1726f5..d9fb1eb 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -6,6 +6,7 @@ import axiosServer from '../../../src/axiosServer'; import common from '../../../src/helpers/common'; import ShiftsList from '../../../components/publisher/ShiftsList'; +import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const" import { useSession, getSession } from 'next-auth/react'; export default function MySchedulePage({ assignments }) { @@ -18,16 +19,37 @@ export default function MySchedulePage({ assignments }) { return ( +

Моите смени

-

Моите смени

- + {assignments && assignments.map((assignment) => ( +
+
{assignment.dateStr + ":"}
{/*This is the column for the date. I've given it a fixed width (w-8) which you can adjust*/} +
+
+ {GetTimeFormat(assignment.shift.startTime)} - {GetTimeFormat(assignment.shift.endTime)} + + +
+
+
+ ))}
); } -//get future assignmenrs for the current user (session.user.id) +//get future assignments for the current user (session.user.id) export const getServerSideProps = async (context) => { const session = await getSession(context); @@ -72,6 +94,7 @@ export const getServerSideProps = async (context) => { if (assignment.shift && assignment.shift.startTime) { return { ...assignment, + dateStr: assignment.shift.startTime.toLocaleDateString("bg-BG", { day: "numeric", month: "long" }), shift: { ...assignment.shift, startTime: assignment.shift.startTime.toISOString(), @@ -82,26 +105,10 @@ 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: assignmentsStructure + props: { assignments: transformedAssignments } } }