Use defaultValue in currency input (#4911)
- Fix default value sent to backend, using single quotes by default - Use default value in field definition and column definition so that field inputs can access it - Used currency default value in CurrencyFieldInput --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -264,6 +264,7 @@ export const RecordBoardCard = () => {
|
||||
iconName: fieldDefinition.iconName,
|
||||
type: fieldDefinition.type,
|
||||
metadata: fieldDefinition.metadata,
|
||||
defaultValue: fieldDefinition.defaultValue,
|
||||
},
|
||||
useUpdateRecord: useUpdateOneRecordHook,
|
||||
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
||||
|
||||
@ -64,6 +64,8 @@ export const useCurrencyField = () => {
|
||||
|
||||
const draftValue = useRecoilValue(getDraftValueSelector());
|
||||
|
||||
const defaultValue = fieldDefinition.defaultValue;
|
||||
|
||||
return {
|
||||
fieldDefinition,
|
||||
fieldValue,
|
||||
@ -72,5 +74,6 @@ export const useCurrencyField = () => {
|
||||
setFieldValue,
|
||||
hotkeyScope,
|
||||
persistCurrencyField,
|
||||
defaultValue,
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
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';
|
||||
|
||||
import { FieldInputOverlay } from '../../../../../ui/field/input/components/FieldInputOverlay';
|
||||
@ -21,14 +22,27 @@ export const CurrencyFieldInput = ({
|
||||
onTab,
|
||||
onShiftTab,
|
||||
}: CurrencyFieldInputProps) => {
|
||||
const { hotkeyScope, draftValue, persistCurrencyField, setDraftValue } =
|
||||
useCurrencyField();
|
||||
const {
|
||||
hotkeyScope,
|
||||
draftValue,
|
||||
persistCurrencyField,
|
||||
setDraftValue,
|
||||
defaultValue,
|
||||
} = useCurrencyField();
|
||||
|
||||
const currencyCode =
|
||||
draftValue?.currencyCode ??
|
||||
((defaultValue as FieldCurrencyValue).currencyCode.replace(
|
||||
/'/g,
|
||||
'',
|
||||
) as CurrencyCode) ??
|
||||
CurrencyCode.USD;
|
||||
|
||||
const handleEnter = (newValue: string) => {
|
||||
onEnter?.(() => {
|
||||
persistCurrencyField({
|
||||
amountText: newValue,
|
||||
currencyCode: draftValue?.currencyCode ?? CurrencyCode.USD,
|
||||
currencyCode,
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -37,7 +51,7 @@ export const CurrencyFieldInput = ({
|
||||
onEscape?.(() => {
|
||||
persistCurrencyField({
|
||||
amountText: newValue,
|
||||
currencyCode: draftValue?.currencyCode ?? CurrencyCode.USD,
|
||||
currencyCode,
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -49,7 +63,7 @@ export const CurrencyFieldInput = ({
|
||||
onClickOutside?.(() => {
|
||||
persistCurrencyField({
|
||||
amountText: newValue,
|
||||
currencyCode: draftValue?.currencyCode ?? CurrencyCode.USD,
|
||||
currencyCode,
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -58,7 +72,7 @@ export const CurrencyFieldInput = ({
|
||||
onTab?.(() => {
|
||||
persistCurrencyField({
|
||||
amountText: newValue,
|
||||
currencyCode: draftValue?.currencyCode ?? CurrencyCode.USD,
|
||||
currencyCode,
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -67,7 +81,7 @@ export const CurrencyFieldInput = ({
|
||||
onShiftTab?.(() =>
|
||||
persistCurrencyField({
|
||||
amountText: newValue,
|
||||
currencyCode: draftValue?.currencyCode ?? CurrencyCode.USD,
|
||||
currencyCode,
|
||||
}),
|
||||
);
|
||||
};
|
||||
@ -75,7 +89,7 @@ export const CurrencyFieldInput = ({
|
||||
const handleChange = (newValue: string) => {
|
||||
setDraftValue({
|
||||
amount: newValue,
|
||||
currencyCode: draftValue?.currencyCode ?? CurrencyCode.USD,
|
||||
currencyCode,
|
||||
});
|
||||
};
|
||||
|
||||
@ -90,7 +104,7 @@ export const CurrencyFieldInput = ({
|
||||
<FieldInputOverlay>
|
||||
<CurrencyInput
|
||||
value={draftValue?.amount?.toString() ?? ''}
|
||||
currencyCode={draftValue?.currencyCode ?? CurrencyCode.USD}
|
||||
currencyCode={currencyCode}
|
||||
autoFocus
|
||||
placeholder="Currency"
|
||||
onClickOutside={handleClickOutside}
|
||||
|
||||
@ -23,4 +23,5 @@ export type FieldDefinition<T extends FieldMetadata> = {
|
||||
type: FieldMetadataType;
|
||||
metadata: T;
|
||||
infoTooltipContent?: string;
|
||||
defaultValue: any;
|
||||
};
|
||||
|
||||
@ -155,6 +155,8 @@ export const RecordShowContainer = ({
|
||||
labelIdentifierFieldMetadataItem?.name || '',
|
||||
objectMetadataNameSingular: objectNameSingular,
|
||||
},
|
||||
defaultValue:
|
||||
labelIdentifierFieldMetadataItem?.defaultValue,
|
||||
},
|
||||
useUpdateRecord: useUpdateOneObjectRecordMutation,
|
||||
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
||||
|
||||
Reference in New Issue
Block a user