Skip to content

Commit

Permalink
Merge pull request #280 from dataforgoodfr/fix/parse-train-distance-w…
Browse files Browse the repository at this point in the history
…hen-validate-forms

fix(utils): Convert string or number to number
  • Loading branch information
Baboo7 authored May 30, 2023
2 parents 8c8219e + 92d0b0e commit fb5e430
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/client/src/modules/administration/Games/Game/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isNaN from "lodash/isNaN";
import { useParams } from "react-router-dom";
import {
Condition,
Expand All @@ -7,6 +8,7 @@ import {
} from "../../../play/Personalization/models/form";
import { compare } from "../../../play/Personalization/utils/formValidation";
import { Row } from "./FormVerification";
import { pipe } from "../../../../lib/fp";

export const useGameId = () => {
const { id } = useParams();
Expand Down Expand Up @@ -51,8 +53,13 @@ export const formatValueOptions = ({
return option ? option.label : "";
};

export const numericParser = (value: number) => {
return value && value < 0 ? 0 : value;
export const numericParser = (value: number | string): number => {
return pipe(
value,
(value) => (typeof value === "string" ? parseInt(value, 10) : value),
(value) => (!value || isNaN(value) ? 0 : value),
(value) => Math.max(value, 0)
);
};

export const isCredible = (fieldName: keyof PersoForm, row: Row) => {
Expand Down

0 comments on commit fb5e430

Please sign in to comment.