-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix: enable save button when changing currency default value #16864
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
Changes from 6 commits
eadc43b
7c39547
d36745b
1162eab
ed2f584
be42bfc
2d1e075
aece73e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
| import { isNonEmptyString } from '@sniptt/guards'; | ||
| import { CurrencyCode } from 'twenty-shared/constants'; | ||
| import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
| import { DEFAULT_DECIMAL_VALUE } from '~/utils/format/formatNumber'; | ||
| import { applySimpleQuotesToString } from '~/utils/string/applySimpleQuotesToString'; | ||
| import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString'; | ||
|
|
||
| export const getFieldMetadataItemInitialValues = ( | ||
| fieldMetadataItem: FieldMetadataItem | null | undefined, | ||
| ) => { | ||
| if (fieldMetadataItem?.type !== FieldMetadataType.CURRENCY) { | ||
| return { | ||
| settings: fieldMetadataItem?.settings ?? undefined, | ||
| defaultValue: fieldMetadataItem?.defaultValue ?? undefined, | ||
| }; | ||
| } | ||
|
|
||
| const settings = fieldMetadataItem.settings ?? { | ||
| format: 'short', | ||
| decimals: DEFAULT_DECIMAL_VALUE, | ||
| }; | ||
|
|
||
| const defaultValue = fieldMetadataItem.defaultValue | ||
| ? { | ||
| amountMicros: fieldMetadataItem.defaultValue.amountMicros ?? null, | ||
| currencyCode: isNonEmptyString( | ||
| stripSimpleQuotesFromString( | ||
| fieldMetadataItem.defaultValue.currencyCode, | ||
| ), | ||
| ) | ||
| ? fieldMetadataItem.defaultValue.currencyCode | ||
| : applySimpleQuotesToString(CurrencyCode.USD), | ||
| } | ||
| : { | ||
| amountMicros: null, | ||
| currencyCode: applySimpleQuotesToString(CurrencyCode.USD), | ||
| }; | ||
|
|
||
| return { settings, defaultValue }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { useGetRelationMetadata } from '@/object-metadata/hooks/useGetRelationMe | |
| import { useUpdateOneFieldMetadataItem } from '@/object-metadata/hooks/useUpdateOneFieldMetadataItem'; | ||
| import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural'; | ||
| import { formatFieldMetadataItemInput } from '@/object-metadata/utils/formatFieldMetadataItemInput'; | ||
| import { getFieldMetadataItemInitialValues } from '@/object-metadata/utils/getFieldMetadataItemInitialValues'; | ||
| import { isLabelIdentifierField } from '@/object-metadata/utils/isLabelIdentifierField'; | ||
| import { isObjectMetadataReadOnly } from '@/object-record/read-only/utils/isObjectMetadataReadOnly'; | ||
| import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons'; | ||
|
|
@@ -107,6 +108,9 @@ export const SettingsObjectFieldEdit = () => { | |
| const getRelationMetadata = useGetRelationMetadata(); | ||
| const { updateOneFieldMetadataItem } = useUpdateOneFieldMetadataItem(); | ||
|
|
||
| const { settings, defaultValue } = | ||
| getFieldMetadataItemInitialValues(fieldMetadataItem); | ||
|
|
||
| const formConfig = useForm<SettingsDataModelFieldEditFormValues>({ | ||
| mode: 'onTouched', | ||
| resolver: zodResolver(settingsFieldFormSchema()), | ||
|
|
@@ -116,7 +120,8 @@ export const SettingsObjectFieldEdit = () => { | |
| label: fieldMetadataItem?.label ?? '', | ||
| description: fieldMetadataItem?.description, | ||
| isLabelSyncedWithName: fieldMetadataItem?.isLabelSyncedWithName ?? true, | ||
| settings: fieldMetadataItem?.settings, | ||
| settings, | ||
| defaultValue, | ||
| }, | ||
| }); | ||
|
Comment on lines
116
to
126
This comment was marked as outdated.
Sorry, something went wrong.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name field is intentionally excluded and it has been the case before the changes. It's managed by a child component (SettingsDataModelFieldIconLabelForm) which has its own Controller with defaultValue={fieldMetadataItem?.name}.
Comment on lines
117
to
126
This comment was marked as outdated.
Sorry, something went wrong.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use the values prop to avoid useEffect, consistent with the codebase patterns. React Hook Form performs deep comparison, so isDirty is not reset when values are unchanged.
Comment on lines
120
to
126
This comment was marked as outdated.
Sorry, something went wrong. |
||
|
|
||
|
Comment on lines
120
to
127
This comment was marked as outdated.
Sorry, something went wrong.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The values prop is appropriate here because:
|
||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.