import { CartEvent, UserRole } from '@prisma/client'; import { useRouter } from "next/router"; import { useState } from "react"; import Layout from "../../../components/layout"; import common from 'src/helpers/common'; import ProtectedRoute from '../../../components/protectedRoute'; import CartEventForm from '../../../components/cartevent/CartEventForm'; // import IProps from '../../../components/cartevent/CartEventForm' import axiosServer from '../../../src/axiosServer'; import { getServerSession } from "next-auth/next" import { authOptions } from "../../../pages/api/auth/[...nextauth]" // export default CartEventForm; export interface ICartEventPageProps { items: [CartEvent]; locations: [Location]; inline: false; } export default function CartEventPage({ items, locations }: ICartEventPageProps) { const router = useRouter(); const [addnew, setAddNew] = useState(false); return (

All cart events

{items.map((item: CartEvent, i) => ( ))}
# Day of Week Time Shift Duration Active
{item.id} {common.dayOfWeekNames[common.getDayOfWeekIndex(item.dayofweek)]} на {locations.find(l => l.id == item.locationId).name} {new Date(item.startTime).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }) + " до " + new Date(item.endTime).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })} {item.shiftDuration} {item.isActive ? "Yes" : "No"}
{addnew && }
) } export const getServerSideProps = async (context) => { const session = await getServerSession(context.req, context.res, authOptions) context.req.session = session; const axios = await axiosServer(context); const { data: items } = await axios.get("/api/data/cartevents"); console.log("gettnng locations from: " + "/api/data/locations?select=id,name"); const locations = await axios .get(`/api/data/locations?select=id,name`) .then((res) => { console.log("locations: " + JSON.stringify(res.data)); return res.data; }); return { props: { items, locations: locations, inline: false, }, }; };