From fde9ba980c497bc15339a82cd3e9055d6d5bab43 Mon Sep 17 00:00:00 2001 From: Preston Mueller Date: Fri, 20 Sep 2024 15:33:42 -0400 Subject: [PATCH] fix(OperatorSelection): ignore leading zeroes (#141) --- js/components/operatorSignIn/attestation.tsx | 4 +++- .../operatorSignIn/operatorSelection.tsx | 7 +++++- .../operatorSignIn/attestation.test.tsx | 20 +++++++++++++++++ .../operatorSignIn/operatorSelection.test.tsx | 22 +++++++++++++++++++ js/util/string.ts | 3 +++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 js/util/string.ts diff --git a/js/components/operatorSignIn/attestation.tsx b/js/components/operatorSignIn/attestation.tsx index 87f0222..ed086be 100644 --- a/js/components/operatorSignIn/attestation.tsx +++ b/js/components/operatorSignIn/attestation.tsx @@ -3,6 +3,7 @@ import { reload } from "../../browser"; import { lookupDisplayName } from "../../hooks/useEmployees"; import { Employee } from "../../models/employee"; import { className } from "../../util/dom"; +import { removeLeadingZero } from "../../util/string"; import { useSignInText } from "./text"; import { ReactElement, useEffect, useState } from "react"; @@ -157,8 +158,9 @@ export const SignaturePrompt = ({ className="fs-mask w-full" inputMode="numeric" defaultValue={defaultValue} + // Do not set `value`- we are transforming below! onChange={(evt) => { - onChange(evt.target.value); + onChange(removeLeadingZero(evt.target.value)); }} required /> diff --git a/js/components/operatorSignIn/operatorSelection.tsx b/js/components/operatorSignIn/operatorSelection.tsx index b6934ab..68c1e0e 100644 --- a/js/components/operatorSignIn/operatorSelection.tsx +++ b/js/components/operatorSignIn/operatorSelection.tsx @@ -1,6 +1,7 @@ import { fetchEmployeeByBadgeSerial } from "../../hooks/useEmployees"; import { useNfc } from "../../hooks/useNfc"; import { className } from "../../util/dom"; +import { removeLeadingZero } from "../../util/string"; import { BadgeEntry } from "./types"; import { ReactElement, useEffect, useId, useState } from "react"; @@ -51,8 +52,12 @@ export const OperatorSelection = ({ className="fs-mask h-10" id={inputId} inputMode="numeric" + // Do not set `value`- we are transforming below! onChange={(evt) => { - setBadgeEntry({ number: evt.target.value, method: "manual" }); + setBadgeEntry({ + number: removeLeadingZero(evt.target.value), + method: "manual", + }); }} />