diff --git a/packages/twenty-front/src/modules/localization/utils/formatDateISOStringToDateTime.ts b/packages/twenty-front/src/modules/localization/utils/formatDateISOStringToDateTime.ts index c812e12f287..50407e17fb8 100644 --- a/packages/twenty-front/src/modules/localization/utils/formatDateISOStringToDateTime.ts +++ b/packages/twenty-front/src/modules/localization/utils/formatDateISOStringToDateTime.ts @@ -1,5 +1,6 @@ import { type DateFormat } from '@/localization/constants/DateFormat'; import { type TimeFormat } from '@/localization/constants/TimeFormat'; +import { isValid } from 'date-fns'; import { formatInTimeZone } from 'date-fns-tz'; export const formatDateISOStringToDateTime = ({ @@ -15,14 +16,15 @@ export const formatDateISOStringToDateTime = ({ timeFormat: TimeFormat; localeCatalog: Locale; }) => { + const parsedDate = new Date(date); + + if (!isValid(parsedDate)) { + return ''; + } + // TODO: replace this with shiftPointInTimeToFromTimezoneDifference to remove date-fns-tz, which formatInTimeZone is doig under the hood : // https://github.com/marnusw/date-fns-tz/blob/4f3383b26a5907a73b14512a2701f3dfd8cf1579/src/toZonedTime/index.ts#L36C9-L36C27 - return formatInTimeZone( - new Date(date), - timeZone, - `${dateFormat} ${timeFormat}`, - { - locale: localeCatalog, - }, - ); + return formatInTimeZone(parsedDate, timeZone, `${dateFormat} ${timeFormat}`, { + locale: localeCatalog, + }); }; diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getFieldLinkDefinedLinks.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getFieldLinkDefinedLinks.test.ts index 0856c382fc6..9dec3106ad3 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getFieldLinkDefinedLinks.test.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getFieldLinkDefinedLinks.test.ts @@ -1,6 +1,23 @@ import { getFieldLinkDefinedLinks } from '@/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks'; +import { type FieldLinksValue } from '@/object-record/record-field/ui/types/FieldMetadata'; describe('getFieldLinkDefinedLinks', () => { + describe('Field value', () => { + it('should return an empty array if fieldValue is undefined', () => { + const result = getFieldLinkDefinedLinks( + undefined as unknown as FieldLinksValue, + ); + expect(result).toEqual([]); + }); + + it('should return an empty array if fieldValue is null', () => { + const result = getFieldLinkDefinedLinks( + null as unknown as FieldLinksValue, + ); + expect(result).toEqual([]); + }); + }); + describe('Primary link', () => { it('should not return primary link when primaryLinkUrl is null', () => { expect( diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks.ts index d895c09148c..a6f9ea236f0 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks.ts @@ -3,6 +3,10 @@ import { isNonEmptyString } from '@sniptt/guards'; import { isDefined, isValidUrl } from 'twenty-shared/utils'; export const getFieldLinkDefinedLinks = (fieldValue: FieldLinksValue) => { + if (!isDefined(fieldValue)) { + return []; + } + return [ isNonEmptyString(fieldValue.primaryLinkUrl) ? { diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx index 624b74d0502..44f6a92d180 100644 --- a/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx +++ b/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx @@ -69,7 +69,9 @@ export const SettingsDataModelFieldPreview = ({ labelIdentifierFieldMetadataItem?.name === fieldMetadataItem.name; const fieldName = fieldMetadataItem.name; - const recordId = `${objectNameSingular}-${fieldName}-preview`; + const fieldType = fieldMetadataItem.type; + + const recordId = `${objectNameSingular}-${fieldName}-${fieldType}-preview`; const fieldPreviewValue = useFieldPreviewValue({ fieldMetadataItem, diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelRelationFieldPreview.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelRelationFieldPreview.tsx index 74eda82249a..3888acecdf7 100644 --- a/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelRelationFieldPreview.tsx +++ b/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelRelationFieldPreview.tsx @@ -72,7 +72,7 @@ export const SettingsDataModelRelationFieldPreview = ({ const fieldName = v4(); - const recordId = `${relationTargetObjectNameSingular}-${fieldName}-preview`; + const recordId = `${relationTargetObjectNameSingular}-${fieldName}-RELATION-preview`; const isRelation = fieldMetadataItem.type === FieldMetadataType.RELATION; const metadata = {