Can create accommodation from WebUI

This commit is contained in:
2024-06-10 22:00:30 +02:00
parent f83cbe1386
commit 7d64ea219f
8 changed files with 296 additions and 5 deletions

View File

@@ -0,0 +1,21 @@
import { LenConstraint } from "../api/ServerApi";
/**
* Check if a constraint was respected or not
*
* @returns An error message appropriate for the constraint
* violation, if any, or undefined otherwise
*/
export function checkConstraint(
constraint: LenConstraint,
value: string | undefined
): string | undefined {
value = value ?? "";
if (value.length < constraint.min)
return `Veuillez indiquer au moins ${constraint.min} caractères !`;
if (value.length > constraint.max)
return `Veuillez indiquer au maximum ${constraint.min} caractères !`;
return undefined;
}