diff --git a/src/routes/viewer/CourseCombobox.tsx b/src/routes/viewer/CourseCombobox.tsx index d6e81e49..7ff13626 100644 --- a/src/routes/viewer/CourseCombobox.tsx +++ b/src/routes/viewer/CourseCombobox.tsx @@ -38,7 +38,7 @@ export function CourseCombobox({ value, courses: c, onSelect }: Props) { return (
-

Corso

+

Corso

{selectedCourse ? ( handleSelect(absCourse.value)}> {selectedCourse.label} diff --git a/src/routes/viewer/LocationSelect.tsx b/src/routes/viewer/LocationSelect.tsx index 324b8545..873a7af1 100644 --- a/src/routes/viewer/LocationSelect.tsx +++ b/src/routes/viewer/LocationSelect.tsx @@ -35,7 +35,7 @@ export default function LocationsSelect(props: Props) { if (locations.length === 0) return <>; return (
-

Sede

+

Sede

{locations.length >= 2 ? ( isMobile ? ( LocationCombobox(props) diff --git a/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx b/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx index 1918331f..df12e6ae 100644 --- a/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx +++ b/src/routes/viewer/PhaseSelect/GroupSelect/index.tsx @@ -11,7 +11,7 @@ export default function GroupSelect(props: GroupSelectProps) { const { groups, isCombobox, selectedGroup, groupOpen, onChange } = props; return (
-

Fase

+

Fase

{groups.size >= 2 ? ( isCombobox ? ( -

Lingua

+

Lingua

{canChoose ? ( -

Graduatoria

+

Graduatoria

{phases.length >= 2 ? ( isCombobox ? ( ({ >
- {option.icon && ( - - )} + {option.icon && } {option.label} {facet && ( diff --git a/src/routes/viewer/Table/Toolbar.tsx b/src/routes/viewer/Table/Toolbar.tsx index da8b03ea..aff98d0d 100644 --- a/src/routes/viewer/Table/Toolbar.tsx +++ b/src/routes/viewer/Table/Toolbar.tsx @@ -7,6 +7,9 @@ import { enrollStatusOpts, enrollAllowedOpts } from "./columns"; import { StudentResultKeys } from "."; import StudentResult from "@/utils/types/data/parsed/Ranking/StudentResult"; import { sha256 } from "@/utils/strings/crypto"; +import { useState } from "react"; +import { LuXCircle } from "react-icons/lu"; +import { Removable } from "@/components/custom-ui/Removable"; type Props = { has: Record; @@ -17,21 +20,89 @@ type Props = { export function Toolbar({ has, onCsvClick, table }: Props) { const enrollStatusCol = table.getColumn("enrollStatus"); const enrollAllowedCol = table.getColumn("enrollAllowed"); + const [matricolaFilter, setMatricolaFilter] = useState(""); + const [matricolaFilterSubmitted, setMatricolaFilterSubmitted] = + useState(false); + const { rows: filteredRows } = table.getFilteredRowModel(); + + function clearMatricolaTableFilter() { + table.getColumn("id")?.setFilterValue(undefined); + } + + function handleClearMatricolaFilter() { + setMatricolaFilter(""); + clearMatricolaTableFilter(); + setMatricolaFilterSubmitted(false); + } + + function handleMatricolaFilterChange( + event: React.ChangeEvent, + ) { + if (matricolaFilterSubmitted) clearMatricolaTableFilter(); + const input = event.target.value; + setMatricolaFilter(input); + setMatricolaFilterSubmitted(false); + } + + async function handleMatricolaFilterSubmit( + e: React.FormEvent, + ) { + e.preventDefault(); + + if (matricolaFilter.length === 0) handleClearMatricolaFilter(); + else { + const hash = await sha256(matricolaFilter); + table.getColumn("id")?.setFilterValue(hash); + setMatricolaFilterSubmitted(true); + } + } return ( -
+
{table.getColumn("id") && ( - { - const input = event.target.value; - const hash = await sha256(event.target.value); - table.getColumn("id")?.setFilterValue(input ? hash : undefined); - }} - /> +
+

Matricola

+ {filteredRows.length > 0 && matricolaFilterSubmitted ? ( + + {matricolaFilter} + + ) : ( + <> +
+ + {matricolaFilter.length > 0 && ( + + )} +
+ {matricolaFilterSubmitted && ( +

+ Matricola non trovata, ricontrolla. +

+ )} + + )} +
)} -
+
{has.enrollAllowed && enrollAllowedCol && ( )}
-
+
);