Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bortoz committed Nov 27, 2024
1 parent db0ff34 commit 6375cda
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/cli/firebase/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ async function importUsers(users: User[], customClaims: object, options: ImportO
let user = await auth.getUserByEmail(record.email).catch(noop);
if (!user) {
user = await auth.createUser({
uid: record.id,
email: record.email,
emailVerified: true,
password: record.password,
Expand Down Expand Up @@ -305,6 +306,7 @@ async function importVariantMappings(db: Firestore, options: ImportOptions) {
}

const userSchema = z.object({
id: z.string().optional(),
name: z.string(),
email: z.string().email(),
password: z.string(),
Expand Down
11 changes: 7 additions & 4 deletions src/web/teacher/table-importer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Ref, forwardRef } from "react";
import { type Ref, forwardRef, useState } from "react";

import { Form, Modal, SingleFileField, SubmitButton } from "@olinfo/react-components";
import { Upload } from "lucide-react";
Expand Down Expand Up @@ -30,7 +30,10 @@ const ImportModal = forwardRef(function ImportModal(_props, ref: Ref<HTMLDialogE
const { variants } = useTeacher();
const [, setStudent] = useTeacherStudents();

const [uploadCount, setUploadCount] = useState(0);

const submit = async ({ file }: { file: File }) => {
setUploadCount((count) => count + 1);
try {
const text = await file.text();
await importStudents(text, contest, variants, participation, setStudent);
Expand Down Expand Up @@ -74,7 +77,7 @@ const ImportModal = forwardRef(function ImportModal(_props, ref: Ref<HTMLDialogE
</p>
)}
<Form onSubmit={submit} className="!max-w-full">
<SingleFileField field="file" label="File CSV" accept="text/csv" />
<SingleFileField key={uploadCount} field="file" label="File CSV" accept="text/csv" />
<SubmitButton icon={Upload}>Importa</SubmitButton>
</Form>
</div>
Expand Down Expand Up @@ -104,7 +107,7 @@ async function importStudents(
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: [contest.userData.length],
message: `La variante ${variantId} non è valida`,
message: `La variante "${variantId}" non è valida`,
});
return z.NEVER;
}
Expand Down Expand Up @@ -156,6 +159,6 @@ async function importStudents(
throw new Error(records.errors[0].message);
}

const students: Student[] = validate(schema, records.data);
const students: Student[] = validate(schema, records.data, { includePath: false });
await Promise.all(students.map((student) => addStudent(student)));
}
20 changes: 15 additions & 5 deletions src/web/teacher/table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { type Ref, Suspense, forwardRef, lazy, useMemo, useRef, useState } from "react";
import {
type ComponentType,
type Ref,
Suspense,
forwardRef,
lazy,
useMemo,
useRef,
useState,
} from "react";

import type {
CellEditRequestEvent,
Expand All @@ -8,6 +17,7 @@ import type {
ITooltipParams,
} from "@ag-grid-community/core";
import { AG_GRID_LOCALE_IT } from "@ag-grid-community/locale";
import type { AgGridReactProps } from "@ag-grid-community/react/dist/types/src/shared/interfaces";
import {
Button,
CheckboxField,
Expand Down Expand Up @@ -40,7 +50,7 @@ import ImportModal from "./table-importer";
import "@ag-grid-community/styles/ag-grid.css";
import "@ag-grid-community/styles/ag-theme-quartz.css";

const AgGridReact = lazy(() => import("~/web/components/ag-grid"));
const AgGridReact: ComponentType<AgGridReactProps> = lazy(() => import("~/web/components/ag-grid"));

export default function TeacherTable() {
const { contest, participation } = useTeacher();
Expand Down Expand Up @@ -113,13 +123,13 @@ const FinalizeModal = forwardRef(function FinalizeModal(
// Generate a list of string that can uniquely identify a student. Multiple
// strings are generated to prevent possible errors during data entry.
function normalize(student: Student) {
const info = student.userData!;
const info = student.userData;
const orderings = [
["name", "surname", "classYear", "classSection"],
["surname", "name", "classYear", "classSection"],
];
return orderings.map((fields) => {
return deburr(fields.map((field) => info[field]).join("\n"))
return deburr(fields.map((field) => info?.[field] ?? "").join("\n"))
.toLowerCase()
.replaceAll(/[^\w\n]/g, "");
});
Expand Down Expand Up @@ -247,7 +257,7 @@ const DeleteModal = forwardRef(function DeleteModal(
<i>Seleziona tutti</i>&rdquo; come filtro.
</p>
<Form onSubmit={confirm} className="!max-w-full">
<CheckboxField field="notAgain" label="Non mostrare più questo pop-up" />
<CheckboxField field="notAgain" label="Non mostrare più questo pop-up" optional />
<div className="flex flex-wrap justify-center gap-2">
<FormButton onClick={() => close("0")}>Annulla</FormButton>
<SubmitButton className="btn-warning">Continua</SubmitButton>
Expand Down

0 comments on commit 6375cda

Please sign in to comment.