diff --git a/package-lock.json b/package-lock.json index b43e1ed..637ccf4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "@radix-ui/react-select": "^1.2.2", "@radix-ui/react-separator": "^1.0.3", "@radix-ui/react-slot": "^1.0.2", + "@radix-ui/react-switch": "^1.0.3", "@radix-ui/react-tabs": "^1.0.4", "@radix-ui/react-toast": "^1.1.4", "@radix-ui/react-tooltip": "^1.0.6", @@ -2535,6 +2536,35 @@ } } }, + "node_modules/@radix-ui/react-switch": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.0.3.tgz", + "integrity": "sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==", + "dependencies": { + "@babel/runtime": "^7.13.10", + "@radix-ui/primitive": "1.0.1", + "@radix-ui/react-compose-refs": "1.0.1", + "@radix-ui/react-context": "1.0.1", + "@radix-ui/react-primitive": "1.0.3", + "@radix-ui/react-use-controllable-state": "1.0.1", + "@radix-ui/react-use-previous": "1.0.1", + "@radix-ui/react-use-size": "1.0.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0", + "react-dom": "^16.8 || ^17.0 || ^18.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-tabs": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.0.4.tgz", diff --git a/package.json b/package.json index 0beedd4..7c9e259 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@radix-ui/react-select": "^1.2.2", "@radix-ui/react-separator": "^1.0.3", "@radix-ui/react-slot": "^1.0.2", + "@radix-ui/react-switch": "^1.0.3", "@radix-ui/react-tabs": "^1.0.4", "@radix-ui/react-toast": "^1.1.4", "@radix-ui/react-tooltip": "^1.0.6", diff --git a/src/app/dashboard/tools/exam-seating/exam/new/_components/NewExamForm.tsx b/src/app/dashboard/tools/exam-seating/exam/new/_components/NewExamForm.tsx index da57d33..5d10bcf 100644 --- a/src/app/dashboard/tools/exam-seating/exam/new/_components/NewExamForm.tsx +++ b/src/app/dashboard/tools/exam-seating/exam/new/_components/NewExamForm.tsx @@ -170,6 +170,8 @@ function GenerateSection({ finalBatches.map((e) => { const st = e.students as IncomeStudent[]; const students = st.map((k) => ({ + batchId: e.batchId, + batchName: e.name, regNo: (k.name || k.primaryNumber)!, subjectCode: parseInt(e.subject.code), examType: e.type === "THEORY" ? 0 : 1, @@ -192,6 +194,8 @@ function GenerateSection({ regNo: string; subjectCode: number; examType: number; + batchId: string; + batchName: string; } & IncomeStudent)[] = []; // console.log(remainingStudents); subjectCodes.map((subCode) => { diff --git a/src/app/dashboard/tools/exam-seating/exam/new/_components/PDFgen.tsx b/src/app/dashboard/tools/exam-seating/exam/new/_components/PDFgen.tsx index f81f47e..919e8cd 100644 --- a/src/app/dashboard/tools/exam-seating/exam/new/_components/PDFgen.tsx +++ b/src/app/dashboard/tools/exam-seating/exam/new/_components/PDFgen.tsx @@ -8,8 +8,8 @@ import { usePDF, } from "@react-pdf/renderer"; import { ArrangedResult } from "./NewExamForm"; -import React, { useEffect, useMemo, useReducer, useState } from "react"; -import { group, mapValues, max } from "radash"; +import React, { useMemo } from "react"; +import { group, max } from "radash"; import { SeatType } from "../../../new-class/_components/newClass"; import { AllocatedSeat } from "@/lib/examTools/hallSort"; import { useForm } from "react-hook-form"; @@ -34,6 +34,7 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { usePermenantGet } from "@/lib/swr"; import { Subject } from "@prisma/client"; @@ -414,6 +415,7 @@ const hallschema = z.object({ alignment: z.string(), title: z.string().min(0).optional(), nameSelect: z.string(), + showBatchName: z.boolean(), }); export function GenerateHallsAssignment({ @@ -421,8 +423,21 @@ export function GenerateHallsAssignment({ }: { seats: ArrangedResult[]; }) { + const { data: subjects } = usePermenantGet( + "/api/secure/subjects/all" + ); + const seatData = useMemo( + () => + seats.map((hall) => ({ + id: hall.hall, + name: hall.hallName, + subs: group(hall.seats, (e) => e.subjectCode), + count: hall.seats.length, + })), + [seats] + ); const [instance, updateInstance] = usePDF({ - document: , + document: , }); const form = useForm>({ @@ -431,24 +446,13 @@ export function GenerateHallsAssignment({ alignment: "portrait", nameSelect: "regNo", title: "", + showBatchName: true, }, }); - const { data: subjects, isLoading: isSubsLoading } = usePermenantGet< - Subject[] - >("/api/secure/subjects/all"); - function onSubmit(data: z.infer) { - const hl = seats.map((hall) => { - return { - id: hall.hall, - name: hall.hallName, - subs: group(hall.seats, (e) => e.subjectCode), - count: hall.seats.length, - }; - }); updateInstance( - + ); } @@ -544,10 +548,31 @@ export function GenerateHallsAssignment({ )} /> - + ( + +
+ Show batch name + + Display batch name on top of each student list + +
+ + + +
+ )} + /> +
{seats && instance.url && ( @@ -648,7 +673,7 @@ function HallArrangementPDF({ subs: Partial>; count: number; }[]; - options?: z.infer; + options?: z.infer; subjects?: Subject[]; }) { return ( @@ -678,38 +703,58 @@ function HallArrangementPDF({ - {Object.entries(hall.subs).map(([subCode, details]) => ( - - - {/* Subject Name */} - - {subCode} - {" - " + - subjects?.find((e) => e.code === subCode)?.name} - - - - - Electronics - - - {/* Details */} - {details?.map((seat) => ( - - {seat[options?.nameSelect as keyof typeof seat] || - seat.name || - " "} - ,{" "} - - ))} - + {Object.entries(hall.subs).map(([subCode, details]) => { + if (!details) return; + const batchGroup = group(details, (e) => e.batchId); + + return ( + + + {/* Subject Name */} + + {subCode} + {" - " + + subjects?.find((e) => e.code === subCode)?.name} + + + {Object.entries(batchGroup).map( + ([batchId, details]) => { + if (!details) return; + return ( + + {options?.showBatchName && ( + + {/* Batch Name */} + {details[0].batchName} + + )} + + {/* Details */} + {details?.map((seat) => ( + + {seat[ + options?.nameSelect as keyof typeof seat + ] || + seat.name || + " "} + ,{" "} + + ))} + + + ); + } + )} - - ))} + ); + })} @@ -719,3 +764,5 @@ function HallArrangementPDF({ ); } + +export function GenerateAttendanceSheet({}) {} diff --git a/src/components/auth/server.ts b/src/components/auth/server.ts index 0352b6a..2cebfe1 100644 --- a/src/components/auth/server.ts +++ b/src/components/auth/server.ts @@ -1,4 +1,3 @@ -"use server"; import { hankoApiUrl } from "./vars"; import { createRemoteJWKSet, jwtVerify } from "jose"; import { NextRequest } from "next/server"; diff --git a/src/components/ui/switch.tsx b/src/components/ui/switch.tsx new file mode 100644 index 0000000..3362b47 --- /dev/null +++ b/src/components/ui/switch.tsx @@ -0,0 +1,29 @@ +"use client" + +import * as React from "react" +import * as SwitchPrimitives from "@radix-ui/react-switch" + +import { cn } from "@/lib/utils" + +const Switch = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +Switch.displayName = SwitchPrimitives.Root.displayName + +export { Switch } diff --git a/src/lib/examTools/hallSort.ts b/src/lib/examTools/hallSort.ts index e0bb59a..b874f31 100644 --- a/src/lib/examTools/hallSort.ts +++ b/src/lib/examTools/hallSort.ts @@ -16,6 +16,8 @@ interface Student { regNumber?: string | undefined; admnNumber?: string | undefined; primaryNumber?: string | undefined; + batchId: string; + batchName: string; } export type AllocatedSeat = Student & {