mirror of
https://github.com/lingble/twenty.git
synced 2025-10-30 20:27:55 +00:00
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 { FieldInputOverlay } from '../../../../../ui/field/input/components/FieldInputOverlay';
|
||||||
import { useCurrencyField } from '../../hooks/useCurrencyField';
|
import { useCurrencyField } from '../../hooks/useCurrencyField';
|
||||||
|
|
||||||
|
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
import { FieldInputEvent } from './DateTimeFieldInput';
|
||||||
|
|
||||||
type CurrencyFieldInputProps = {
|
type CurrencyFieldInputProps = {
|
||||||
@@ -108,7 +109,7 @@ export const CurrencyFieldInput = ({
|
|||||||
|
|
||||||
const handleSelect = (newValue: string) => {
|
const handleSelect = (newValue: string) => {
|
||||||
setDraftValue({
|
setDraftValue({
|
||||||
amount: draftValue?.amount ?? '',
|
amount: isUndefinedOrNull(draftValue?.amount) ? '' : draftValue?.amount,
|
||||||
currencyCode: newValue as CurrencyCode,
|
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 { computeEmptyDraftValue } from '@/object-record/record-field/utils/computeEmptyDraftValue';
|
||||||
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
|
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
|
||||||
import { isDefined } from '~/utils/isDefined';
|
import { isDefined } from '~/utils/isDefined';
|
||||||
|
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||||
|
|
||||||
type computeDraftValueFromFieldValueParams<FieldValue> = {
|
type computeDraftValueFromFieldValueParams<FieldValue> = {
|
||||||
fieldDefinition: Pick<FieldDefinition<FieldMetadata>, 'type'>;
|
fieldDefinition: Pick<FieldDefinition<FieldMetadata>, 'type'>;
|
||||||
@@ -32,7 +33,9 @@ export const computeDraftValueFromFieldValue = <FieldValue>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
amount: fieldValue?.amountMicros ? fieldValue.amountMicros / 1000000 : '',
|
amount: isUndefinedOrNull(fieldValue?.amountMicros)
|
||||||
|
? ''
|
||||||
|
: (fieldValue.amountMicros / 1000000).toString(),
|
||||||
currencyCode: fieldValue?.currencyCode ?? '',
|
currencyCode: fieldValue?.currencyCode ?? '',
|
||||||
} as unknown as FieldInputDraftValue<FieldValue>;
|
} as unknown as FieldInputDraftValue<FieldValue>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ export const CurrencyDisplay = ({ currencyValue }: CurrencyDisplayProps) => {
|
|||||||
? SETTINGS_FIELD_CURRENCY_CODES[currencyValue?.currencyCode]?.Icon
|
? SETTINGS_FIELD_CURRENCY_CODES[currencyValue?.currencyCode]?.Icon
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const amountToDisplay = (currencyValue?.amountMicros ?? 0) / 1000000;
|
const amountToDisplay =
|
||||||
|
currencyValue?.amountMicros != null
|
||||||
|
? currencyValue?.amountMicros / 1000000
|
||||||
|
: null;
|
||||||
|
|
||||||
if (!shouldDisplayCurrency) {
|
if (!shouldDisplayCurrency) {
|
||||||
return <StyledEllipsisDisplay>{0}</StyledEllipsisDisplay>;
|
return <StyledEllipsisDisplay>{0}</StyledEllipsisDisplay>;
|
||||||
@@ -46,7 +49,7 @@ export const CurrencyDisplay = ({ currencyValue }: CurrencyDisplayProps) => {
|
|||||||
/>{' '}
|
/>{' '}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{amountToDisplay !== 0 ? formatAmount(amountToDisplay) : ''}
|
{amountToDisplay !== null ? formatAmount(amountToDisplay) : ''}
|
||||||
</StyledEllipsisDisplay>
|
</StyledEllipsisDisplay>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
||||||
import { IMaskInput, IMaskInputProps } from 'react-imask';
|
|
||||||
import { useTheme } from '@emotion/react';
|
import { useTheme } from '@emotion/react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
import { IMaskInput, IMaskInputProps } from 'react-imask';
|
||||||
import { IconComponent, TEXT_INPUT_STYLE } from 'twenty-ui';
|
import { IconComponent, TEXT_INPUT_STYLE } from 'twenty-ui';
|
||||||
|
|
||||||
import { useRegisterInputEvents } from '@/object-record/record-field/meta-types/input/hooks/useRegisterInputEvents';
|
import { useRegisterInputEvents } from '@/object-record/record-field/meta-types/input/hooks/useRegisterInputEvents';
|
||||||
@@ -138,7 +138,6 @@ export const CurrencyInput = ({
|
|||||||
mask={Number}
|
mask={Number}
|
||||||
thousandsSeparator={','}
|
thousandsSeparator={','}
|
||||||
radix="."
|
radix="."
|
||||||
unmask="typed"
|
|
||||||
onAccept={(value: string) => handleChange(value)}
|
onAccept={(value: string) => handleChange(value)}
|
||||||
inputRef={wrapperRef}
|
inputRef={wrapperRef}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
|
|||||||
Reference in New Issue
Block a user