//page to show all repots in the database with a link to the report page import axiosInstance from '../../../src/axiosSecure'; import { useEffect, useState } from "react"; import toast from "react-hot-toast"; import { useRouter } from "next/router"; import Link from "next/link"; import { useSession } from "next-auth/react" //const common = require('src/helpers/common'); import common from '../../../src/helpers/common'; import Layout from "../../../components/layout"; import ProtectedRoute from '../../../components/protectedRoute'; import { Location, Shift, UserRole, EventLog, EventType, EventLogType } from "@prisma/client"; import { set } from 'date-fns'; export default function EventLogList() { const [eventLogs, setEventLog] = useState([]); const [requestedAssignments, setRequestedAssignments] = useState([]); const router = useRouter(); const { data: session } = useSession(); const [locations, setLocations] = useState([]); const [showOpenRequests, setShowOpenRequests] = useState(false); useEffect(() => { const fetchLocations = async () => { try { const { data: eventLogsData } = await axiosInstance.get(`/api/data/prisma/eventLog?where={"type":"${EventLogType.AssignmentReplacementAccepted}"}&include={"publisher":{"select":{"firstName":true,"lastName":true}},"shift":{"include":{"assignments":{"include":{"publisher":{"select":{"firstName":true,"lastName":true}}}}}}}`); setEventLog(eventLogsData); const { data: shiftsData } = await axiosInstance.get(`/api/data/prisma/assignment?where={"publicGuid":{"not":"null"}}&include={"shift":{"include":{"assignments":{"include":{"publisher":{"select":{"firstName":true,"lastName":true}}}}}},"publisher":{"select":{"firstName":true,"lastName":true}}}`); setRequestedAssignments(shiftsData); } catch (error) { console.error(error); } }; if (!locations.length) { fetchLocations(); } }, []); return (

Заявки за заместване

{/* */}
{!showOpenRequests && (eventLogs.map((event) => ( )) )} {showOpenRequests && (requestedAssignments.map((assignment) => ( )) )}
От Дата Смяна Действия
{event.publisher.firstName + " " + event.publisher.lastName} {new Date(event.shift?.startTime).toLocaleString('bg')} {event.shift?.assignments.map((ass) => (
{ass.publisher.firstName + " " + ass.publisher.lastName}
))}
{event.content}
{assignment.publisher.firstName + " " + assignment.publisher.lastName} {new Date(assignment.shift.startTime).toLocaleString('bg')} {assignment.shift.assignments.map((ass) => (
{ass.publisher.firstName + " " + ass.publisher.lastName}
))}
); }