Skip to content

The open alternative to Salesforce, designed for AI.

fix(front): keep legacy null phone subfields from being dropped (#25420)

Abhinav A Pa5ee5c967317
diff --git a/packages/twenty-front/src/modules/activities/timeline-activities/rows/main-object/components/EventFieldDiffValueEffect.tsx b/packages/twenty-front/src/modules/activities/timeline-activities/rows/main-object/components/EventFieldDiffValueEffect.tsx
index a9e924da59b..531625f90e3 100644
--- a/packages/twenty-front/src/modules/activities/timeline-activities/rows/main-object/components/EventFieldDiffValueEffect.tsx
+++ b/packages/twenty-front/src/modules/activities/timeline-activities/rows/main-object/components/EventFieldDiffValueEffect.tsx
@@ -1,6 +1,10 @@
import { useContext, useEffect } from 'react';
import { TimelineActivityContext } from '@/activities/timeline-activities/contexts/TimelineActivityContext';
+import {
+ normalizeTimelinePhonesDiffValue,
+ type TimelinePhonesDiffValue,
+} from '@/activities/timeline-activities/utils/normalizeTimelinePhonesDiffValue';
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { type FieldFilesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
@@ -55,6 +59,12 @@ export const EventFieldDiffValueEffect = ({
});
}
+ if (fieldMetadataItem.type === FieldMetadataType.PHONES) {
+ fieldValue = normalizeTimelinePhonesDiffValue(
+ diffRecord as TimelinePhonesDiffValue,
+ );
+ }
+
const forgedObjectRecord = {
__typename: mainObjectMetadataItem.nameSingular,
id: diffArtificialRecordStoreId,
diff --git a/packages/twenty-front/src/modules/activities/timeline-activities/utils/__tests__/normalizeTimelinePhonesDiffValue.test.ts b/packages/twenty-front/src/modules/activities/timeline-activities/utils/__tests__/normalizeTimelinePhonesDiffValue.test.ts
new file mode 100644
index 00000000000..02e1044e5dd
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/timeline-activities/utils/__tests__/normalizeTimelinePhonesDiffValue.test.ts
@@ -0,0 +1,101 @@
+import { normalizeTimelinePhonesDiffValue } from '@/activities/timeline-activities/utils/normalizeTimelinePhonesDiffValue';
+import { createPhonesFromFieldValue } from '@/object-record/record-field/ui/meta-types/input/utils/phonesUtils';
+
+describe('normalizeTimelinePhonesDiffValue', () => {
+ it('should parse additionalPhones stored as a JSON string', () => {
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones:
+ '[{"number":"987654321","callingCode":"+44","countryCode":"GB"}]',
+ });
+
+ expect(result.additionalPhones).toEqual([
+ { number: '987654321', callingCode: '+44', countryCode: 'GB' },
+ ]);
+ });
+
+ it('should keep additional phones visible when the primary number is null', () => {
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: null,
+ primaryPhoneCountryCode: null,
+ primaryPhoneCallingCode: null,
+ additionalPhones:
+ '[{"number":"987654321","callingCode":"+44","countryCode":"GB"}]',
+ });
+
+ expect(createPhonesFromFieldValue(result)).toEqual([
+ { number: '987654321', callingCode: '+44', countryCode: 'GB' },
+ ]);
+ });
+
+ it('should leave additionalPhones untouched when it is already an array', () => {
+ const additionalPhones = [
+ { number: '987654321', callingCode: '+44', countryCode: 'GB' },
+ ];
+
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones,
+ });
+
+ expect(result.additionalPhones).toEqual(additionalPhones);
+ });
+
+ it('should fall back to null when additionalPhones is not valid JSON', () => {
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: 'not json',
+ });
+
+ expect(result.additionalPhones).toBeNull();
+ });
+
+ it('should fall back to null when the parsed value is not an array', () => {
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: '{"number":"987654321"}',
+ });
+
+ expect(result.additionalPhones).toBeNull();
+ });
+
+ it('should normalize a missing additionalPhones to null', () => {
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ });
+
+ expect(result.additionalPhones).toBeNull();
+ });
+
+ it.each([
+ ['an empty string', ''],
+ ['a non-array object', { number: '987654321' }],
+ ['a number', 42],
+ ['a boolean', true],
+ ])(
+ 'should normalize additionalPhones stored as %s to null',
+ (_label, additionalPhones) => {
+ const result = normalizeTimelinePhonesDiffValue({
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones,
+ });
+
+ expect(result.additionalPhones).toBeNull();
+ expect(createPhonesFromFieldValue(result)).toEqual([
+ { number: '123456789', callingCode: '+33', countryCode: 'FR' },
+ ]);
+ },
+ );
+});
diff --git a/packages/twenty-front/src/modules/activities/timeline-activities/utils/normalizeTimelinePhonesDiffValue.ts b/packages/twenty-front/src/modules/activities/timeline-activities/utils/normalizeTimelinePhonesDiffValue.ts
new file mode 100644
index 00000000000..7f9260dd84b
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/timeline-activities/utils/normalizeTimelinePhonesDiffValue.ts
@@ -0,0 +1,40 @@
+import { type FieldPhonesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { isNonEmptyString } from '@sniptt/guards';
+import { parseJson } from 'twenty-shared/utils';
+
+export type TimelinePhonesDiffValue = Omit<
+ FieldPhonesValue,
+ 'additionalPhones'
+> & {
+ additionalPhones?: unknown;
+};
+
+export const normalizeTimelinePhonesDiffValue = (
+ diffValue: TimelinePhonesDiffValue,
+): FieldPhonesValue => {
+ const { additionalPhones, ...primaryPhoneFields } = diffValue;
+
+ if (Array.isArray(additionalPhones)) {
+ return {
+ ...primaryPhoneFields,
+ additionalPhones,
+ };
+ }
+
+ if (!isNonEmptyString(additionalPhones)) {
+ return {
+ ...primaryPhoneFields,
+ additionalPhones: null,
+ };
+ }
+
+ const parsedAdditionalPhones =
+ parseJson<FieldPhonesValue['additionalPhones']>(additionalPhones);
+
+ return {
+ ...primaryPhoneFields,
+ additionalPhones: Array.isArray(parsedAdditionalPhones)
+ ? parsedAdditionalPhones
+ : null,
+ };
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormPhoneFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormPhoneFieldInput.tsx
index 40b8575eabd..4155a09dc7a 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormPhoneFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormPhoneFieldInput.tsx
@@ -50,7 +50,7 @@ export const FormPhoneFieldInput = ({
<FormCallingCodeSelectInput
label={t`Calling Code`}
selectedCountryCode={defaultValue?.primaryPhoneCountryCode ?? ''}
- selectedCallingCode={defaultValue?.primaryPhoneCallingCode}
+ selectedCallingCode={defaultValue?.primaryPhoneCallingCode ?? ''}
onChange={handleCallingCodeChange}
readonly={readonly}
VariablePicker={VariablePicker}
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/phonesUtils.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/phonesUtils.test.ts
index df7939963b3..a27280b9c66 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/phonesUtils.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/phonesUtils.test.ts
@@ -126,4 +126,62 @@ describe('createPhonesFromFieldValue test suite', () => {
const result = createPhonesFromFieldValue(fieldValue);
expect(result).toEqual([]);
});
+
+ it('should return an array with primary phone number if its country and calling codes are null', () => {
+ const fieldValue: FieldPhonesValue = {
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: null,
+ primaryPhoneCallingCode: null,
+ additionalPhones: null,
+ };
+ const result = createPhonesFromFieldValue(fieldValue);
+ expect(result).toEqual([
+ { number: '123456789', callingCode: '', countryCode: '' },
+ ]);
+ });
+
+ it('should return an empty array if the primary phone number is null', () => {
+ const fieldValue: FieldPhonesValue = {
+ primaryPhoneNumber: null,
+ primaryPhoneCountryCode: null,
+ primaryPhoneCallingCode: null,
+ additionalPhones: null,
+ };
+ const result = createPhonesFromFieldValue(fieldValue);
+ expect(result).toEqual([]);
+ });
+
+ it('should default the null subfields of an additional phone', () => {
+ const fieldValue: FieldPhonesValue = {
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: [
+ { number: '987654321', callingCode: null, countryCode: null },
+ ],
+ };
+ const result = createPhonesFromFieldValue(fieldValue);
+ expect(result).toEqual([
+ { number: '123456789', callingCode: '+33', countryCode: 'FR' },
+ { number: '987654321', callingCode: '', countryCode: '' },
+ ]);
+ });
+
+ it('should drop additional phones that have no number', () => {
+ const fieldValue: FieldPhonesValue = {
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: [
+ { number: '', callingCode: '', countryCode: '' },
+ { number: '987654321', callingCode: '+44', countryCode: 'GB' },
+ { number: null, callingCode: null, countryCode: null },
+ ],
+ };
+ const result = createPhonesFromFieldValue(fieldValue);
+ expect(result).toEqual([
+ { number: '123456789', callingCode: '+33', countryCode: 'FR' },
+ { number: '987654321', callingCode: '+44', countryCode: 'GB' },
+ ]);
+ });
});
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/phonesUtils.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/phonesUtils.ts
index 831eece5d62..0233a49058b 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/phonesUtils.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/phonesUtils.ts
@@ -1,19 +1,40 @@
-import { type FieldPhonesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import {
+ type FieldPhonesValue,
+ type PhoneRecord,
+} from '@/object-record/record-field/ui/types/FieldMetadata';
+import { isNonEmptyString } from '@sniptt/guards';
import { isDefined } from 'twenty-shared/utils';
-export const createPhonesFromFieldValue = (fieldValue: FieldPhonesValue) => {
- return !isDefined(fieldValue)
- ? []
- : [
- fieldValue.primaryPhoneNumber
- ? {
- number: fieldValue.primaryPhoneNumber,
- callingCode: fieldValue.primaryPhoneCallingCode
- ? fieldValue.primaryPhoneCallingCode
- : fieldValue.primaryPhoneCountryCode,
- countryCode: fieldValue.primaryPhoneCountryCode,
- }
- : null,
- ...(fieldValue.additionalPhones ?? []),
- ].filter(isDefined);
+export const createPhonesFromFieldValue = (
+ fieldValue: FieldPhonesValue,
+): PhoneRecord[] => {
+ if (!isDefined(fieldValue)) {
+ return [];
+ }
+
+ return [
+ isNonEmptyString(fieldValue.primaryPhoneNumber)
+ ? {
+ number: fieldValue.primaryPhoneNumber,
+ callingCode: isNonEmptyString(fieldValue.primaryPhoneCallingCode)
+ ? fieldValue.primaryPhoneCallingCode
+ : fieldValue.primaryPhoneCountryCode,
+ countryCode: fieldValue.primaryPhoneCountryCode,
+ }
+ : null,
+ ...(fieldValue.additionalPhones ?? []),
+ ]
+ .filter(isDefined)
+ .map((phone) => {
+ if (!isNonEmptyString(phone.number)) {
+ return undefined;
+ }
+
+ return {
+ number: phone.number,
+ callingCode: phone.callingCode ?? '',
+ countryCode: phone.countryCode ?? '',
+ };
+ })
+ .filter(isDefined);
};
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/types/FieldMetadata.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/types/FieldMetadata.ts
index 37be615acdd..f76286bceb6 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/types/FieldMetadata.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/types/FieldMetadata.ts
@@ -337,11 +337,17 @@ export type PhoneRecord = {
countryCode: string;
};
+export type PhoneRecordNullable = {
+ number: string | null;
+ callingCode: string | null;
+ countryCode: string | null;
+};
+
export type FieldPhonesValue = {
- primaryPhoneNumber: string;
- primaryPhoneCountryCode: string;
- primaryPhoneCallingCode?: string;
- additionalPhones?: PhoneRecord[] | null;
+ primaryPhoneNumber: string | null;
+ primaryPhoneCountryCode: string | null;
+ primaryPhoneCallingCode?: string | null;
+ additionalPhones?: PhoneRecordNullable[] | null;
};
export type FieldFilesValue = {
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldDefaultValueSchema.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldDefaultValueSchema.test.ts
index ff311c3f2b1..04b660d87d5 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldDefaultValueSchema.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldDefaultValueSchema.test.ts
@@ -1,5 +1,4 @@
import { phonesFieldDefaultValueSchema } from '@/object-record/record-field/ui/validation-schemas/phonesFieldDefaultValueSchema';
-import { phonesFieldValueSchema } from '@/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema';
describe('phonesFieldDefaultValueSchema', () => {
it('should accept a fully populated default value', () => {
@@ -22,6 +21,5 @@ describe('phonesFieldDefaultValueSchema', () => {
};
expect(phonesFieldDefaultValueSchema.safeParse(value).success).toBe(true);
- expect(phonesFieldValueSchema.safeParse(value).success).toBe(false);
});
});
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldValueSchema.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldValueSchema.test.ts
new file mode 100644
index 00000000000..580adfc6dff
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/__tests__/phonesFieldValueSchema.test.ts
@@ -0,0 +1,27 @@
+import { phonesFieldValueSchema } from '@/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema';
+
+describe('phonesFieldValueSchema', () => {
+ it('should accept null primary phone subfields', () => {
+ const value = {
+ primaryPhoneNumber: null,
+ primaryPhoneCountryCode: null,
+ primaryPhoneCallingCode: null,
+ additionalPhones: null,
+ };
+
+ expect(phonesFieldValueSchema.safeParse(value).success).toBe(true);
+ });
+
+ it('should accept null subfields on an additional phone', () => {
+ const value = {
+ primaryPhoneNumber: '123456789',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: [
+ { number: '987654321', callingCode: null, countryCode: null },
+ ],
+ };
+
+ expect(phonesFieldValueSchema.safeParse(value).success).toBe(true);
+ });
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema.ts
index 3f6bd173c2d..68655676cab 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema.ts
@@ -3,15 +3,15 @@ import { z } from 'zod';
import { type FieldPhonesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
export const phonesFieldValueSchema = z.object({
- primaryPhoneNumber: z.string(),
- primaryPhoneCountryCode: z.string(),
- primaryPhoneCallingCode: z.string().optional(),
+ primaryPhoneNumber: z.string().nullable(),
+ primaryPhoneCountryCode: z.string().nullable(),
+ primaryPhoneCallingCode: z.string().nullable().optional(),
additionalPhones: z
.array(
z.object({
- number: z.string(),
- callingCode: z.string(),
- countryCode: z.string(),
+ number: z.string().nullable(),
+ callingCode: z.string().nullable(),
+ countryCode: z.string().nullable(),
}),
)
.nullable(),
diff --git a/packages/twenty-front/src/modules/ui/field/display/components/PhonesDisplay.tsx b/packages/twenty-front/src/modules/ui/field/display/components/PhonesDisplay.tsx
index 23a1deae8c6..45c0b467fd5 100644
--- a/packages/twenty-front/src/modules/ui/field/display/components/PhonesDisplay.tsx
+++ b/packages/twenty-front/src/modules/ui/field/display/components/PhonesDisplay.tsx
@@ -1,6 +1,6 @@
-import { t } from '@lingui/core/macro';
import React, { useMemo } from 'react';
+import { createPhonesFromFieldValue } from '@/object-record/record-field/ui/meta-types/input/utils/phonesUtils';
import { type FieldPhonesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
import { ExpandableList } from '@/ui/layout/expandable-list/components/ExpandableList';
@@ -8,7 +8,6 @@ import { styled } from '@linaria/react';
import { parsePhoneNumber } from 'libphonenumber-js';
import { isDefined } from 'twenty-shared/utils';
import { RoundedLink } from 'twenty-ui/primitives/navigation';
-import { logError } from '~/utils/logError';
type PhonesDisplayProps = {
value?: FieldPhonesValue;
@@ -37,34 +36,13 @@ export const PhonesDisplay = ({
isFocused,
onPhoneNumberClick,
}: PhonesDisplayProps) => {
- const phones = useMemo(
- () =>
- [
- value?.primaryPhoneNumber
- ? {
- number: value.primaryPhoneNumber,
- callingCode:
- value.primaryPhoneCallingCode ||
- value.primaryPhoneCountryCode ||
- '',
- }
- : null,
- ...parseAdditionalPhones(value?.additionalPhones),
- ]
- .filter(isDefined)
- .map(({ number, callingCode }) => {
- return {
- number,
- callingCode,
- };
- }),
- [
- value?.primaryPhoneNumber,
- value?.primaryPhoneCallingCode,
- value?.primaryPhoneCountryCode,
- value?.additionalPhones,
- ],
- );
+ const phones = useMemo(() => {
+ if (!isDefined(value)) {
+ return [];
+ }
+
+ return createPhonesFromFieldValue(value);
+ }, [value]);
const parsePhoneNumberOrReturnInvalidValue = (number: string) => {
try {
return { parsedPhone: parsePhoneNumber(number) };
@@ -115,23 +93,3 @@ export const PhonesDisplay = ({
</StyledContainer>
);
};
-
-const parseAdditionalPhones = (additionalPhones?: any) => {
- if (!additionalPhones) {
- return [];
- }
-
- if (typeof additionalPhones === 'object') {
- return additionalPhones;
- }
-
- if (typeof additionalPhones === 'string') {
- try {
- return JSON.parse(additionalPhones);
- } catch (error) {
- logError(t`Error parsing additional phones: ${String(error)}`);
- }
- }
-
- return [];
-};
diff --git a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-phones-value.util.spec.ts b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-phones-value.util.spec.ts
index aa3cd85293e..364eb552a5f 100644
--- a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-phones-value.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-phones-value.util.spec.ts
@@ -24,7 +24,7 @@ describe('transformPhonesValue', () => {
});
});
- it('should normalize empty number inside an additionalPhones entry to null', () => {
+ it('should drop an additionalPhones entry that has no number', () => {
const result = transformPhonesValue({
input: {
primaryPhoneNumber: '',
@@ -32,7 +32,25 @@ describe('transformPhonesValue', () => {
},
});
- expect(result?.additionalPhones).toBe(JSON.stringify([{ number: null }]));
+ expect(result?.additionalPhones).toBeNull();
+ });
+
+ it('should keep valid additionalPhones entries while dropping numberless ones', () => {
+ const result = transformPhonesValue({
+ input: {
+ primaryPhoneNumber: '',
+ additionalPhones: JSON.stringify([
+ { number: '' },
+ { number: '+442071838750', callingCode: '+44', countryCode: 'GB' },
+ ]),
+ },
+ });
+
+ expect(result?.additionalPhones).toBe(
+ JSON.stringify([
+ { countryCode: 'GB', callingCode: '+44', number: '2071838750' },
+ ]),
+ );
});
it('should parse a valid international phone number into its canonical parts', () => {
diff --git a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-phones-value.util.ts b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-phones-value.util.ts
index 819bd0241d7..d10e4a97a2f 100644
--- a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-phones-value.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-phones-value.util.ts
@@ -210,9 +210,9 @@ export const transformPhonesValue = ({
? additionalPhones
: [];
- const validatedAdditionalPhones = parsedAdditionalPhones.map(
- validateAndInferPhoneInput,
- );
+ const validatedAdditionalPhones = parsedAdditionalPhones
+ .filter((additionalPhone) => isNonEmptyString(additionalPhone.number))
+ .map(validateAndInferPhoneInput);
return removeUndefinedFields({
additionalPhones: isEmpty(validatedAdditionalPhones)
diff --git a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/constants/successful-create-input-by-field-metadata-type.constant.ts b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/constants/successful-create-input-by-field-metadata-type.constant.ts
index 7cd644cebd8..c8d32ae52cf 100644
--- a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/constants/successful-create-input-by-field-metadata-type.constant.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/create-validation/constants/successful-create-input-by-field-metadata-type.constant.ts
@@ -342,6 +342,25 @@ export const successfulCreateInputByFieldMetadataType: {
);
},
},
+ {
+ input: {
+ phonesField: {
+ primaryPhoneNumber: '1234567890',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: [
+ { number: '', callingCode: '+33', countryCode: 'FR' },
+ { number: '1234567890', callingCode: '+33', countryCode: 'FR' },
+ ],
+ },
+ },
+ validateInput: (record: Record<string, any>) => {
+ return (
+ record.phonesField.additionalPhones.length === 1 &&
+ record.phonesField.additionalPhones[0].number === '1234567890'
+ );
+ },
+ },
],
[FieldMetadataType.FULL_NAME]: [
{
diff --git a/packages/twenty-server/test/integration/metadata/suites/field-metadata/composite/successful-create-phone-field-metadata.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/field-metadata/composite/successful-create-phone-field-metadata.integration-spec.ts
index a549b9e2927..4a60198f80f 100644
--- a/packages/twenty-server/test/integration/metadata/suites/field-metadata/composite/successful-create-phone-field-metadata.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/field-metadata/composite/successful-create-phone-field-metadata.integration-spec.ts
@@ -215,9 +215,7 @@ const SUCCESSFUL_TEST_CASES: EachTestingContext<CreatePhoneFieldMetadataTestCase
primaryPhoneCallingCode: '',
primaryPhoneCountryCode: '' as CountryCode,
primaryPhoneNumber: '',
- additionalPhones: [
- { callingCode: null, countryCode: null, number: null },
- ],
+ additionalPhones: [],
},
},
},