Use defaultValue in currency input (#4911)

- Fix default value sent to backend, using single quotes by default
- Use default value in field definition and column definition so that
field inputs can access it
- Used currency default value in CurrencyFieldInput

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau
2024-04-11 16:49:00 +02:00
committed by GitHub
parent e48960afbe
commit c69a3f01da
17 changed files with 188 additions and 103 deletions

View File

@ -43,5 +43,6 @@ export const formatFieldMetadataItemAsFieldDefinition = ({
options: field.options,
},
iconName: field.icon ?? 'Icon123',
defaultValue: field.defaultValue,
};
};

View File

@ -0,0 +1,19 @@
import { FieldCurrencyValue } from '@/object-record/record-field/types/FieldMetadata';
import { FieldMetadataType } from '~/generated-metadata/graphql';
export const getDefaultValueForBackend = (
defaultValue: any,
fieldMetadataType: FieldMetadataType,
) => {
if (fieldMetadataType === FieldMetadataType.Currency) {
const currencyDefaultValue = defaultValue as FieldCurrencyValue;
return {
amountMicros: currencyDefaultValue.amountMicros,
currencyCode: `'${currencyDefaultValue.currencyCode}'` as any,
} satisfies FieldCurrencyValue;
} else if (typeof defaultValue === 'string') {
return `'${defaultValue}'`;
}
return defaultValue;
};