fix: zero showing in record cell and page (#7384)
This PR fixes zero being displayed as empty in record cell and show page in currency field #6802 I checked graphql resquests and the data is stored in the correct form (0 or null). The problem only lies in the front end and how the field is null checked. --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -7,6 +7,7 @@ import { CurrencyInput } from '@/ui/field/input/components/CurrencyInput';
|
||||
import { FieldInputOverlay } from '../../../../../ui/field/input/components/FieldInputOverlay';
|
||||
import { useCurrencyField } from '../../hooks/useCurrencyField';
|
||||
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
||||
|
||||
type CurrencyFieldInputProps = {
|
||||
@ -108,7 +109,7 @@ export const CurrencyFieldInput = ({
|
||||
|
||||
const handleSelect = (newValue: string) => {
|
||||
setDraftValue({
|
||||
amount: draftValue?.amount ?? '',
|
||||
amount: isUndefinedOrNull(draftValue?.amount) ? '' : draftValue?.amount,
|
||||
currencyCode: newValue as CurrencyCode,
|
||||
});
|
||||
};
|
||||
|
||||
@ -9,6 +9,7 @@ import { isFieldRelation } from '@/object-record/record-field/types/guards/isFie
|
||||
import { computeEmptyDraftValue } from '@/object-record/record-field/utils/computeEmptyDraftValue';
|
||||
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
|
||||
type computeDraftValueFromFieldValueParams<FieldValue> = {
|
||||
fieldDefinition: Pick<FieldDefinition<FieldMetadata>, 'type'>;
|
||||
@ -32,7 +33,9 @@ export const computeDraftValueFromFieldValue = <FieldValue>({
|
||||
}
|
||||
|
||||
return {
|
||||
amount: fieldValue?.amountMicros ? fieldValue.amountMicros / 1000000 : '',
|
||||
amount: isUndefinedOrNull(fieldValue?.amountMicros)
|
||||
? ''
|
||||
: (fieldValue.amountMicros / 1000000).toString(),
|
||||
currencyCode: fieldValue?.currencyCode ?? '',
|
||||
} as unknown as FieldInputDraftValue<FieldValue>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user