fix(882): fixes negative number submission for employees input (#1130)
* fix(882): fixes negative number submission for employees input * formatting * fix linting
This commit is contained in:
@ -81,6 +81,7 @@ export const companyViewFields: ViewFieldDefinition<ViewFieldMetadata>[] = [
|
||||
metadata: {
|
||||
type: 'number',
|
||||
fieldName: 'employees',
|
||||
isPositive: true,
|
||||
},
|
||||
isVisible: true,
|
||||
} satisfies ViewFieldDefinition<ViewFieldNumberMetadata>,
|
||||
|
||||
@ -39,6 +39,7 @@ export type ViewFieldDateMetadata = {
|
||||
export type ViewFieldNumberMetadata = {
|
||||
type: 'number';
|
||||
fieldName: string;
|
||||
isPositive: boolean;
|
||||
};
|
||||
|
||||
export type ViewFieldRelationMetadata = {
|
||||
|
||||
@ -7,6 +7,10 @@ import {
|
||||
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
|
||||
import { useUpdateEntityField } from '@/ui/table/hooks/useUpdateEntityField';
|
||||
import { tableEntityFieldFamilySelector } from '@/ui/table/states/tableEntityFieldFamilySelector';
|
||||
import {
|
||||
canBeCastAsPositiveIntegerOrNull,
|
||||
castAsPositiveIntegerOrNull,
|
||||
} from '~/utils/cast-as-positive-integer-or-null';
|
||||
|
||||
import { TextCellEdit } from './TextCellEdit';
|
||||
|
||||
@ -31,12 +35,27 @@ export function GenericEditableNumberCellEditMode({ viewField }: OwnProps) {
|
||||
if (newText === fieldValue) return;
|
||||
|
||||
try {
|
||||
const numberValue = parseInt(newText);
|
||||
let numberValue = parseInt(newText);
|
||||
|
||||
if (isNaN(numberValue)) {
|
||||
throw new Error('Not a number');
|
||||
}
|
||||
|
||||
if (viewField.metadata.isPositive) {
|
||||
if (!canBeCastAsPositiveIntegerOrNull(newText)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const valueCastedAsPositiveNumberOrNull =
|
||||
castAsPositiveIntegerOrNull(newText);
|
||||
|
||||
if (valueCastedAsPositiveNumberOrNull === null) {
|
||||
throw Error('Not a number');
|
||||
}
|
||||
|
||||
numberValue = valueCastedAsPositiveNumberOrNull;
|
||||
}
|
||||
|
||||
// TODO: find a way to store this better in DB
|
||||
if (numberValue > 2000000000) {
|
||||
throw new Error('Number too big');
|
||||
|
||||
Reference in New Issue
Block a user