Skip to content

Commit

Permalink
fix: update class
Browse files Browse the repository at this point in the history
  • Loading branch information
amjed-ali-k committed Oct 28, 2023
1 parent 9af60d2 commit ef8cda7
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 52 deletions.
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -192,6 +194,8 @@ function GenerateSection({
regNo: string;
subjectCode: number;
examType: number;
batchId: string;
batchName: string;
} & IncomeStudent)[] = [];
// console.log(remainingStudents);
subjectCodes.map((subCode) => {
Expand Down
149 changes: 98 additions & 51 deletions src/app/dashboard/tools/exam-seating/exam/new/_components/PDFgen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -414,15 +415,29 @@ const hallschema = z.object({
alignment: z.string(),
title: z.string().min(0).optional(),
nameSelect: z.string(),
showBatchName: z.boolean(),
});

export function GenerateHallsAssignment({
seats,
}: {
seats: ArrangedResult[];
}) {
const { data: subjects } = usePermenantGet<Subject[]>(
"/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: <ExamHallPDF seats={seats} />,
document: <HallArrangementPDF seats={seatData} subjects={subjects} />,
});

const form = useForm<z.infer<typeof hallschema>>({
Expand All @@ -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<typeof hallschema>) {
const hl = seats.map((hall) => {
return {
id: hall.hall,
name: hall.hallName,
subs: group(hall.seats, (e) => e.subjectCode),
count: hall.seats.length,
};
});
updateInstance(
<HallArrangementPDF seats={hl} options={data} subjects={subjects} />
<HallArrangementPDF seats={seatData} options={data} subjects={subjects} />
);
}

Expand Down Expand Up @@ -544,10 +548,31 @@ export function GenerateHallsAssignment({
</FormItem>
)}
/>
<Button type="submit" className=" w-64" variant="default">
Update
</Button>
<FormField
control={form.control}
name="showBatchName"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between">
<div className="space-y-0.5">
<FormLabel>Show batch name</FormLabel>
<FormDescription>
Display batch name on top of each student list
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
aria-readonly
/>
</FormControl>
</FormItem>
)}
/>
</div>
<Button type="submit" className="my-4 w-64" variant="default">
Update
</Button>
<div className="w-full">
{seats && instance.url && (
<iframe height="700px" width="100%" src={instance.url}></iframe>
Expand Down Expand Up @@ -648,7 +673,7 @@ function HallArrangementPDF({
subs: Partial<Record<number, AllocatedSeat[]>>;
count: number;
}[];
options?: z.infer<typeof seatingSchema>;
options?: z.infer<typeof hallschema>;
subjects?: Subject[];
}) {
return (
Expand Down Expand Up @@ -678,38 +703,58 @@ function HallArrangementPDF({
</Text>
</View>
<View style={hallStyle.contentCol}>
{Object.entries(hall.subs).map(([subCode, details]) => (
<View key={subCode} style={{ width: "100%" }}>
<View style={hallStyle.contentTitleContainer}>
{/* Subject Name */}
<Text style={hallStyle.contentTitle}>
{subCode}
{" - " +
subjects?.find((e) => e.code === subCode)?.name}
</Text>
</View>
<View style={hallStyle.contentSubContainer}>
<Text style={hallStyle.contentSubTitle}>
Electronics
</Text>
<Text style={hallStyle.contentDetails}>
{/* Details */}
{details?.map((seat) => (
<Text
key={seat.name}
style={hallStyle.contentItem}
wrap
>
{seat[options?.nameSelect as keyof typeof seat] ||
seat.name ||
" "}
,{" "}
</Text>
))}
</Text>
{Object.entries(hall.subs).map(([subCode, details]) => {
if (!details) return;
const batchGroup = group(details, (e) => e.batchId);

return (
<View key={subCode} style={{ width: "100%" }}>
<View style={hallStyle.contentTitleContainer}>
{/* Subject Name */}
<Text style={hallStyle.contentTitle}>
{subCode}
{" - " +
subjects?.find((e) => e.code === subCode)?.name}
</Text>
</View>
{Object.entries(batchGroup).map(
([batchId, details]) => {
if (!details) return;
return (
<View
key={batchId}
style={hallStyle.contentSubContainer}
>
{options?.showBatchName && (
<Text style={hallStyle.contentSubTitle}>
{/* Batch Name */}
{details[0].batchName}
</Text>
)}
<Text style={hallStyle.contentDetails}>
{/* Details */}
{details?.map((seat) => (
<Text
key={seat.name}
style={hallStyle.contentItem}
wrap
>
{seat[
options?.nameSelect as keyof typeof seat
] ||
seat.name ||
" "}
,{" "}
</Text>
))}
</Text>
</View>
);
}
)}
</View>
</View>
))}
);
})}
</View>
</View>
</View>
Expand All @@ -719,3 +764,5 @@ function HallArrangementPDF({
</Document>
);
}

export function GenerateAttendanceSheet({}) {}
1 change: 0 additions & 1 deletion src/components/auth/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use server";
import { hankoApiUrl } from "./vars";
import { createRemoteJWKSet, jwtVerify } from "jose";
import { NextRequest } from "next/server";
Expand Down
29 changes: 29 additions & 0 deletions src/components/ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
"peer inline-flex h-[20px] w-[36px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
className
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"
)}
/>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName

export { Switch }
2 changes: 2 additions & 0 deletions src/lib/examTools/hallSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface Student {
regNumber?: string | undefined;
admnNumber?: string | undefined;
primaryNumber?: string | undefined;
batchId: string;
batchName: string;
}

export type AllocatedSeat = Student & {
Expand Down

0 comments on commit ef8cda7

Please sign in to comment.