Revert "[offers][fix] Fix number input scroll issue (#524)" (#525)

This reverts commit 5d34a44237.
pull/526/head
Ai Ling 2 years ago committed by GitHub
parent 5ecaf75270
commit a79e132161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,7 +9,6 @@ import {
Currency,
CURRENCY_OPTIONS,
} from '~/utils/offers/currency/CurrencyEnum';
import { validateNumber } from '~/utils/offers/form';
import { EducationFieldOptions } from '../../EducationFields';
import { EducationLevelOptions } from '../../EducationLevels';
@ -35,11 +34,10 @@ function YoeSection() {
label="Total YOE"
placeholder="0"
required={true}
type="text"
type="number"
{...register(`background.totalYoe`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
required: FieldError.REQUIRED,
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -50,10 +48,9 @@ function YoeSection() {
<FormTextInput
errorMessage={backgroundFields?.specificYoes?.[0]?.yoe?.message}
label="Specific YOE 1"
type="text"
type="number"
{...register(`background.specificYoes.0.yoe`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -67,10 +64,9 @@ function YoeSection() {
<FormTextInput
errorMessage={backgroundFields?.specificYoes?.[1]?.yoe?.message}
label="Specific YOE 2"
type="text"
type="number"
{...register(`background.specificYoes.1.yoe`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -123,10 +119,9 @@ function FullTimeJobFields() {
placeholder="0.00"
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(`background.experiences.0.totalCompensation.value`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -147,10 +142,9 @@ function FullTimeJobFields() {
<FormTextInput
errorMessage={experiencesField?.durationInMonths?.message}
label="Duration (months)"
type="text"
type="number"
{...register(`background.experiences.0.durationInMonths`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -194,10 +188,9 @@ function InternshipJobFields() {
placeholder="0.00"
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(`background.experiences.0.monthlySalary.value`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -212,10 +205,9 @@ function InternshipJobFields() {
<FormTextInput
errorMessage={experiencesField?.durationInMonths?.message}
label="Duration (months)"
type="text"
type="number"
{...register(`background.experiences.0.durationInMonths`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>

@ -13,8 +13,6 @@ import { TrashIcon } from '@heroicons/react/24/outline';
import { JobType } from '@prisma/client';
import { Button, Dialog, HorizontalDivider } from '@tih/ui';
import { validateNumber } from '~/utils/offers/form';
import {
defaultFullTimeOfferValues,
defaultInternshipOfferValues,
@ -158,13 +156,12 @@ function FullTimeOfferDetailsForm({
required={true}
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(
`offers.${index}.offersFullTime.totalCompensation.value`,
{
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
required: FieldError.REQUIRED,
validate: validateNumber,
valueAsNumber: true,
},
)}
@ -192,10 +189,9 @@ function FullTimeOfferDetailsForm({
placeholder="0"
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(`offers.${index}.offersFullTime.baseSalary.value`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -216,10 +212,9 @@ function FullTimeOfferDetailsForm({
placeholder="0"
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(`offers.${index}.offersFullTime.bonus.value`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -240,10 +235,9 @@ function FullTimeOfferDetailsForm({
placeholder="0"
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(`offers.${index}.offersFullTime.stocks.value`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
validate: validateNumber,
valueAsNumber: true,
})}
/>
@ -400,11 +394,10 @@ function InternshipOfferDetailsForm({
required={true}
startAddOn="$"
startAddOnType="label"
type="text"
type="number"
{...register(`offers.${index}.offersIntern.monthlySalary.value`, {
min: { message: FieldError.NON_NEGATIVE_NUMBER, value: 0 },
required: FieldError.REQUIRED,
validate: validateNumber,
valueAsNumber: true,
})}
/>

@ -1,9 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Validate } from 'react-hook-form';
import { FieldError } from '~/components/offers/constants';
/**
* Removes empty objects, empty strings, `null`, `undefined`, and `NaN` values from an object.
* Does not remove empty arrays.
@ -89,16 +85,3 @@ export function removeInvalidMoneyData(object: any) {
});
return object;
}
/**
* Validation rule for numbers.
* @param value
* @returns `true` if value is a number, otherwise error message.
*/
export const validateNumber: Validate<number | null | undefined> = (value) => {
// Checks for NaN value, as the value passed in by the form is already converted to number pre-validation.
if (value !== value) {
return FieldError.NUMBER;
}
return true;
};

Loading…
Cancel
Save