feat: select default Unit for Currency field (#2996)
Closes #2347 Co-authored-by: Thais GUIGON <thaisguigon@macbook-pro.home>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { useContext } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { CurrencyCode } from '@/object-record/field/types/CurrencyCode';
|
||||
import { FieldInitialValue } from '@/object-record/field/types/FieldInitialValue';
|
||||
import { canBeCastAsIntegerOrNull } from '~/utils/cast-as-integer-or-null';
|
||||
import {
|
||||
@ -22,17 +23,17 @@ const initializeValue = (
|
||||
fieldValue: FieldCurrencyValue,
|
||||
) => {
|
||||
if (fieldInitialValue?.isEmpty) {
|
||||
return { amount: null, currencyCode: 'USD' };
|
||||
return { amount: null, currencyCode: CurrencyCode.USD };
|
||||
}
|
||||
if (!isNaN(Number(fieldInitialValue?.value))) {
|
||||
return {
|
||||
amount: Number(fieldInitialValue?.value),
|
||||
currencyCode: 'USD',
|
||||
currencyCode: CurrencyCode.USD,
|
||||
};
|
||||
}
|
||||
|
||||
if (!fieldValue) {
|
||||
return { amount: null, currencyCode: 'USD' };
|
||||
return { amount: null, currencyCode: CurrencyCode.USD };
|
||||
}
|
||||
|
||||
return {
|
||||
@ -73,7 +74,7 @@ export const useCurrencyField = () => {
|
||||
amountMicros: isNaN(amount)
|
||||
? null
|
||||
: convertCurrencyToCurrencyMicros(amount),
|
||||
currencyCode: currencyCode,
|
||||
currencyCode,
|
||||
};
|
||||
|
||||
if (!isFieldCurrencyValue(newCurrencyValue)) {
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
export enum CurrencyCode {
|
||||
CAD = 'CAD',
|
||||
CHF = 'CHF',
|
||||
CNY = 'CNY',
|
||||
EUR = 'EUR',
|
||||
GBP = 'GBP',
|
||||
HKD = 'HKD',
|
||||
JPY = 'JPY',
|
||||
USD = 'USD',
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
|
||||
import { ThemeColor } from '@/ui/theme/constants/colors';
|
||||
|
||||
import { CurrencyCode } from './CurrencyCode';
|
||||
|
||||
export type FieldUuidMetadata = {
|
||||
objectMetadataNameSingular?: string;
|
||||
fieldName: string;
|
||||
@ -111,7 +113,7 @@ export type FieldPhoneValue = string;
|
||||
export type FieldEmailValue = string;
|
||||
export type FieldLinkValue = { url: string; label: string };
|
||||
export type FieldCurrencyValue = {
|
||||
currencyCode: string;
|
||||
currencyCode: CurrencyCode;
|
||||
amountMicros: number | null;
|
||||
};
|
||||
export type FieldFullNameValue = { firstName: string; lastName: string };
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { CurrencyCode } from '../CurrencyCode';
|
||||
import { FieldCurrencyValue } from '../FieldMetadata';
|
||||
|
||||
const currencySchema = z.object({
|
||||
currencyCode: z.string().nullable(),
|
||||
currencyCode: z.nativeEnum(CurrencyCode).nullable(),
|
||||
amountMicros: z.number().nullable(),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user