diff --git a/src/app/components/Navbar.js b/src/app/components/Navbar.js index dd7a030..0f3e327 100644 --- a/src/app/components/Navbar.js +++ b/src/app/components/Navbar.js @@ -2,6 +2,7 @@ import { useState, useEffect, useRef } from "react"; import { account } from "../lib/appwrite"; import { useTheme } from "../context/ThemeContext"; +import { useSidebar } from "../context/SidebarContext"; // Add this import const Navbar = () => { const { darkMode, toggleDarkMode } = useTheme(); @@ -12,6 +13,7 @@ const { darkMode, toggleDarkMode } = useTheme(); const [notifying, setNotifying] = useState(true); // assuming initial notifying state is true const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); + const { isOpen, toggleSidebar } = useSidebar(); // Use the sidebar context // ------fetch user----------------- useEffect(() => { @@ -80,7 +82,7 @@ useEffect(() => { {/* Left side - Menu Button */}
- -

- {isLogin ? "New user?" : "Already registered?"}{" "} - -

-
+ + {children} + ); } + +export function useSidebar() { + const context = useContext(SidebarContext); + if (!context) { + throw new Error('useSidebar must be used within a SidebarProvider'); + } + return context; +} \ No newline at end of file diff --git a/src/app/layout.js b/src/app/layout.js index 1da0ed9..47830f6 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -6,6 +6,7 @@ import Navbar from "./components/Navbar"; import Sidebar from "./components/Sidebar"; import { AuthProvider } from "./context/AuthContext"; import { ThemeProvider,useTheme } from "./context/ThemeContext"; +import { SidebarProvider } from './context/SidebarContext'; function LayoutContent({ children }) { const { darkMode } = useTheme(); @@ -48,7 +49,9 @@ export default function RootLayout({ children }) { + {children} + ); diff --git a/src/app/pages/TraineesData/page.js b/src/app/pages/TraineesData/page.js index 35d4146..78e7d15 100644 --- a/src/app/pages/TraineesData/page.js +++ b/src/app/pages/TraineesData/page.js @@ -2,31 +2,34 @@ import { useEffect, useState } from 'react'; import Link from 'next/link'; +import { + Table, + TableBody, + TableCell, + TableHeader, + TableRow +} from '../../ui/Table'; export default function TraineesDataPage() { const [trainees, setTrainees] = useState([]); const [loading, setLoading] = useState(true); - useEffect(() => { - fetch('https://dtsnew.adhcloud.space/items/trainees', { - headers: { - Authorization: 'Bearer G_2h5o1NlX1_PfomkUe5zk7Xx0dT2juV', - }, - }) - - // fetch('http://localhost:8055/items/trainees') - - - .then((res) => res.json()) - .then((data) => { - setTrainees(data.data || []); - setLoading(false); + useEffect(() => { + fetch(`${process.env.NEXT_PUBLIC_API_URL}/items/trainees`, { + headers: { + Authorization: `Bearer ${process.env.NEXT_PUBLIC_API_TOKEN}`, + }, }) - .catch((err) => { - console.error('Error fetching trainees:', err); - setLoading(false); - }); -}, []); + .then((res) => res.json()) + .then((data) => { + setTrainees(data.data || []); + setLoading(false); + }) + .catch((err) => { + console.error('Error fetching trainees:', err); + setLoading(false); + }); + }, []); return (
@@ -34,20 +37,37 @@ export default function TraineesDataPage() { {loading ? (

Loading...

) : ( - +
+ + + + Name + Batch + DOJ + Speed + Accuracy + + + + {trainees.map((trainee) => ( + + + + {trainee.Name} + + + {trainee.batch_name} + {trainee.doj} + {trainee.speed} + {trainee.accuracy} + + ))} + +
+
)}
); } -export const dynamic = 'force-dynamic'; \ No newline at end of file +export const dynamic = 'force-dynamic'; diff --git a/src/app/pages/TraineesData/trainee/[id]/page.js b/src/app/pages/TraineesData/trainee/[id]/page.js index be0c560..c05b984 100644 --- a/src/app/pages/TraineesData/trainee/[id]/page.js +++ b/src/app/pages/TraineesData/trainee/[id]/page.js @@ -1,29 +1,12 @@ import { notFound } from 'next/navigation'; -// async function getTrainee(id) { -// try { -// const res = await fetch(`http://localhost:8055/items/trainees/${id}`); -// const json = await res.json(); -// return json.data; -// } catch (error) { -// console.error('Error fetching trainee:', error); -// return null; -// } -// } - - async function getTrainee(id) { try { - const res = await fetch(`https://dtsnew.adhcloud.space/items/trainees/${id}`, { + const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/items/trainees/${id}`, { headers: { - Authorization: 'Bearer G_2h5o1NlX1_PfomkUe5zk7Xx0dT2juV', + Authorization: `Bearer ${process.env.NEXT_PUBLIC_API_TOKEN}`, }, }); - -// if we are using directus API -// const res = await fetch(`http://localhost:8055/items/trainees/${id}`); - - const json = await res.json(); return json.data; } catch (error) { @@ -32,28 +15,125 @@ async function getTrainee(id) { } } +async function getAssignmentsByTrainee(traineeId) { + try { + const res = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/items/assignment?filter[sub_by][_eq]=${traineeId}`, + { + headers: { + Authorization: `Bearer ${process.env.NEXT_PUBLIC_API_TOKEN}`, + }, + } + ); + const json = await res.json(); + return json.data || []; + } catch (error) { + console.error('Error fetching assignments:', error); + return []; + } +} - - - -// ✅ Destructure 'params' at the top level export default async function TraineeDetailPage({ params: { id } }) { const trainee = await getTrainee(id); + const assignments = await getAssignmentsByTrainee(id); if (!trainee) return notFound(); return (

{trainee.Name}

- + +
+

Trainee Details

+ +
+ +
+

Assignments

+ {assignments.length === 0 ? ( +
+
+
+

+ No assignments found for this trainee. This could mean: +

+
    +
  • The trainee hasn't submitted any assignments yet
  • +
  • Assignments exist but are associated with a different ID
  • +
  • There might be a data connection issue
  • +
+
+

Debug info:

+

Trainee ID: {id}

+

Total assignments in system: {assignments.length}

+
+
+
+
+ ) : ( +
+ {assignments.map((assignment, index) => ( +
+

Assignment {index + 1}

+

Format: {assignment.format || 'Not specified'}

+ {assignment.link && ( +

+ Main Link:{" "} + + {assignment.link} + +

+ )} + +
+

Submissions:

+ {assignment.assignments && assignment.assignments.length > 0 ? ( +
    + {assignment.assignments.map((submission, subIndex) => ( +
  • +

    + Submission {subIndex + 1}:{" "} + {submission.link_or_zip?.includes('://') ? ( + + {submission.link_or_zip} + + ) : ( + submission.link_or_zip || 'No link provided' + )} +

    + {submission.info && ( +

    Feedback: {submission.info}

    + )} +
  • + ))} +
+ ) : ( +

No submissions yet

+ )} +
+
+ ))} +
+ )} +
); -} +} \ No newline at end of file