fix: rating type issues (#3638)
* fix: rating type issues * fix: rebase --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -23,7 +23,7 @@ export const useRatingField = () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const rating = +(fieldValue ?? 0);
|
||||
const rating = fieldValue ?? 'RATING_1';
|
||||
|
||||
return {
|
||||
fieldDefinition,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { FieldRatingValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { RatingInput } from '@/ui/field/input/components/RatingInput';
|
||||
|
||||
import { usePersistField } from '../../../hooks/usePersistField';
|
||||
@ -10,6 +11,14 @@ export type RatingFieldInputProps = {
|
||||
readonly?: boolean;
|
||||
};
|
||||
|
||||
export const RATING_VALUES = [
|
||||
'RATING_1',
|
||||
'RATING_2',
|
||||
'RATING_3',
|
||||
'RATING_4',
|
||||
'RATING_5',
|
||||
] as const;
|
||||
|
||||
export const RatingFieldInput = ({
|
||||
onSubmit,
|
||||
readonly,
|
||||
@ -18,8 +27,8 @@ export const RatingFieldInput = ({
|
||||
|
||||
const persistField = usePersistField();
|
||||
|
||||
const handleChange = (newRating: number) => {
|
||||
onSubmit?.(() => persistField(`${newRating}`));
|
||||
const handleChange = (newRating: FieldRatingValue) => {
|
||||
onSubmit?.(() => persistField(newRating));
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { RATING_VALUES } from '@/object-record/record-field/meta-types/input/components/RatingFieldInput';
|
||||
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
|
||||
import { ThemeColor } from '@/ui/theme/constants/colors';
|
||||
|
||||
@ -119,7 +120,7 @@ export type FieldCurrencyValue = {
|
||||
amountMicros: number | null;
|
||||
};
|
||||
export type FieldFullNameValue = { firstName: string; lastName: string };
|
||||
export type FieldRatingValue = '1' | '2' | '3' | '4' | '5';
|
||||
export type FieldRatingValue = (typeof RATING_VALUES)[number];
|
||||
export type FieldSelectValue = string | null;
|
||||
|
||||
export type FieldRelationValue = EntityForSelect | null;
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { RATING_VALUES } from '../../meta-types/input/components/RatingFieldInput';
|
||||
import { FieldRatingValue } from '../FieldMetadata';
|
||||
|
||||
const ratingSchema = z
|
||||
.string()
|
||||
.transform((value) => +value)
|
||||
.pipe(z.number().int().min(1).max(5));
|
||||
const ratingSchema = z.string().pipe(z.enum(RATING_VALUES));
|
||||
|
||||
export const isFieldRatingValue = (
|
||||
fieldValue: unknown,
|
||||
|
||||
Reference in New Issue
Block a user