Skip to content

Commit

Permalink
fix(front/backend): closes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
AritroSaha10 committed Nov 18, 2023
1 parent 5850843 commit abcd944
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions frontend/pages/admin/tickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/20/solid";
import createNewTicket from "@/lib/backend/ticket/createNewTicket";
import DatePickerModal from "@/components/DatePicker";
import { DateRangePicker, RangeKeyDict, Range } from 'react-date-range';
import { studentOrTeacherNumberRegex } from "@/util/regexps";

export default function TicketViewingPage() {
const queryClient = useQueryClient();
Expand Down Expand Up @@ -122,11 +123,11 @@ export default function TicketViewingPage() {
const createNewTicketUI = async () => {
setModalSubmitting(true)

const studentNumber = Number(modalStudentNumberRef.current?.value);
const studentNumber = modalStudentNumberRef.current?.value ?? "";
const maxScanCount = Number(modalMaxScanCountRef.current?.value ?? 0);

if (Number.isNaN(studentNumber) || studentNumber < 100000 || studentNumber > 9999999) {
alert("Please provide a valid student number.")
if (!studentOrTeacherNumberRegex.test(studentNumber)) {
alert("Please provide a valid student / teacher number. If you're typing in a teacher number, make sure to include the p00.")
} else if (Number.isNaN(maxScanCount) || maxScanCount < 0 || Math.floor(maxScanCount) !== maxScanCount) {
alert("Please provide a whole number max scan count above or equal to 0, or keep it blank for infinite entires.")
} else if (modalEventChosen === null || modalEventQuery !== "") {
Expand Down Expand Up @@ -201,7 +202,7 @@ export default function TicketViewingPage() {
id="studentNumber"
required
minLength={6}
maxLength={7}
maxLength={8}
ref={modalStudentNumberRef}
/>

Expand Down
3 changes: 3 additions & 0 deletions frontend/util/regexps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const studentOrTeacherNumberRegex = /^\d{6,7}$|^p00\d{5}$/

export { studentOrTeacherNumberRegex }

0 comments on commit abcd944

Please sign in to comment.