mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-03 07:14:38 +03:00
Fixed default currency code in currency field (#5028)
Default currency logic was not handling a specific case where the default currency is empty in the field metadata. I fixed the ternary cascade and made it more explicit, thus also avoiding falling into having an empty currency code being persisted.
This commit is contained in:
parent
7065495223
commit
bc5cfd046c
@ -1,3 +1,5 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { CurrencyCode } from '@/object-record/record-field/types/CurrencyCode';
|
||||
import { FieldCurrencyValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { CurrencyInput } from '@/ui/field/input/components/CurrencyInput';
|
||||
@ -30,13 +32,24 @@ export const CurrencyFieldInput = ({
|
||||
defaultValue,
|
||||
} = useCurrencyField();
|
||||
|
||||
const currencyCode =
|
||||
draftValue?.currencyCode ??
|
||||
((defaultValue as FieldCurrencyValue).currencyCode.replace(
|
||||
/'/g,
|
||||
'',
|
||||
) as CurrencyCode) ??
|
||||
CurrencyCode.USD;
|
||||
const defaultCurrencyCodeWithoutSQLQuotes = (
|
||||
defaultValue as FieldCurrencyValue
|
||||
).currencyCode.replace(/'/g, '') as CurrencyCode;
|
||||
|
||||
const defaultCurrencyCodeIsNotEmpty = isNonEmptyString(
|
||||
defaultCurrencyCodeWithoutSQLQuotes,
|
||||
);
|
||||
|
||||
const draftCurrencyCode = draftValue?.currencyCode;
|
||||
|
||||
const draftCurrencyCodeIsEmptyIsNotEmpty =
|
||||
isNonEmptyString(draftCurrencyCode);
|
||||
|
||||
const currencyCode = draftCurrencyCodeIsEmptyIsNotEmpty
|
||||
? draftCurrencyCode
|
||||
: defaultCurrencyCodeIsNotEmpty
|
||||
? defaultCurrencyCodeWithoutSQLQuotes
|
||||
: CurrencyCode.USD;
|
||||
|
||||
const handleEnter = (newValue: string) => {
|
||||
onEnter?.(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user