Fix transliteration for metadata + transliterate select options (#5430)
## 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>
This commit is contained in:
@ -3,6 +3,7 @@ import { z } from 'zod';
|
||||
import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { getOptionValueFromLabel } from '@/settings/data-model/fields/forms/utils/getOptionValueFromLabel';
|
||||
import { themeColorSchema } from '@/ui/theme/utils/themeColorSchema';
|
||||
import { computeOptionValueFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-option-value-from-label.utils';
|
||||
|
||||
const selectOptionSchema = z
|
||||
.object({
|
||||
@ -14,7 +15,20 @@ const selectOptionSchema = z
|
||||
})
|
||||
.refine((option) => option.value === getOptionValueFromLabel(option.label), {
|
||||
message: 'Value does not match label',
|
||||
}) satisfies z.ZodType<FieldMetadataItemOption>;
|
||||
})
|
||||
.refine(
|
||||
(option) => {
|
||||
try {
|
||||
computeOptionValueFromLabelOrThrow(option.label);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
{
|
||||
message: 'Label is not transliterable',
|
||||
},
|
||||
) satisfies z.ZodType<FieldMetadataItemOption>;
|
||||
|
||||
export const selectOptionsSchema = z
|
||||
.array(selectOptionSchema)
|
||||
|
||||
Reference in New Issue
Block a user