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 27af974..da57d33 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 @@ -68,7 +68,7 @@ import { sum, flat, group, sift } from "radash"; import { assignHallsCustom } from "@/lib/examTools/customHallAsiign"; import { AllocatedSeat, allocateSeats } from "@/lib/examTools/hallSort"; import { SeatObjectType } from "../../../new-class/_components/newClass"; -import { ExamHallPDF, GenerateSeatArrangements } from "./PDFgen"; +import { GenerateHallsAssignment, GenerateSeatArrangements } from "./PDFgen"; type tabsType = "batches-section" | "halls-section" | "generate-section"; @@ -232,6 +232,7 @@ function GenerateSection({ return (
+
); } 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 864b294..52b7daa 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 @@ -5,13 +5,11 @@ import { Font, Document, StyleSheet, - PDFViewer, - Link, usePDF, } from "@react-pdf/renderer"; import { ArrangedResult } from "./NewExamForm"; import React, { useEffect, useMemo, useReducer, useState } from "react"; -import { max } from "radash"; +import { group, mapValues, max } from "radash"; import { SeatType } from "../../../new-class/_components/newClass"; import { AllocatedSeat } from "@/lib/examTools/hallSort"; import { useForm } from "react-hook-form"; @@ -171,10 +169,6 @@ export function GenerateSeatArrangements({ }: { seats: ArrangedResult[]; }) { - const [examPdf, setExamPdf] = useState(() => ( - - )); - const [instance, updateInstance] = usePDF({ document: , }); @@ -300,7 +294,7 @@ export function GenerateSeatArrangements({ ); } -export function ExamHallPDF({ +function ExamHallPDF({ seats, options, }: { @@ -413,3 +407,290 @@ function getSeatData( } return seat?.regNo || " "; } + +const hallschema = z.object({ + alignment: z.string(), + title: z.string().min(0).optional(), + nameSelect: z.string(), +}); + +export function GenerateHallsAssignment({ + seats, +}: { + seats: ArrangedResult[]; +}) { + const [instance, updateInstance] = usePDF({ + document: , + }); + + const form = useForm>({ + resolver: zodResolver(hallschema), + defaultValues: { + alignment: "portrait", + nameSelect: "regNo", + title: "", + }, + }); + + 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(); + } + + return ( +
+ + + +
+
Hall arrangement
+

+ Hall arrangement sheets are made to paste in notice board. So + that students can find respective halls +

+
+
+ ( + + Page alignment + + + + + + + + Portrait + + + + + + + + Landscape + + + + + + + )} + /> + ( + + Title + + + + + This will be the title of all pages. + + + + )} + /> + ( + + Student Name + + + Choose which value should be printed in student name + session + + + + )} + /> + +
+
+ {seats && instance.url && ( + + )} +
+
+
+
+ + ); +} + +const hallStyle = StyleSheet.create({ + page: { + flexDirection: "column", + backgroundColor: "#fff", + justifyContent: "flex-start", + fontFamily: "Inter", + padding: 10, + width: "100%", + }, + tableContainer: { + display: "flex", + flexDirection: "row", + width: "100%", + marginVertical: 10, + border: 1, + fontFamily: "Inter", + }, + hallCol: { + display: "flex", + flexDirection: "column", + width: "30%", + padding: 10, + borderRightWidth: 1, + alignItems: "center", + justifyContent: "center", + flexShrink: 0, + }, + hallTitle: { + fontSize: 12, + fontWeight: "bold", + }, + hallSubTitle: { + fontSize: 10, + fontWeight: "normal", + }, + contentCol: { + display: "flex", + flexDirection: "column", + flex: 1, + }, + contentTitleContainer: { + display: "flex", + flexDirection: "row", + width: "100%", + borderBottomWidth: 1, + borderBottomColor: "#000", + backgroundColor: "#eee", + paddingVertical: 5, + paddingHorizontal: 10, + }, + contentTitle: { + fontSize: 12, + fontWeight: "bold", + flex: 1, + }, + contentDetails: { + display: "flex", + flexDirection: "column", + justifyContent: "flex-start", + paddingHorizontal: 10, + paddingVertical: 10, + flexWrap: "wrap", + }, + contentItem: { + fontSize: 12, + lineHeight: 1.5, + fontWeight: "normal", + flex: 1, + }, +}); + +function HallArrangementPDF({ + seats, + options, +}: { + seats: { + id: string; + name: string; + subs: Partial>; + count: number; + }[]; + options?: z.infer; +}) { + return ( + + + + {options?.title && options.title !== "" && ( + + {options?.title} + + )} + + Hall arrangement + + {seats.map((hall) => ( + + + + {/* Hall Details */} + {hall.name} + + {hall.count} students + + + + {Object.entries(hall.subs).map(([subCode, details]) => ( + + + {/* Subject Name */} + {subCode} + + + {/* Details */} + {details?.map((seat) => ( + + {seat[options?.nameSelect as keyof typeof seat] || + seat.name || + " "} + ,{" "} + + ))} + + + ))} + + + + ))} + + + + ); +}