63387424c3
## Context Fixes #5403 Transliteration is now integrated to form validation through the schema. While it does not impede inputting an invalid value, it impedes submitting a form that will fail as the transliteration is not possible. Until then we were only performing the transliteration at save time in the front-end, but it's best to provide the information as soon as possible. Later we will add helpers to guide the user (eg "This name is not valid": https://github.com/twentyhq/twenty/issues/5428). --------- Co-authored-by: Charles Bochet <charles@twenty.com>
24 lines
635 B
TypeScript
24 lines
635 B
TypeScript
import { z } from 'zod';
|
|
|
|
import { METADATA_LABEL_VALID_PATTERN } from '~/pages/settings/data-model/constants/MetadataLabelValidPattern';
|
|
import { computeMetadataNameFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
|
|
|
export const metadataLabelSchema = z
|
|
.string()
|
|
.trim()
|
|
.min(1)
|
|
.regex(METADATA_LABEL_VALID_PATTERN)
|
|
.refine(
|
|
(label) => {
|
|
try {
|
|
computeMetadataNameFromLabelOrThrow(label);
|
|
return true;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
},
|
|
{
|
|
message: 'Label is not formattable',
|
|
},
|
|
); // allows non-latin char
|