Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed default currency code in currency field #5028

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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?.(() => {
Expand Down
Loading