From a79e1321611c145a45f2105f8dc619f3904f2594 Mon Sep 17 00:00:00 2001 From: Ai Ling <50992674+ailing35@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:17:59 +0800 Subject: [PATCH] Revert "[offers][fix] Fix number input scroll issue (#524)" (#525) This reverts commit 5d34a44237f8451bcbabab0f8c38f49ab5c38a90. --- .../submissionForm/BackgroundForm.tsx | 22 ++++++------------- .../submissionForm/OfferDetailsForm.tsx | 17 +++++--------- apps/portal/src/utils/offers/form.tsx | 17 -------------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx b/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx index 07696d77..63e0148b 100644 --- a/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx +++ b/apps/portal/src/components/offers/offersSubmission/submissionForm/BackgroundForm.tsx @@ -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() { @@ -67,10 +64,9 @@ function YoeSection() { @@ -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() { @@ -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() { diff --git a/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx b/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx index c9a26670..9b24c5e6 100644 --- a/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx +++ b/apps/portal/src/components/offers/offersSubmission/submissionForm/OfferDetailsForm.tsx @@ -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, })} /> diff --git a/apps/portal/src/utils/offers/form.tsx b/apps/portal/src/utils/offers/form.tsx index 52ee4deb..ac03e281 100644 --- a/apps/portal/src/utils/offers/form.tsx +++ b/apps/portal/src/utils/offers/form.tsx @@ -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 = (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; -};