Skip to content

Commit

Permalink
Add Requested Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidSumra committed Nov 21, 2024
1 parent 7f5e000 commit de7d829
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
7 changes: 2 additions & 5 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,9 @@ export const keysOf = <T extends object>(obj: T) => {
return Object.keys(obj) as (keyof T)[];
};

export const handleNegativeValue = (
export const sanitizeNumberInput = (
event: React.FormEvent<HTMLInputElement>,
): void => {
const input = event.currentTarget;
input.value = input.value.replace(/-/g, "");
if (isNaN(Number(input.value))) {
input.value = "";
}
input.value = input.value.replace(/[^0-9]/g, "");
};
4 changes: 0 additions & 4 deletions src/components/Form/FormFields/TextFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export type TextFormFieldProps = FormFieldBaseProps<string> &
trailingPadding?: string | undefined;
leadingPadding?: string | undefined;
suggestions?: string[];
min?: number | string;
max?: number | string;
clearable?: boolean | undefined;
};

Expand Down Expand Up @@ -102,8 +100,6 @@ const TextFormField = forwardRef((props: TextFormFieldProps, ref) => {
type={props.type === "password" ? getPasswordFieldType() : props.type}
name={field.name}
value={field.value}
min={Number(props?.min || Number.MIN_SAFE_INTEGER)}
max={Number(props?.max || Number.MAX_SAFE_INTEGER)}
required={field.required}
onChange={(e) => field.handleChange(e.target.value)}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Resource/ResourceCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import useQuery from "@/Utils/request/useQuery";
import { handleNegativeValue, parsePhoneNumber } from "@/Utils/utils";
import { parsePhoneNumber, sanitizeNumberInput } from "@/Utils/utils";

interface resourceProps {
facilityId: number;
Expand Down Expand Up @@ -304,7 +304,7 @@ export default function ResourceCreate(props: resourceProps) {
min={1}
value={state.form.required_quantity}
onChange={handleChange}
onInput={handleNegativeValue}
onInput={sanitizeNumberInput}
/>

<div className="md:col-span-2">
Expand Down
6 changes: 3 additions & 3 deletions src/components/Resource/ResourceDetailsUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import useQuery from "@/Utils/request/useQuery";
import { handleNegativeValue } from "@/Utils/utils";
import { sanitizeNumberInput } from "@/Utils/utils";

interface resourceProps {
id: string;
Expand Down Expand Up @@ -275,7 +275,7 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
min={1}
value={state.form.requested_quantity}
onChange={handleChange}
onInput={handleNegativeValue}
onInput={sanitizeNumberInput}
/>
</div>
<div>
Expand All @@ -287,7 +287,7 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
value={state.form.assigned_quantity}
onChange={handleChange}
disabled={state.form.status !== "PENDING"}
onInput={handleNegativeValue}
onInput={sanitizeNumberInput}
/>
</div>

Expand Down

0 comments on commit de7d829

Please sign in to comment.