Files
twenty_crm/packages/twenty-front/src/modules/object-metadata/utils/getDefaultValueForBackend.ts
Thaïs bb995d5488 refactor: use react-hook-form for Field type config forms (#5326)
Closes #4295

Note: for the sake of an easier code review, I did not rename/move some
files and added "todo" comments instead so Github is able to match those
files with their previous version.
2024-05-07 21:07:56 +02:00

23 lines
932 B
TypeScript

import { CurrencyCode } from '@/object-record/record-field/types/CurrencyCode';
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 CurrencyCode,
} satisfies FieldCurrencyValue;
} else if (fieldMetadataType === FieldMetadataType.Select) {
return defaultValue ? `'${defaultValue}'` : null;
} else if (fieldMetadataType === FieldMetadataType.MultiSelect) {
return defaultValue.map((value: string) => `'${value}'`);
}
return defaultValue;
};