feat: set Select field option as default option (#2725)

Closes #2591
This commit is contained in:
Thaïs
2023-11-29 12:19:56 +01:00
committed by GitHub
parent f00c05c342
commit 34a3197fee
14 changed files with 127 additions and 74 deletions

View File

@ -5,5 +5,5 @@ import { useSelectField } from '../../hooks/useSelectField';
export const SelectFieldDisplay = () => {
const { fieldValue } = useSelectField();
return <Tag color={fieldValue.color} text={fieldValue.text} />;
return <Tag color={fieldValue.color} text={fieldValue.label} />;
};

View File

@ -26,15 +26,15 @@ export const useSelectField = () => {
);
const fieldSelectValue = isFieldSelectValue(fieldValue)
? fieldValue
: { color: 'green' as ThemeColor, text: '' };
: { color: 'green' as ThemeColor, label: '' };
const fieldInitialValue = useFieldInitialValue();
const initialValue = {
color: 'green' as ThemeColor,
text: fieldInitialValue?.isEmpty
label: fieldInitialValue?.isEmpty
? ''
: fieldInitialValue?.value ?? fieldSelectValue?.text ?? '',
: fieldInitialValue?.value ?? fieldSelectValue?.label ?? '',
};
return {

View File

@ -116,6 +116,6 @@ export type FieldCurrencyValue = {
};
export type FieldFullNameValue = { firstName: string; lastName: string };
export type FieldProbabilityValue = number;
export type FieldSelectValue = { color: ThemeColor; text: string };
export type FieldSelectValue = { color: ThemeColor; label: string };
export type FieldRelationValue = EntityForSelect | null;

View File

@ -5,7 +5,7 @@ import { mainColors, ThemeColor } from '@/ui/theme/constants/colors';
const selectColors = Object.keys(mainColors) as [ThemeColor, ...ThemeColor[]];
const selectValueSchema = z.object({
color: z.enum(selectColors),
text: z.string(),
label: z.string(),
});
export const isFieldSelectValue = (