Skip to content

The open alternative to Salesforce, designed for AI.

Edit phones, links, files and full name in the record form (#28757)

Charles Bochet1e64974a89ae
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/FilesFieldLabelInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/FilesFieldLabelInput.tsx
index 96b7b984e1d..161ad37e1b3 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/FilesFieldLabelInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/FilesFieldLabelInput.tsx
@@ -17,7 +17,7 @@ const StyledFilesFieldLabelInputContainer = styled.div`
type FilesFieldLabelInputProps = {
file: FieldFilesValue;
value: string;
- hasError: boolean;
+ hasError?: boolean;
onChange: (value: string) => void;
onEnter: () => void;
onEscape: () => void;
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldEditInputs.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldEditInputs.tsx
index 17b337610e7..1fc462d225f 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldEditInputs.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldEditInputs.tsx
@@ -1,9 +1,8 @@
+import { getMultiItemInputKeyDownHandler } from '@/object-record/record-field/ui/meta-types/input/utils/getMultiItemInputKeyDownHandler';
import { TextInput } from '@/ui/input/components/TextInput';
-import { isKeyboardEventComposing } from '@/ui/utilities/hotkey/utils/isKeyboardEventComposing';
import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
-import { type KeyboardEvent, useCallback } from 'react';
-import { Key } from 'ts-key-enum';
+import { useCallback } from 'react';
import { themeCssVariables } from 'twenty-ui/theme';
const StyledLinksFieldEditInputsContainer = styled.div`
@@ -20,6 +19,8 @@ type LinksFieldEditInputsProps = {
onUrlChange: (url: string) => void;
onLabelChange: (label: string) => void;
onEnter: () => void;
+ onEscape?: () => void;
+ onUrlBlur?: () => void;
};
export const LinksFieldEditInputs = ({
@@ -29,23 +30,14 @@ export const LinksFieldEditInputs = ({
onUrlChange,
onLabelChange,
onEnter,
+ onEscape,
+ onUrlBlur,
}: LinksFieldEditInputsProps) => {
const scrollIntoViewOnMount = useCallback((node: HTMLDivElement | null) => {
node?.scrollIntoView({ block: 'nearest' });
}, []);
- const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
- if (
- event.key !== Key.Enter ||
- isKeyboardEventComposing(event.nativeEvent)
- ) {
- return;
- }
-
- event.preventDefault();
- event.stopPropagation();
- onEnter();
- };
+ const handleKeyDown = getMultiItemInputKeyDownHandler({ onEnter, onEscape });
return (
<StyledLinksFieldEditInputsContainer ref={scrollIntoViewOnMount}>
@@ -53,6 +45,7 @@ export const LinksFieldEditInputs = ({
label={t`URL`}
value={url}
onChange={onUrlChange}
+ onBlur={onUrlBlur}
onKeyDown={handleKeyDown}
error={hasError ? t`Enter a valid URL` : undefined}
noErrorHelper
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldInput.tsx
index 648f79ba951..8947f21baef 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/LinksFieldInput.tsx
@@ -18,6 +18,7 @@ import { useMultiItemSearch } from '@/object-record/record-field/ui/meta-types/i
import { type LinkRecord } from '@/object-record/record-field/ui/meta-types/input/types/LinkRecord';
import { getFieldLinkDefinedLinks } from '@/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks';
import { computeUpdatedMultiItemFieldItems } from '@/object-record/record-field/ui/meta-types/input/utils/computeUpdatedMultiItemFieldItems';
+import { validateLinkInput } from '@/object-record/record-field/ui/meta-types/input/utils/validateLinkInput';
import { getLinkLabelFromDraft } from '@/object-record/record-field/ui/meta-types/input/utils/getLinkLabelFromDraft';
import { type MultiItemFieldInputSpacing } from '@/object-record/record-field/ui/meta-types/input/types/MultiItemFieldInputSpacing';
import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';
@@ -27,12 +28,7 @@ import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSe
import { useLingui } from '@lingui/react/macro';
import { useContext, useMemo, useRef, useState } from 'react';
import { MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES } from 'twenty-shared/constants';
-import {
- absoluteUrlSchema,
- isDefined,
- isNonEmptyArray,
- isValidDomain,
-} from 'twenty-shared/utils';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { moveArrayItem } from '~/utils/array/moveArrayItem';
import { toSpliced } from '~/utils/array/toSpliced';
@@ -107,12 +103,8 @@ export const LinksFieldInput = () => {
settings: fieldDefinition.metadata.settings,
}) === 'domain';
- const validateLink = (input: string) => ({
- isValid: isDomainField
- ? isValidDomain(input)
- : absoluteUrlSchema.safeParse(input).success,
- errorMessage: '',
- });
+ const validateLink = (input: string) =>
+ validateLinkInput({ input, isDomainField });
const isSingleItemMode = maxNumberOfValues === 1;
const isLimitReached = links.length >= maxNumberOfValues;
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldInput.tsx
index d1407386d22..aad70689089 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldInput.tsx
@@ -5,13 +5,16 @@ import { MultiItemFieldAddButton } from '@/object-record/record-field/ui/meta-ty
import { MultiItemFieldInputRow } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldInputRow';
import { MultiItemFieldList } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldList';
import { MultiItemFieldSaveButton } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldSaveButton';
+import { PhonesFieldPhoneInput } from '@/object-record/record-field/ui/meta-types/input/components/PhonesFieldPhoneInput';
import { PhonesFieldMenuItem } from '@/object-record/record-field/ui/meta-types/input/components/PhonesFieldMenuItem';
import { MULTI_ITEM_FIELD_INPUT_DROPDOWN_ID_PREFIX } from '@/object-record/record-field/ui/meta-types/input/constants/MultiItemFieldInputDropdownClickOutsideId';
import { useMultiItemFieldDismiss } from '@/object-record/record-field/ui/meta-types/input/hooks/useMultiItemFieldDismiss';
import { useMultiItemInput } from '@/object-record/record-field/ui/meta-types/input/hooks/useMultiItemInput';
import { useMultiItemSearch } from '@/object-record/record-field/ui/meta-types/input/hooks/useMultiItemSearch';
import { computeUpdatedMultiItemFieldItems } from '@/object-record/record-field/ui/meta-types/input/utils/computeUpdatedMultiItemFieldItems';
-import { getMultiItemInputKeyDownHandler } from '@/object-record/record-field/ui/meta-types/input/utils/getMultiItemInputKeyDownHandler';
+import { formatPhoneInput } from '@/object-record/record-field/ui/meta-types/input/utils/formatPhoneInput';
+import { getPhoneText } from '@/object-record/record-field/ui/meta-types/input/utils/getPhoneText';
+import { validatePhoneInput } from '@/object-record/record-field/ui/meta-types/input/utils/validatePhoneInput';
import { createPhonesFromFieldValue } from '@/object-record/record-field/ui/meta-types/input/utils/phonesUtils';
import { type MultiItemFieldInputSpacing } from '@/object-record/record-field/ui/meta-types/input/types/MultiItemFieldInputSpacing';
import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';
@@ -19,118 +22,17 @@ import {
type FieldPhonesValue,
type PhoneRecord,
} from '@/object-record/record-field/ui/types/FieldMetadata';
-import { phoneSchema } from '@/object-record/record-field/ui/validation-schemas/phoneSchema';
import { phonesFieldValueSchema } from '@/object-record/record-field/ui/validation-schemas/phonesFieldValueSchema';
-import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';
import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
-import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
-import { parsePhoneNumber, type E164Number } from 'libphonenumber-js';
import { useContext, useRef } from 'react';
-import ReactPhoneNumberInput from 'react-phone-number-input';
-import 'react-phone-number-input/style.css';
import { MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES } from 'twenty-shared/constants';
import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
-import { themeCssVariables } from 'twenty-ui/theme';
import { moveArrayItem } from '~/utils/array/moveArrayItem';
import { toSpliced } from '~/utils/array/toSpliced';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
-const StyledCustomPhoneInputContainer = styled.div<{
- hasItem: boolean;
- hasError?: boolean;
- spacing: MultiItemFieldInputSpacing;
-}>`
- align-self: ${({ spacing }) => (spacing === 'compact' ? 'stretch' : 'auto')};
- background-color: ${({ hasItem }) =>
- hasItem ? themeCssVariables.background.transparent.lighter : 'transparent'};
- border: ${({ hasItem, hasError }) =>
- hasItem
- ? hasError
- ? `1px solid ${themeCssVariables.border.color.danger}`
- : `1px solid ${themeCssVariables.border.color.medium}`
- : 'none'};
- border-radius: ${({ hasItem }) => (hasItem ? '4px' : '0')};
- flex: 1;
- height: ${({ hasItem }) => (hasItem ? '30px' : 'auto')};
- min-width: 0;
-`;
-
-const StyledCustomPhoneInputWrapper = styled.div<{
- spacing: MultiItemFieldInputSpacing;
-}>`
- background-color: transparent;
- border: none;
- color: ${themeCssVariables.font.color.primary};
- font-family: ${themeCssVariables.font.family};
- font-size: inherit;
- font-weight: inherit;
- height: 100%;
- width: 100%;
-
- .PhoneInput {
- height: 100%;
- }
-
- .PhoneInputInput {
- background: none;
- border: none;
- box-sizing: border-box;
- color: ${themeCssVariables.font.color.primary};
- height: 100%;
- padding-left: ${({ spacing }) =>
- spacing === 'compact'
- ? themeCssVariables.spacing[1]
- : themeCssVariables.spacing[2]};
-
- &::placeholder,
- &::-webkit-input-placeholder {
- color: ${themeCssVariables.font.color.light};
- font-family: ${themeCssVariables.font.family};
- font-weight: ${themeCssVariables.font.weight.medium};
- }
-
- &:focus {
- outline: none;
- }
- }
-`;
-
-const EMPTY_PHONE: PhoneRecord = {
- number: '',
- callingCode: '',
- countryCode: '',
-};
-
-const getPhoneText = ({
- callingCode,
- number,
-}: Pick<PhoneRecord, 'callingCode' | 'number'>) => callingCode + number;
-
-const validatePhone = (input: string) => ({
- isValid: phoneSchema.safeParse(input).success,
- errorMessage: '',
-});
-
-const formatPhoneInput = ({ input }: { input: string }): PhoneRecord => {
- if (input === '') {
- return EMPTY_PHONE;
- }
-
- const phone = parsePhoneNumber(input);
-
- if (!isDefined(phone)) {
- return EMPTY_PHONE;
- }
-
- return {
- number: phone.nationalNumber,
- callingCode: `+${phone.countryCallingCode}`,
- countryCode: phone.country ?? '',
- };
-};
-
export const PhonesFieldInput = () => {
const { fieldDefinition, setDraftValue, draftValue } = usePhonesField();
@@ -206,7 +108,7 @@ export const PhonesFieldInput = () => {
getItemText: getPhoneText,
isInputInitiallyOpen: phones.length === 0 || isSingleItemMode,
initialEditedItemIndex: isSingleItemMode && phones.length > 0 ? 0 : null,
- validateInput: validatePhone,
+ validateInput: validatePhoneInput,
onHasErrorChange: (hasError) =>
setRecordFieldInputIsFieldInError(hasError && phones.length === 0),
});
@@ -338,29 +240,19 @@ export const PhonesFieldInput = () => {
) : undefined
}
>
- <StyledCustomPhoneInputContainer
- hasItem={isNonEmptyArray(phones) && inputSpacing === 'default'}
+ <PhonesFieldPhoneInput
+ autoFocus
+ hasBorder={isNonEmptyArray(phones) && inputSpacing === 'default'}
hasError={hasError}
spacing={inputSpacing}
- >
- <StyledCustomPhoneInputWrapper spacing={inputSpacing}>
- <ReactPhoneNumberInput
- autoFocus
- placeholder={t`Phone`}
- value={inputValue as E164Number}
- onChange={(value?: E164Number) => handleInputChange(value ?? '')}
- onKeyDown={getMultiItemInputKeyDownHandler({
- onEnter: handleInputEnter,
- onEscape: handleEscape,
- shouldPreventTabNavigation: true,
- })}
- international={true}
- withCountryCallingCode={true}
- countrySelectComponent={PhoneCountryPickerDropdownButton}
- defaultCountry={defaultCountry}
- />
- </StyledCustomPhoneInputWrapper>
- </StyledCustomPhoneInputContainer>
+ placeholder={t`Phone`}
+ value={inputValue}
+ onChange={handleInputChange}
+ onEnter={handleInputEnter}
+ onEscape={handleEscape}
+ defaultCountry={defaultCountry}
+ shouldPreventTabNavigation
+ />
</MultiItemFieldInputRow>
);
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldPhoneInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldPhoneInput.tsx
new file mode 100644
index 00000000000..58a9c084402
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/PhonesFieldPhoneInput.tsx
@@ -0,0 +1,133 @@
+import { type MultiItemFieldInputSpacing } from '@/object-record/record-field/ui/meta-types/input/types/MultiItemFieldInputSpacing';
+import { getMultiItemInputKeyDownHandler } from '@/object-record/record-field/ui/meta-types/input/utils/getMultiItemInputKeyDownHandler';
+import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';
+import { styled } from '@linaria/react';
+import { type CountryCode, type E164Number } from 'libphonenumber-js';
+import { type Ref } from 'react';
+import ReactPhoneNumberInput from 'react-phone-number-input';
+import 'react-phone-number-input/style.css';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+const StyledPhoneInputContainer = styled.div<{
+ hasBorder: boolean;
+ hasError: boolean;
+ spacing: MultiItemFieldInputSpacing;
+}>`
+ align-self: ${({ spacing }) => (spacing === 'compact' ? 'stretch' : 'auto')};
+ background-color: ${({ hasBorder }) =>
+ hasBorder
+ ? themeCssVariables.background.transparent.lighter
+ : 'transparent'};
+ border: ${({ hasBorder, hasError }) =>
+ hasBorder
+ ? `1px solid ${
+ hasError
+ ? themeCssVariables.border.color.danger
+ : themeCssVariables.border.color.medium
+ }`
+ : 'none'};
+ border-radius: ${({ hasBorder }) =>
+ hasBorder ? themeCssVariables.border.radius.sm : '0'};
+ flex: 1;
+ height: ${({ hasBorder }) => (hasBorder ? '30px' : 'auto')};
+ min-width: 0;
+`;
+
+const StyledPhoneInputWrapper = styled.div<{
+ spacing: MultiItemFieldInputSpacing;
+}>`
+ background-color: transparent;
+ border: none;
+ color: ${themeCssVariables.font.color.primary};
+ font-family: ${themeCssVariables.font.family};
+ font-size: inherit;
+ font-weight: inherit;
+ height: 100%;
+ width: 100%;
+
+ .PhoneInput {
+ height: 100%;
+ }
+
+ .PhoneInputInput {
+ background: none;
+ border: none;
+ box-sizing: border-box;
+ color: ${themeCssVariables.font.color.primary};
+ height: 100%;
+ padding-left: ${({ spacing }) =>
+ spacing === 'compact'
+ ? themeCssVariables.spacing[1]
+ : themeCssVariables.spacing[2]};
+
+ &::placeholder,
+ &::-webkit-input-placeholder {
+ color: ${themeCssVariables.font.color.light};
+ font-family: ${themeCssVariables.font.family};
+ font-weight: ${themeCssVariables.font.weight.medium};
+ }
+
+ &:focus {
+ outline: none;
+ }
+ }
+`;
+
+type PhonesFieldPhoneInputProps = {
+ value: string;
+ onChange: (value: string) => void;
+ placeholder?: string;
+ defaultCountry?: CountryCode;
+ autoFocus?: boolean;
+ hasBorder?: boolean;
+ hasError?: boolean;
+ spacing?: MultiItemFieldInputSpacing;
+ onEnter?: () => void;
+ onEscape?: () => void;
+ onBlur?: () => void;
+ shouldPreventTabNavigation?: boolean;
+ ref?: Ref<HTMLInputElement>;
+};
+
+export const PhonesFieldPhoneInput = ({
+ value,
+ onChange,
+ placeholder,
+ defaultCountry,
+ autoFocus,
+ hasBorder = false,
+ hasError = false,
+ spacing = 'default',
+ onEnter,
+ onEscape,
+ onBlur,
+ shouldPreventTabNavigation,
+ ref,
+}: PhonesFieldPhoneInputProps) => (
+ <StyledPhoneInputContainer
+ hasBorder={hasBorder}
+ hasError={hasError}
+ spacing={spacing}
+ >
+ <StyledPhoneInputWrapper spacing={spacing}>
+ <ReactPhoneNumberInput
+ // Typed as the class component, but the library forwards it to the <input>
+ ref={ref as unknown as Ref<InstanceType<typeof ReactPhoneNumberInput>>}
+ autoFocus={autoFocus}
+ placeholder={placeholder}
+ value={value as E164Number}
+ onChange={(newValue?: E164Number) => onChange(newValue ?? '')}
+ onBlur={onBlur}
+ onKeyDown={getMultiItemInputKeyDownHandler({
+ onEnter,
+ onEscape,
+ shouldPreventTabNavigation,
+ })}
+ international={true}
+ withCountryCallingCode={true}
+ countrySelectComponent={PhoneCountryPickerDropdownButton}
+ defaultCountry={defaultCountry}
+ />
+ </StyledPhoneInputWrapper>
+ </StyledPhoneInputContainer>
+);
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/formatPhoneInput.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/formatPhoneInput.ts
new file mode 100644
index 00000000000..1f7b510db2c
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/formatPhoneInput.ts
@@ -0,0 +1,27 @@
+import { type PhoneRecord } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { parsePhoneNumber } from 'libphonenumber-js';
+import { isDefined } from 'twenty-shared/utils';
+
+const EMPTY_PHONE: PhoneRecord = {
+ number: '',
+ callingCode: '',
+ countryCode: '',
+};
+
+export const formatPhoneInput = ({ input }: { input: string }): PhoneRecord => {
+ if (input === '') {
+ return EMPTY_PHONE;
+ }
+
+ const phone = parsePhoneNumber(input);
+
+ if (!isDefined(phone)) {
+ return EMPTY_PHONE;
+ }
+
+ return {
+ number: phone.nationalNumber,
+ callingCode: `+${phone.countryCallingCode}`,
+ countryCode: phone.country ?? '',
+ };
+};
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 a6f9ea236f0..b2b1c74c230 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
@@ -2,7 +2,9 @@ import { type FieldLinksValue } from '@/object-record/record-field/ui/types/Fiel
import { isNonEmptyString } from '@sniptt/guards';
import { isDefined, isValidUrl } from 'twenty-shared/utils';
-export const getFieldLinkDefinedLinks = (fieldValue: FieldLinksValue) => {
+export const getFieldLinkDefinedLinks = (
+ fieldValue: FieldLinksValue | null | undefined,
+) => {
if (!isDefined(fieldValue)) {
return [];
}
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getPhoneText.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getPhoneText.ts
new file mode 100644
index 00000000000..3859f2952e6
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getPhoneText.ts
@@ -0,0 +1,6 @@
+import { type PhoneRecord } from '@/object-record/record-field/ui/types/FieldMetadata';
+
+export const getPhoneText = ({
+ callingCode,
+ number,
+}: Pick<PhoneRecord, 'callingCode' | 'number'>) => callingCode + number;
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 0233a49058b..7713f7a6d89 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
@@ -6,7 +6,7 @@ import { isNonEmptyString } from '@sniptt/guards';
import { isDefined } from 'twenty-shared/utils';
export const createPhonesFromFieldValue = (
- fieldValue: FieldPhonesValue,
+ fieldValue: FieldPhonesValue | null | undefined,
): PhoneRecord[] => {
if (!isDefined(fieldValue)) {
return [];
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/validateLinkInput.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/validateLinkInput.ts
new file mode 100644
index 00000000000..9825b70c572
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/validateLinkInput.ts
@@ -0,0 +1,14 @@
+import { absoluteUrlSchema, isValidDomain } from 'twenty-shared/utils';
+
+export const validateLinkInput = ({
+ input,
+ isDomainField,
+}: {
+ input: string;
+ isDomainField: boolean;
+}) => ({
+ isValid: isDomainField
+ ? isValidDomain(input)
+ : absoluteUrlSchema.safeParse(input).success,
+ errorMessage: '',
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/validatePhoneInput.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/validatePhoneInput.ts
new file mode 100644
index 00000000000..32982d5b58d
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/validatePhoneInput.ts
@@ -0,0 +1,6 @@
+import { phoneSchema } from '@/object-record/record-field/ui/validation-schemas/phoneSchema';
+
+export const validatePhoneInput = (input: string) => ({
+ isValid: phoneSchema.safeParse(input).success,
+ errorMessage: '',
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormEmailsFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormEmailsFieldInput.tsx
index b082deeb11f..5482133e75f 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormEmailsFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormEmailsFieldInput.tsx
@@ -242,6 +242,7 @@ export const RecordFormEmailsFieldInput = ({
openNextInput(updatedEmails);
};
+ const isInputValueInvalid = hasError || isInvalidInputLeft;
const shouldShowItems = !isSingleItemMode && isNonEmptyArray(savedEmails);
const visibleEmails = shouldShowItems ? savedEmails : undefined;
const shouldShowInputInFooter = isInputOpen && !isEditingItemInPlace;
@@ -268,7 +269,6 @@ export const RecordFormEmailsFieldInput = ({
spacing={inputSpacing}
placeholder={placeholder ?? t`Email`}
value={inputValue}
- hasError={hasError || isInvalidInputLeft}
onBlur={() => setIsInvalidInputLeft(!isInputValueValid(inputValue))}
onChange={handleTyping}
onEnter={handleEnter}
@@ -281,6 +281,7 @@ export const RecordFormEmailsFieldInput = ({
<FormFieldInputContainer>
{isNonEmptyString(label) ? <Field.Label>{label}</Field.Label> : null}
<RecordFormMultiItemList
+ hasError={isInputValueInvalid}
footer={shouldShowInputInFooter ? itemInput : undefined}
>
{visibleEmails?.map((email, index) =>
@@ -325,7 +326,7 @@ export const RecordFormEmailsFieldInput = ({
),
)}
</RecordFormMultiItemList>
- {hasError || isInvalidInputLeft ? (
+ {isInputValueInvalid ? (
<Field.Error match role="alert">
{t`Enter a valid email`}
</Field.Error>
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx
index bb003be8b69..a455f2dc9da 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx
@@ -1,6 +1,5 @@
import { FormFieldInput } from '@/object-record/record-field/ui/components/FormFieldInput';
import { FormEmailsFieldInput } from '@/object-record/record-field/ui/form-types/components/FormEmailsFieldInput';
-import { FormLinksFieldInput } from '@/object-record/record-field/ui/form-types/components/FormLinksFieldInput';
import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';
import { type FormFieldInputSubFieldPlaceholders } from '@/object-record/record-field/ui/form-types/types/FormFieldInputSubFieldPlaceholders';
import { type FieldDefinition } from '@/object-record/record-field/ui/types/FieldDefinition';
@@ -13,6 +12,10 @@ import { isFieldCurrency } from '@/object-record/record-field/ui/types/guards/is
import { isFieldCurrencyValue } from '@/object-record/record-field/ui/types/guards/isFieldCurrencyValue';
import { isFieldEmails } from '@/object-record/record-field/ui/types/guards/isFieldEmails';
import { isFieldEmailsValue } from '@/object-record/record-field/ui/types/guards/isFieldEmailsValue';
+import { isFieldFiles } from '@/object-record/record-field/ui/types/guards/isFieldFiles';
+import { isFieldFilesValue } from '@/object-record/record-field/ui/types/guards/isFieldFilesValue';
+import { isFieldFullName } from '@/object-record/record-field/ui/types/guards/isFieldFullName';
+import { isFieldFullNameValue } from '@/object-record/record-field/ui/types/guards/isFieldFullNameValue';
import { isFieldLinks } from '@/object-record/record-field/ui/types/guards/isFieldLinks';
import { isFieldLinksValue } from '@/object-record/record-field/ui/types/guards/isFieldLinksValue';
import { isFieldNumber } from '@/object-record/record-field/ui/types/guards/isFieldNumber';
@@ -24,17 +27,23 @@ import { RecordFormBooleanFieldInput } from '@/object-record/record-form/compone
import { RecordFormCurrencyFieldInput } from '@/object-record/record-form/components/RecordFormCurrencyFieldInput';
import { RecordFormEmailsFieldInput } from '@/object-record/record-form/components/RecordFormEmailsFieldInput';
import { RecordFormPercentageFieldInput } from '@/object-record/record-form/components/RecordFormPercentageFieldInput';
-import { RecordFormPhoneFieldInput } from '@/object-record/record-form/components/RecordFormPhoneFieldInput';
+import { RecordFormFilesFieldInput } from '@/object-record/record-form/components/RecordFormFilesFieldInput';
+import { RecordFormFullNameFieldInput } from '@/object-record/record-form/components/RecordFormFullNameFieldInput';
+import { RecordFormLinksFieldInput } from '@/object-record/record-form/components/RecordFormLinksFieldInput';
+import { RecordFormPhonesFieldInput } from '@/object-record/record-form/components/RecordFormPhonesFieldInput';
import { getRecordFormCurrencyFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormCurrencyFieldDefaultValue';
+import { getLinksVariant } from '@/object-record/spreadsheet-import/utils/getLinksVariant';
import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
import { isNonEmptyString } from '@sniptt/guards';
+import { isValidCountryCode } from 'twenty-shared/utils';
import { type JsonValue } from 'type-fest';
+import { FieldMetadataType } from '~/generated-metadata/graphql';
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
type RecordFormFieldInputProps = {
field: Pick<
FieldDefinition<FieldMetadata>,
- 'label' | 'metadata' | 'type' | 'defaultValue'
+ 'fieldMetadataId' | 'label' | 'metadata' | 'type' | 'defaultValue'
>;
defaultValue: JsonValue;
onChange: (value: JsonValue) => void;
@@ -57,17 +66,73 @@ export const RecordFormFieldInput = ({
recordFieldInputIsFieldInErrorComponentState,
);
- if (isFieldLinks(field)) {
+ if (isFieldLinks(field) && !readonly) {
return (
- <FormLinksFieldInput
+ <RecordFormLinksFieldInput
label={field.label}
defaultValue={
isFieldLinksValue(defaultValue) ? defaultValue : undefined
}
+ isDomainField={
+ getLinksVariant({
+ type: FieldMetadataType.LINKS,
+ settings: field.metadata.settings,
+ }) === 'domain'
+ }
+ maxNumberOfValues={field.metadata.settings?.maxNumberOfValues}
+ placeholder={subFieldPlaceholders?.primaryLinkUrl}
+ onChange={onChange}
+ />
+ );
+ }
+
+ if (isFieldPhones(field) && !readonly) {
+ const defaultCountryCode = stripSimpleQuotesFromString(
+ field.defaultValue?.primaryPhoneCountryCode ?? '',
+ );
+
+ return (
+ <RecordFormPhonesFieldInput
+ label={field.label}
+ defaultValue={
+ isFieldPhonesValue(defaultValue) ? defaultValue : undefined
+ }
+ defaultCountry={
+ isValidCountryCode(defaultCountryCode)
+ ? defaultCountryCode
+ : undefined
+ }
+ maxNumberOfValues={field.metadata.settings?.maxNumberOfValues}
+ placeholder={subFieldPlaceholders?.primaryPhoneNumber}
+ onChange={onChange}
+ />
+ );
+ }
+
+ if (isFieldFiles(field) && !readonly) {
+ return (
+ <RecordFormFilesFieldInput
+ label={field.label}
+ defaultValue={
+ isFieldFilesValue(defaultValue) ? defaultValue : undefined
+ }
+ fieldMetadataId={field.fieldMetadataId}
+ maxNumberOfValues={field.metadata.settings?.maxNumberOfValues}
+ onChange={onChange}
+ />
+ );
+ }
+
+ if (isFieldFullName(field) && !readonly) {
+ return (
+ <RecordFormFullNameFieldInput
+ label={field.label}
+ defaultValue={
+ isFieldFullNameValue(defaultValue) ? defaultValue : undefined
+ }
+ firstNamePlaceholder={subFieldPlaceholders?.firstName}
+ lastNamePlaceholder={subFieldPlaceholders?.lastName}
onChange={onChange}
- readonly={readonly}
- subFieldPlaceholders={subFieldPlaceholders}
- isPrimaryLinkUrlOnly
/>
);
}
@@ -157,27 +222,6 @@ export const RecordFormFieldInput = ({
);
}
- if (isFieldPhones(field)) {
- const defaultCountryCode = field.defaultValue?.primaryPhoneCountryCode;
-
- return (
- <RecordFormPhoneFieldInput
- label={field.label}
- defaultValue={
- isFieldPhonesValue(defaultValue) ? defaultValue : undefined
- }
- defaultCountryCode={
- isNonEmptyString(defaultCountryCode)
- ? stripSimpleQuotesFromString(defaultCountryCode)
- : undefined
- }
- onChange={onChange}
- readonly={readonly}
- placeholder={subFieldPlaceholders?.primaryPhoneNumber}
- />
- );
- }
-
return (
<FormFieldInput
field={field}
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFilesFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFilesFieldInput.tsx
new file mode 100644
index 00000000000..b119daae4b6
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFilesFieldInput.tsx
@@ -0,0 +1,202 @@
+import { useFileUpload } from '@/file-upload/hooks/useFileUpload';
+import { useUploadFilesFieldFile } from '@/object-record/record-field/ui/meta-types/hooks/useUploadFilesFieldFile';
+import { FilesFieldLabelInput } from '@/object-record/record-field/ui/meta-types/input/components/FilesFieldLabelInput';
+import { FilesFieldMenuItem } from '@/object-record/record-field/ui/meta-types/input/components/FilesFieldMenuItem';
+import { MultiItemFieldAddButton } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldAddButton';
+import { MultiItemFieldEditedItem } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldEditedItem';
+import { MultiItemFieldInputRow } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldInputRow';
+import { MultiItemFieldSaveButton } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldSaveButton';
+import { useMultiItemInput } from '@/object-record/record-field/ui/meta-types/input/hooks/useMultiItemInput';
+import { uploadMultipleFiles } from '@/object-record/record-field/ui/meta-types/utils/uploadMultipleFiles';
+import { type FieldFilesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { RecordFormMultiItemList } from '@/object-record/record-form/components/RecordFormMultiItemList';
+import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { useId, useState } from 'react';
+import { MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES } from 'twenty-shared/constants';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+import { useToast } from 'twenty-ui/components/feedback';
+import { Field } from 'twenty-ui/primitives/input';
+import { toSpliced } from '~/utils/array/toSpliced';
+
+const getFileText = (file: FieldFilesValue) => file.label;
+
+type RecordFormFilesFieldInputProps = {
+ label?: string;
+ defaultValue?: FieldFilesValue[];
+ fieldMetadataId: string;
+ maxNumberOfValues?: number | null;
+ onChange: (value: FieldFilesValue[]) => void;
+};
+
+export const RecordFormFilesFieldInput = ({
+ label,
+ defaultValue,
+ fieldMetadataId,
+ maxNumberOfValues,
+ onChange,
+}: RecordFormFilesFieldInputProps) => {
+ const { t } = useLingui();
+ const instanceId = useId();
+ const { uploadFile } = useUploadFilesFieldFile();
+ const { openFileUpload } = useFileUpload();
+ const { enqueueToast } = useToast();
+
+ const maxItemCount = maxNumberOfValues ?? MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES;
+
+ const [savedFiles, setSavedFiles] = useState(defaultValue ?? []);
+ const [isUploading, setIsUploading] = useState(false);
+
+ const {
+ editedItemIndex,
+ inputValue,
+ startEditingItem,
+ closeInput,
+ handleInputChange,
+ } = useMultiItemInput({
+ items: savedFiles,
+ getItemText: getFileText,
+ isInputInitiallyOpen: false,
+ });
+
+ const getFilesWithLabel = (fileLabel: string) => {
+ const trimmedFileLabel = fileLabel.trim();
+
+ if (!isDefined(editedItemIndex) || !isNonEmptyString(trimmedFileLabel)) {
+ return savedFiles;
+ }
+
+ return toSpliced(savedFiles, editedItemIndex, 1, {
+ ...savedFiles[editedItemIndex],
+ label: trimmedFileLabel,
+ });
+ };
+
+ const saveFiles = (files: FieldFilesValue[]) => {
+ setSavedFiles(files);
+ onChange(files);
+ };
+
+ const handleTyping = (value: string) => {
+ handleInputChange(value);
+ onChange(getFilesWithLabel(value));
+ };
+
+ const saveInputValue = () => {
+ const updatedFiles = getFilesWithLabel(inputValue);
+
+ saveFiles(updatedFiles);
+ closeInput();
+
+ return updatedFiles;
+ };
+
+ const handleEscape = () => {
+ saveFiles(savedFiles);
+ closeInput();
+ };
+
+ const handleEdit = (index: number) => {
+ const updatedFiles = saveInputValue();
+
+ startEditingItem({ itemIndex: index, currentItems: updatedFiles });
+ };
+
+ const handleDelete = (index: number) => {
+ const updatedFiles = saveInputValue();
+
+ saveFiles(toSpliced(updatedFiles, index, 1));
+ };
+
+ const handleUploadClick = () => {
+ const currentFiles = saveInputValue();
+
+ if (isUploading) {
+ return;
+ }
+
+ openFileUpload({
+ multiple: true,
+ onUpload: async (selectedFiles: File[]) => {
+ if (selectedFiles.length > maxItemCount - currentFiles.length) {
+ enqueueToast({
+ status: 'error',
+ children: t`Cannot upload more than ${maxItemCount} files`,
+ });
+ return;
+ }
+
+ setIsUploading(true);
+
+ try {
+ const uploadedFiles = await uploadMultipleFiles(
+ selectedFiles,
+ fieldMetadataId,
+ uploadFile,
+ );
+
+ if (isNonEmptyArray(uploadedFiles)) {
+ saveFiles([...currentFiles, ...uploadedFiles]);
+ }
+ } finally {
+ setIsUploading(false);
+ }
+ },
+ });
+ };
+
+ const visibleFiles = isNonEmptyArray(savedFiles) ? savedFiles : undefined;
+
+ return (
+ <FormFieldInputContainer>
+ {isNonEmptyString(label) ? <Field.Label>{label}</Field.Label> : null}
+ <RecordFormMultiItemList
+ footer={
+ savedFiles.length < maxItemCount ? (
+ <MultiItemFieldAddButton
+ label={isUploading ? t`Uploading...` : t`Upload file`}
+ onClick={handleUploadClick}
+ />
+ ) : undefined
+ }
+ >
+ {visibleFiles?.map((file, index) =>
+ index === editedItemIndex ? (
+ <MultiItemFieldEditedItem
+ key={file.fileId}
+ hasSeparatorBefore={index > 0}
+ hasSeparatorAfter={index < savedFiles.length - 1}
+ >
+ <MultiItemFieldInputRow
+ spacing="compact"
+ rightComponent={
+ <MultiItemFieldSaveButton
+ isAddingNewItem={false}
+ onClick={saveInputValue}
+ />
+ }
+ >
+ <FilesFieldLabelInput
+ file={file}
+ value={inputValue}
+ onChange={handleTyping}
+ onEnter={saveInputValue}
+ onEscape={handleEscape}
+ />
+ </MultiItemFieldInputRow>
+ </MultiItemFieldEditedItem>
+ ) : (
+ <FilesFieldMenuItem
+ key={file.fileId}
+ dropdownId={`${instanceId}-file-${index}`}
+ file={file}
+ onEdit={isUploading ? undefined : () => handleEdit(index)}
+ onDelete={isUploading ? undefined : () => handleDelete(index)}
+ />
+ ),
+ )}
+ </RecordFormMultiItemList>
+ </FormFieldInputContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFullNameFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFullNameFieldInput.tsx
new file mode 100644
index 00000000000..70e1fc1251c
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFullNameFieldInput.tsx
@@ -0,0 +1,142 @@
+import { addCharactersToAvoidPasswordManagers } from '@/object-record/record-field/ui/meta-types/input/utils/addCharactersToAvoidPasswordManagers';
+import { type FieldFullNameValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { StyledRecordFormFieldBox } from '@/object-record/record-form/components/StyledRecordFormFieldBox';
+import { splitFullNameInputText } from '@/object-record/record-form/utils/splitFullNameInputText';
+import { StyledTextInput } from '@/ui/field/input/components/TextInput';
+import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';
+import { TextInput } from '@/ui/input/components/TextInput';
+import { PASSWORD_MANAGER_IGNORE_ATTRIBUTES } from '@/ui/input/constants/PasswordManagerIgnoreAttributes';
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { useId, useState } from 'react';
+import { LightIconButton } from 'twenty-ui/components/input';
+import { IconListDetails } from 'twenty-ui/icon';
+import { Field } from 'twenty-ui/primitives/input';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+const StyledFullNameRow = styled.div`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[1]};
+ height: ${themeCssVariables.spacing[8]};
+ padding-right: ${themeCssVariables.spacing[1]};
+`;
+
+const StyledNameDetails = styled.div`
+ border-top: 1px solid ${themeCssVariables.border.color.light};
+ display: grid;
+ gap: ${themeCssVariables.spacing[2]};
+ grid-template-columns: 1fr 1fr;
+ padding: ${themeCssVariables.spacing[2]};
+`;
+
+const joinFullName = ({ firstName, lastName }: FieldFullNameValue) =>
+ `${firstName} ${lastName}`.trim();
+
+const trimFullName = ({
+ firstName,
+ lastName,
+}: FieldFullNameValue): FieldFullNameValue => ({
+ firstName: firstName.trim(),
+ lastName: lastName.trim(),
+});
+
+type RecordFormFullNameFieldInputProps = {
+ label?: string;
+ defaultValue?: FieldFullNameValue;
+ firstNamePlaceholder?: string;
+ lastNamePlaceholder?: string;
+ onChange: (value: FieldFullNameValue) => void;
+};
+
+export const RecordFormFullNameFieldInput = ({
+ label,
+ defaultValue,
+ firstNamePlaceholder,
+ lastNamePlaceholder,
+ onChange,
+}: RecordFormFullNameFieldInputProps) => {
+ const { t } = useLingui();
+ const instanceId = useId();
+
+ const [fullName, setFullName] = useState<FieldFullNameValue>(
+ defaultValue ?? { firstName: '', lastName: '' },
+ );
+ const [fullNameText, setFullNameText] = useState(() =>
+ joinFullName(fullName),
+ );
+ const [isExpanded, setIsExpanded] = useState(false);
+
+ const firstNameText = firstNamePlaceholder ?? t`First name`;
+ const lastNameText = lastNamePlaceholder ?? t`Last name`;
+
+ const updateFullName = (nextFullName: FieldFullNameValue) => {
+ setFullName(nextFullName);
+ onChange(trimFullName(nextFullName));
+ };
+
+ const handleFullNameTextChange = (text: string) => {
+ setFullNameText(text);
+ updateFullName(splitFullNameInputText({ text, currentFullName: fullName }));
+ };
+
+ const handleNamePartChange = (nextFullName: FieldFullNameValue) => {
+ setFullNameText(joinFullName(nextFullName));
+ updateFullName(nextFullName);
+ };
+
+ return (
+ <FormFieldInputContainer>
+ {isNonEmptyString(label) ? (
+ <Field.Label htmlFor={instanceId}>{label}</Field.Label>
+ ) : null}
+ <StyledRecordFormFieldBox>
+ <StyledFullNameRow>
+ <StyledTextInput
+ id={instanceId}
+ autoComplete="off"
+ // oxlint-disable-next-line react/jsx-props-no-spreading
+ {...PASSWORD_MANAGER_IGNORE_ATTRIBUTES}
+ placeholder={addCharactersToAvoidPasswordManagers(
+ `${firstNameText} ${lastNameText}`,
+ )}
+ value={fullNameText}
+ onChange={(event) => handleFullNameTextChange(event.target.value)}
+ />
+ <LightIconButton
+ aria-label={t`Name details`}
+ aria-expanded={isExpanded}
+ onClick={() => setIsExpanded(!isExpanded)}
+ >
+ <IconListDetails />
+ </LightIconButton>
+ </StyledFullNameRow>
+ {isExpanded && (
+ <StyledNameDetails>
+ <TextInput
+ label={t`First name`}
+ value={fullName.firstName}
+ placeholder={addCharactersToAvoidPasswordManagers(firstNameText)}
+ fullWidth
+ ignorePasswordManagers
+ onChange={(firstName) =>
+ handleNamePartChange({ ...fullName, firstName })
+ }
+ />
+ <TextInput
+ label={t`Last name`}
+ value={fullName.lastName}
+ placeholder={addCharactersToAvoidPasswordManagers(lastNameText)}
+ fullWidth
+ ignorePasswordManagers
+ onChange={(lastName) =>
+ handleNamePartChange({ ...fullName, lastName })
+ }
+ />
+ </StyledNameDetails>
+ )}
+ </StyledRecordFormFieldBox>
+ </FormFieldInputContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormLinksFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormLinksFieldInput.tsx
new file mode 100644
index 00000000000..c6162c2ce89
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormLinksFieldInput.tsx
@@ -0,0 +1,407 @@
+import { LinksFieldEditInputs } from '@/object-record/record-field/ui/meta-types/input/components/LinksFieldEditInputs';
+import { LinksFieldEditPreview } from '@/object-record/record-field/ui/meta-types/input/components/LinksFieldEditPreview';
+import { LinksFieldMenuItem } from '@/object-record/record-field/ui/meta-types/input/components/LinksFieldMenuItem';
+import { MultiItemFieldEditedItem } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldEditedItem';
+import { MultiItemFieldInputRow } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldInputRow';
+import { MultiItemFieldItemSeparator } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldItemSeparator';
+import { MultiItemFieldSaveButton } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldSaveButton';
+import { MultiItemFieldTextInput } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldTextInput';
+import { useMultiItemInput } from '@/object-record/record-field/ui/meta-types/input/hooks/useMultiItemInput';
+import { type LinkRecord } from '@/object-record/record-field/ui/meta-types/input/types/LinkRecord';
+import { type MultiItemFieldInputSpacing } from '@/object-record/record-field/ui/meta-types/input/types/MultiItemFieldInputSpacing';
+import { computeUpdatedMultiItemFieldItems } from '@/object-record/record-field/ui/meta-types/input/utils/computeUpdatedMultiItemFieldItems';
+import { getFieldLinkDefinedLinks } from '@/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks';
+import { validateLinkInput } from '@/object-record/record-field/ui/meta-types/input/utils/validateLinkInput';
+import { getLinkLabelFromDraft } from '@/object-record/record-field/ui/meta-types/input/utils/getLinkLabelFromDraft';
+import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';
+import { type FieldLinksValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { RecordFormMultiItemList } from '@/object-record/record-form/components/RecordFormMultiItemList';
+import { getRecordFormItemIndexAfterSave } from '@/object-record/record-form/utils/getRecordFormItemIndexAfterSave';
+import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';
+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { useId, useRef, useState } from 'react';
+import { MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES } from 'twenty-shared/constants';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+import { Field } from 'twenty-ui/primitives/input';
+import { moveArrayItem } from '~/utils/array/moveArrayItem';
+import { toSpliced } from '~/utils/array/toSpliced';
+
+const getLinkText = (link: LinkRecord) => link.url;
+
+const getLinksValue = (links: LinkRecord[]): FieldLinksValue => {
+ const [primaryLink, ...secondaryLinks] = links;
+
+ return {
+ primaryLinkUrl: primaryLink?.url ?? null,
+ primaryLinkLabel: primaryLink?.label ?? null,
+ secondaryLinks,
+ };
+};
+
+type RecordFormLinksFieldInputProps = {
+ label?: string;
+ defaultValue?: FieldLinksValue;
+ isDomainField: boolean;
+ maxNumberOfValues?: number | null;
+ placeholder?: string;
+ onChange: (value: FieldLinksValue) => void;
+};
+
+export const RecordFormLinksFieldInput = ({
+ label,
+ defaultValue,
+ isDomainField,
+ maxNumberOfValues,
+ placeholder,
+ onChange,
+}: RecordFormLinksFieldInputProps) => {
+ const { t } = useLingui();
+ const instanceId = useId();
+
+ const setRecordFieldInputIsFieldInError = useSetAtomComponentState(
+ recordFieldInputIsFieldInErrorComponentState,
+ );
+
+ const maxItemCount = maxNumberOfValues ?? MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES;
+ const isSingleItemMode = maxItemCount === 1;
+
+ const validateLink = (input: string) =>
+ validateLinkInput({ input, isDomainField });
+
+ const [savedLinks, setSavedLinks] = useState(() =>
+ getFieldLinkDefinedLinks(defaultValue),
+ );
+ const [labelDraft, setLabelDraft] = useState('');
+ const [shouldFocusInput, setShouldFocusInput] = useState(false);
+ const inputRef = useRef<HTMLInputElement>(null);
+ const [isInvalidInputLeft, setIsInvalidInputLeft] = useState(false);
+
+ const {
+ isInputOpen,
+ editedItemIndex,
+ inputValue,
+ hasError,
+ startAddingItem,
+ startEditingItem,
+ closeInput,
+ handleInputChange,
+ validateInputValue,
+ } = useMultiItemInput({
+ items: savedLinks,
+ getItemText: getLinkText,
+ isInputInitiallyOpen: isSingleItemMode || savedLinks.length < maxItemCount,
+ initialEditedItemIndex:
+ isSingleItemMode && savedLinks.length > 0 ? 0 : null,
+ validateInput: validateLink,
+ });
+
+ const openNextInput = (links: LinkRecord[]) => {
+ if (isSingleItemMode && isNonEmptyArray(links)) {
+ startEditingItem({ itemIndex: 0, currentItems: links });
+ return;
+ }
+
+ if (links.length < maxItemCount) {
+ startAddingItem();
+ return;
+ }
+
+ closeInput();
+ };
+
+ const isEditingItemInPlace = isDefined(editedItemIndex) && !isSingleItemMode;
+ const shouldEditLabel = isEditingItemInPlace && !isDomainField;
+
+ const getLinkLabel = ({
+ itemIndex,
+ labelInput,
+ }: {
+ itemIndex?: number;
+ labelInput: string;
+ }) => {
+ if (shouldEditLabel) {
+ return getLinkLabelFromDraft(labelInput);
+ }
+
+ return isDefined(itemIndex) ? (savedLinks[itemIndex]?.label ?? null) : null;
+ };
+
+ const getLinksWithInput = ({
+ sanitizedInput,
+ labelInput,
+ }: {
+ sanitizedInput: string;
+ labelInput: string;
+ }) =>
+ computeUpdatedMultiItemFieldItems({
+ sanitizedInput,
+ items: savedLinks,
+ editingIndex: isSingleItemMode ? 0 : editedItemIndex,
+ singleItemMode: isSingleItemMode,
+ formatInput: ({ input, itemIndex }): LinkRecord => ({
+ url: input,
+ label: getLinkLabel({ itemIndex, labelInput }),
+ }),
+ });
+
+ const saveLinks = (links: LinkRecord[]) => {
+ setSavedLinks(links);
+ setIsInvalidInputLeft(false);
+ setRecordFieldInputIsFieldInError(false);
+ onChange(getLinksValue(links));
+ };
+
+ const isInputValueValid = (value: string) => {
+ const sanitizedInput = value.trim();
+
+ return (
+ !isNonEmptyString(sanitizedInput) || validateLink(sanitizedInput).isValid
+ );
+ };
+
+ const sendLinksWithInput = ({
+ urlInput,
+ labelInput,
+ }: {
+ urlInput: string;
+ labelInput: string;
+ }) => {
+ const isValid = isInputValueValid(urlInput);
+
+ setRecordFieldInputIsFieldInError(!isValid);
+ onChange(
+ getLinksValue(
+ isValid
+ ? getLinksWithInput({ sanitizedInput: urlInput.trim(), labelInput })
+ : savedLinks,
+ ),
+ );
+ };
+
+ const handleTyping = (value: string) => {
+ handleInputChange(value);
+ setIsInvalidInputLeft(false);
+ sendLinksWithInput({ urlInput: value, labelInput: labelDraft });
+ };
+
+ const handleLabelTyping = (value: string) => {
+ setLabelDraft(value);
+ sendLinksWithInput({ urlInput: inputValue, labelInput: value });
+ };
+
+ const saveInputValue = () => {
+ const sanitizedInput = validateInputValue();
+
+ if (!isDefined(sanitizedInput)) {
+ return null;
+ }
+
+ const updatedLinks = getLinksWithInput({
+ sanitizedInput,
+ labelInput: labelDraft,
+ });
+
+ saveLinks(updatedLinks);
+
+ return updatedLinks;
+ };
+
+ const handleEnter = () => {
+ const updatedLinks = saveInputValue();
+
+ if (!isDefined(updatedLinks) || isSingleItemMode) {
+ return;
+ }
+
+ setShouldFocusInput(true);
+ openNextInput(updatedLinks);
+ inputRef.current?.focus();
+ };
+
+ const handleEscape = () => {
+ saveLinks(savedLinks);
+ openNextInput(savedLinks);
+ };
+
+ const saveInputValueBeforeRowAction = (itemIndex: number) => {
+ const updatedLinks = saveInputValue();
+
+ if (!isDefined(updatedLinks)) {
+ return null;
+ }
+
+ const hasRemovedEditedItem = updatedLinks.length < savedLinks.length;
+
+ return {
+ updatedLinks,
+ itemIndexAfterSave: getRecordFormItemIndexAfterSave({
+ itemIndex,
+ removedItemIndex: hasRemovedEditedItem ? editedItemIndex : null,
+ }),
+ };
+ };
+
+ const handleEdit = (index: number) => {
+ const saveResult = saveInputValueBeforeRowAction(index);
+
+ if (!isDefined(saveResult)) {
+ return;
+ }
+
+ setShouldFocusInput(true);
+ if (isDefined(saveResult.itemIndexAfterSave)) {
+ setLabelDraft(
+ saveResult.updatedLinks[saveResult.itemIndexAfterSave]?.label ?? '',
+ );
+ startEditingItem({
+ itemIndex: saveResult.itemIndexAfterSave,
+ currentItems: saveResult.updatedLinks,
+ });
+ return;
+ }
+
+ openNextInput(saveResult.updatedLinks);
+ };
+
+ const updateLinks = ({
+ itemIndex,
+ getUpdatedLinks,
+ }: {
+ itemIndex: number;
+ getUpdatedLinks: (params: {
+ links: LinkRecord[];
+ itemIndex: number;
+ }) => LinkRecord[];
+ }) => {
+ const saveResult = saveInputValueBeforeRowAction(itemIndex);
+
+ if (!isDefined(saveResult)) {
+ return;
+ }
+
+ const updatedLinks = isDefined(saveResult.itemIndexAfterSave)
+ ? getUpdatedLinks({
+ links: saveResult.updatedLinks,
+ itemIndex: saveResult.itemIndexAfterSave,
+ })
+ : saveResult.updatedLinks;
+
+ saveLinks(updatedLinks);
+ openNextInput(updatedLinks);
+ };
+
+ const inputPlaceholder = isDomainField ? t`Domain` : t`URL`;
+ const isInputValueInvalid = hasError || isInvalidInputLeft;
+ const shouldShowItems = !isSingleItemMode && isNonEmptyArray(savedLinks);
+ const visibleLinks = shouldShowItems ? savedLinks : undefined;
+ const shouldShowInputInFooter = isInputOpen && !isEditingItemInPlace;
+ const inputSpacing: MultiItemFieldInputSpacing = shouldShowItems
+ ? 'compact'
+ : 'default';
+
+ const saveButton = isSingleItemMode ? undefined : (
+ <MultiItemFieldSaveButton
+ isAddingNewItem={!isDefined(editedItemIndex)}
+ onClick={handleEnter}
+ />
+ );
+
+ const handleInputBlur = () =>
+ setIsInvalidInputLeft(!isInputValueValid(inputValue));
+
+ const itemInput = (
+ <MultiItemFieldInputRow
+ spacing={inputSpacing}
+ hasPadding={shouldShowItems && shouldShowInputInFooter}
+ rightComponent={saveButton}
+ >
+ <MultiItemFieldTextInput
+ ref={inputRef}
+ autoFocus={shouldFocusInput}
+ spacing={inputSpacing}
+ placeholder={placeholder ?? inputPlaceholder}
+ value={inputValue}
+ onBlur={handleInputBlur}
+ onChange={handleTyping}
+ onEnter={handleEnter}
+ onEscape={handleEscape}
+ />
+ </MultiItemFieldInputRow>
+ );
+
+ const editedLinkInputs = shouldEditLabel ? (
+ <>
+ <LinksFieldEditPreview
+ url={inputValue}
+ label={getLinkLabelFromDraft(labelDraft)}
+ saveButton={saveButton}
+ />
+ <MultiItemFieldItemSeparator />
+ <LinksFieldEditInputs
+ url={inputValue}
+ label={labelDraft}
+ hasError={isInputValueInvalid}
+ onUrlChange={handleTyping}
+ onLabelChange={handleLabelTyping}
+ onEnter={handleEnter}
+ onEscape={handleEscape}
+ onUrlBlur={handleInputBlur}
+ />
+ </>
+ ) : (
+ itemInput
+ );
+
+ return (
+ <FormFieldInputContainer>
+ {isNonEmptyString(label) ? <Field.Label>{label}</Field.Label> : null}
+ <RecordFormMultiItemList
+ hasError={isInputValueInvalid}
+ footer={shouldShowInputInFooter ? itemInput : undefined}
+ >
+ {visibleLinks?.map((link, index) =>
+ index === editedItemIndex && isEditingItemInPlace ? (
+ <MultiItemFieldEditedItem
+ key={index}
+ hasSeparatorBefore={!shouldEditLabel && index > 0}
+ hasSeparatorAfter={index < savedLinks.length - 1}
+ >
+ {editedLinkInputs}
+ </MultiItemFieldEditedItem>
+ ) : (
+ <LinksFieldMenuItem
+ key={index}
+ dropdownId={`${instanceId}-link-${index}`}
+ showPrimaryIcon={index === 0 && savedLinks.length > 1}
+ showSetAsPrimaryButton={index > 0}
+ url={link.url}
+ label={link.label}
+ onEdit={() => handleEdit(index)}
+ onSetAsPrimary={() =>
+ updateLinks({
+ itemIndex: index,
+ getUpdatedLinks: ({ links, itemIndex }) =>
+ moveArrayItem(links, { fromIndex: itemIndex, toIndex: 0 }),
+ })
+ }
+ onDelete={() =>
+ updateLinks({
+ itemIndex: index,
+ getUpdatedLinks: ({ links, itemIndex }) =>
+ toSpliced(links, itemIndex, 1),
+ })
+ }
+ />
+ ),
+ )}
+ </RecordFormMultiItemList>
+ {isInputValueInvalid ? (
+ <Field.Error match role="alert">
+ {isDomainField ? t`Enter a valid domain` : t`Enter a valid URL`}
+ </Field.Error>
+ ) : null}
+ </FormFieldInputContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormMultiItemList.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormMultiItemList.tsx
index 23264292d32..b91a521a2f6 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormMultiItemList.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormMultiItemList.tsx
@@ -1,23 +1,10 @@
+import { StyledRecordFormFieldBox } from '@/object-record/record-form/components/StyledRecordFormFieldBox';
import { OverlayMenuListSeparator } from '@/ui/layout/overlay/components/OverlayMenuListSeparator';
import { styled } from '@linaria/react';
import { type ReactNode } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { themeCssVariables } from 'twenty-ui/theme';
-const StyledContainer = styled.div`
- background-color: ${themeCssVariables.background.transparent.lighter};
- border-radius: ${themeCssVariables.border.radius.md};
- box-shadow: inset 0 0 0 1px ${themeCssVariables.border.color.medium};
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- width: 100%;
-
- &:has(input:focus-visible) {
- box-shadow: inset 0 0 0 1px ${themeCssVariables.color.blue};
- }
-`;
-
const StyledItems = styled.div`
display: flex;
flex-direction: column;
@@ -28,15 +15,17 @@ const StyledItems = styled.div`
type RecordFormMultiItemListProps = {
children?: ReactNode;
footer?: ReactNode;
+ hasError?: boolean;
};
export const RecordFormMultiItemList = ({
children,
footer,
+ hasError = false,
}: RecordFormMultiItemListProps) => (
- <StyledContainer>
+ <StyledRecordFormFieldBox hasError={hasError}>
{isDefined(children) && <StyledItems>{children}</StyledItems>}
{isDefined(children) && isDefined(footer) && <OverlayMenuListSeparator />}
{footer}
- </StyledContainer>
+ </StyledRecordFormFieldBox>
);
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx
deleted file mode 100644
index 64876a25862..00000000000
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { type FieldPhonesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
-import { RecordFormTextInput } from '@/object-record/record-form/components/RecordFormTextInput';
-import { useCountries } from '@/ui/input/components/internal/hooks/useCountries';
-import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';
-import { t } from '@lingui/core/macro';
-import { isNonEmptyString } from '@sniptt/guards';
-import { useState } from 'react';
-import { isDefined } from 'twenty-shared/utils';
-
-type RecordFormPhoneFieldInputProps = {
- label?: string;
- defaultValue?: FieldPhonesValue;
- defaultCountryCode?: string;
- onChange: (value: FieldPhonesValue) => void;
- readonly?: boolean;
- placeholder?: string;
-};
-
-export const RecordFormPhoneFieldInput = ({
- label,
- defaultValue,
- defaultCountryCode,
- onChange,
- readonly,
- placeholder,
-}: RecordFormPhoneFieldInputProps) => {
- const countries = useCountries();
-
- const [countryCode, setCountryCode] = useState(
- isNonEmptyString(defaultValue?.primaryPhoneCountryCode)
- ? defaultValue.primaryPhoneCountryCode
- : defaultCountryCode,
- );
-
- const phoneNumber = defaultValue?.primaryPhoneNumber ?? '';
-
- const emitPhoneValue = (
- newCountryCode: string | undefined,
- newNumber: string,
- ) => {
- const country = isNonEmptyString(newNumber)
- ? countries.find((candidate) => candidate.countryCode === newCountryCode)
- : undefined;
-
- onChange({
- primaryPhoneNumber: newNumber,
- primaryPhoneCountryCode: country?.countryCode ?? '',
- primaryPhoneCallingCode: isDefined(country)
- ? `+${country.callingCode}`
- : '',
- additionalPhones: defaultValue?.additionalPhones ?? null,
- });
- };
-
- const handleCountryCodeChange = (newCountryCode: string | undefined) => {
- setCountryCode(newCountryCode);
- emitPhoneValue(newCountryCode, phoneNumber);
- };
-
- return (
- <RecordFormTextInput
- label={label}
- value={phoneNumber}
- onChange={(newNumber) => emitPhoneValue(countryCode, newNumber)}
- placeholder={placeholder ?? t`Enter phone number`}
- readonly={readonly}
- picker={
- <PhoneCountryPickerDropdownButton
- value={countryCode}
- onChange={handleCountryCodeChange}
- disabled={readonly}
- />
- }
- />
- );
-};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhonesFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhonesFieldInput.tsx
new file mode 100644
index 00000000000..5f7162bd5f7
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhonesFieldInput.tsx
@@ -0,0 +1,329 @@
+import { MultiItemFieldEditedItem } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldEditedItem';
+import { MultiItemFieldInputRow } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldInputRow';
+import { MultiItemFieldSaveButton } from '@/object-record/record-field/ui/meta-types/input/components/MultiItemFieldSaveButton';
+import { PhonesFieldMenuItem } from '@/object-record/record-field/ui/meta-types/input/components/PhonesFieldMenuItem';
+import { PhonesFieldPhoneInput } from '@/object-record/record-field/ui/meta-types/input/components/PhonesFieldPhoneInput';
+import { useMultiItemInput } from '@/object-record/record-field/ui/meta-types/input/hooks/useMultiItemInput';
+import { type MultiItemFieldInputSpacing } from '@/object-record/record-field/ui/meta-types/input/types/MultiItemFieldInputSpacing';
+import { computeUpdatedMultiItemFieldItems } from '@/object-record/record-field/ui/meta-types/input/utils/computeUpdatedMultiItemFieldItems';
+import { formatPhoneInput } from '@/object-record/record-field/ui/meta-types/input/utils/formatPhoneInput';
+import { getPhoneText } from '@/object-record/record-field/ui/meta-types/input/utils/getPhoneText';
+import { createPhonesFromFieldValue } from '@/object-record/record-field/ui/meta-types/input/utils/phonesUtils';
+import { validatePhoneInput } from '@/object-record/record-field/ui/meta-types/input/utils/validatePhoneInput';
+import { recordFieldInputIsFieldInErrorComponentState } from '@/object-record/record-field/ui/states/recordFieldInputIsFieldInErrorComponentState';
+import {
+ type FieldPhonesValue,
+ type PhoneRecord,
+} from '@/object-record/record-field/ui/types/FieldMetadata';
+import { RecordFormMultiItemList } from '@/object-record/record-form/components/RecordFormMultiItemList';
+import { getRecordFormItemIndexAfterSave } from '@/object-record/record-form/utils/getRecordFormItemIndexAfterSave';
+import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';
+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { type CountryCode } from 'libphonenumber-js';
+import { useId, useRef, useState } from 'react';
+import { MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES } from 'twenty-shared/constants';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+import { Field } from 'twenty-ui/primitives/input';
+import { moveArrayItem } from '~/utils/array/moveArrayItem';
+import { toSpliced } from '~/utils/array/toSpliced';
+
+const getPhonesValue = (phones: PhoneRecord[]): FieldPhonesValue => {
+ const [primaryPhone, ...additionalPhones] = phones;
+
+ return {
+ primaryPhoneNumber: primaryPhone?.number ?? '',
+ primaryPhoneCountryCode: primaryPhone?.countryCode ?? '',
+ primaryPhoneCallingCode: primaryPhone?.callingCode ?? '',
+ additionalPhones,
+ };
+};
+
+type RecordFormPhonesFieldInputProps = {
+ label?: string;
+ defaultValue?: FieldPhonesValue;
+ defaultCountry?: CountryCode;
+ maxNumberOfValues?: number | null;
+ placeholder?: string;
+ onChange: (value: FieldPhonesValue) => void;
+};
+
+export const RecordFormPhonesFieldInput = ({
+ label,
+ defaultValue,
+ defaultCountry,
+ maxNumberOfValues,
+ placeholder,
+ onChange,
+}: RecordFormPhonesFieldInputProps) => {
+ const { t } = useLingui();
+ const instanceId = useId();
+
+ const setRecordFieldInputIsFieldInError = useSetAtomComponentState(
+ recordFieldInputIsFieldInErrorComponentState,
+ );
+
+ const maxItemCount = maxNumberOfValues ?? MULTI_ITEM_FIELD_DEFAULT_MAX_VALUES;
+ const isSingleItemMode = maxItemCount === 1;
+
+ const [savedPhones, setSavedPhones] = useState(() =>
+ createPhonesFromFieldValue(defaultValue),
+ );
+ const [shouldFocusInput, setShouldFocusInput] = useState(false);
+ const inputRef = useRef<HTMLInputElement>(null);
+ const [isInvalidInputLeft, setIsInvalidInputLeft] = useState(false);
+
+ const {
+ isInputOpen,
+ editedItemIndex,
+ inputValue,
+ hasError,
+ startAddingItem,
+ startEditingItem,
+ closeInput,
+ handleInputChange,
+ validateInputValue,
+ } = useMultiItemInput({
+ items: savedPhones,
+ getItemText: getPhoneText,
+ isInputInitiallyOpen: isSingleItemMode || savedPhones.length < maxItemCount,
+ initialEditedItemIndex:
+ isSingleItemMode && savedPhones.length > 0 ? 0 : null,
+ validateInput: validatePhoneInput,
+ });
+
+ const openNextInput = (phones: PhoneRecord[]) => {
+ if (isSingleItemMode && isNonEmptyArray(phones)) {
+ startEditingItem({ itemIndex: 0, currentItems: phones });
+ return;
+ }
+
+ if (phones.length < maxItemCount) {
+ startAddingItem();
+ return;
+ }
+
+ closeInput();
+ };
+
+ const isEditingItemInPlace = isDefined(editedItemIndex) && !isSingleItemMode;
+
+ const getPhonesWithInput = (sanitizedInput: string) =>
+ computeUpdatedMultiItemFieldItems({
+ sanitizedInput,
+ items: savedPhones,
+ editingIndex: isSingleItemMode ? 0 : editedItemIndex,
+ singleItemMode: isSingleItemMode,
+ formatInput: formatPhoneInput,
+ });
+
+ const savePhones = (phones: PhoneRecord[]) => {
+ setSavedPhones(phones);
+ setIsInvalidInputLeft(false);
+ setRecordFieldInputIsFieldInError(false);
+ onChange(getPhonesValue(phones));
+ };
+
+ const isInputValueValid = (value: string) => {
+ const sanitizedInput = value.trim();
+
+ return (
+ !isNonEmptyString(sanitizedInput) ||
+ validatePhoneInput(sanitizedInput).isValid
+ );
+ };
+
+ const handleTyping = (value: string) => {
+ handleInputChange(value);
+ setIsInvalidInputLeft(false);
+
+ const isValid = isInputValueValid(value);
+
+ setRecordFieldInputIsFieldInError(!isValid);
+ onChange(
+ getPhonesValue(isValid ? getPhonesWithInput(value.trim()) : savedPhones),
+ );
+ };
+
+ const saveInputValue = () => {
+ const sanitizedInput = validateInputValue();
+
+ if (!isDefined(sanitizedInput)) {
+ return null;
+ }
+
+ const updatedPhones = getPhonesWithInput(sanitizedInput);
+
+ savePhones(updatedPhones);
+
+ return updatedPhones;
+ };
+
+ const handleEnter = () => {
+ const updatedPhones = saveInputValue();
+
+ if (!isDefined(updatedPhones) || isSingleItemMode) {
+ return;
+ }
+
+ setShouldFocusInput(true);
+ openNextInput(updatedPhones);
+ inputRef.current?.focus();
+ };
+
+ const handleEscape = () => {
+ savePhones(savedPhones);
+ openNextInput(savedPhones);
+ };
+
+ const saveInputValueBeforeRowAction = (itemIndex: number) => {
+ const updatedPhones = saveInputValue();
+
+ if (!isDefined(updatedPhones)) {
+ return null;
+ }
+
+ const hasRemovedEditedItem = updatedPhones.length < savedPhones.length;
+
+ return {
+ updatedPhones,
+ itemIndexAfterSave: getRecordFormItemIndexAfterSave({
+ itemIndex,
+ removedItemIndex: hasRemovedEditedItem ? editedItemIndex : null,
+ }),
+ };
+ };
+
+ const handleEdit = (index: number) => {
+ const saveResult = saveInputValueBeforeRowAction(index);
+
+ if (!isDefined(saveResult)) {
+ return;
+ }
+
+ setShouldFocusInput(true);
+ if (isDefined(saveResult.itemIndexAfterSave)) {
+ startEditingItem({
+ itemIndex: saveResult.itemIndexAfterSave,
+ currentItems: saveResult.updatedPhones,
+ });
+ return;
+ }
+
+ openNextInput(saveResult.updatedPhones);
+ };
+
+ const updatePhones = ({
+ itemIndex,
+ getUpdatedPhones,
+ }: {
+ itemIndex: number;
+ getUpdatedPhones: (params: {
+ phones: PhoneRecord[];
+ itemIndex: number;
+ }) => PhoneRecord[];
+ }) => {
+ const saveResult = saveInputValueBeforeRowAction(itemIndex);
+
+ if (!isDefined(saveResult)) {
+ return;
+ }
+
+ const updatedPhones = isDefined(saveResult.itemIndexAfterSave)
+ ? getUpdatedPhones({
+ phones: saveResult.updatedPhones,
+ itemIndex: saveResult.itemIndexAfterSave,
+ })
+ : saveResult.updatedPhones;
+
+ savePhones(updatedPhones);
+ openNextInput(updatedPhones);
+ };
+
+ const isInputValueInvalid = hasError || isInvalidInputLeft;
+ const shouldShowItems = !isSingleItemMode && isNonEmptyArray(savedPhones);
+ const visiblePhones = shouldShowItems ? savedPhones : undefined;
+ const shouldShowInputInFooter = isInputOpen && !isEditingItemInPlace;
+ const inputSpacing: MultiItemFieldInputSpacing = shouldShowItems
+ ? 'compact'
+ : 'default';
+
+ const itemInput = (
+ <MultiItemFieldInputRow
+ spacing={inputSpacing}
+ hasPadding={shouldShowItems && shouldShowInputInFooter}
+ rightComponent={
+ isSingleItemMode ? undefined : (
+ <MultiItemFieldSaveButton
+ isAddingNewItem={!isDefined(editedItemIndex)}
+ onClick={handleEnter}
+ />
+ )
+ }
+ >
+ <PhonesFieldPhoneInput
+ ref={inputRef}
+ autoFocus={shouldFocusInput}
+ spacing={inputSpacing}
+ placeholder={placeholder ?? t`Phone`}
+ value={inputValue}
+ defaultCountry={defaultCountry}
+ onBlur={() => setIsInvalidInputLeft(!isInputValueValid(inputValue))}
+ onChange={handleTyping}
+ onEnter={handleEnter}
+ onEscape={handleEscape}
+ />
+ </MultiItemFieldInputRow>
+ );
+
+ return (
+ <FormFieldInputContainer>
+ {isNonEmptyString(label) ? <Field.Label>{label}</Field.Label> : null}
+ <RecordFormMultiItemList
+ hasError={isInputValueInvalid}
+ footer={shouldShowInputInFooter ? itemInput : undefined}
+ >
+ {visiblePhones?.map((phone, index) =>
+ index === editedItemIndex && isEditingItemInPlace ? (
+ <MultiItemFieldEditedItem
+ key={index}
+ hasSeparatorBefore={index > 0}
+ hasSeparatorAfter={index < savedPhones.length - 1}
+ >
+ {itemInput}
+ </MultiItemFieldEditedItem>
+ ) : (
+ <PhonesFieldMenuItem
+ key={index}
+ dropdownId={`${instanceId}-phone-${index}`}
+ showPrimaryIcon={index === 0 && savedPhones.length > 1}
+ showSetAsPrimaryButton={index > 0}
+ phone={phone}
+ onEdit={() => handleEdit(index)}
+ onSetAsPrimary={() =>
+ updatePhones({
+ itemIndex: index,
+ getUpdatedPhones: ({ phones, itemIndex }) =>
+ moveArrayItem(phones, { fromIndex: itemIndex, toIndex: 0 }),
+ })
+ }
+ onDelete={() =>
+ updatePhones({
+ itemIndex: index,
+ getUpdatedPhones: ({ phones, itemIndex }) =>
+ toSpliced(phones, itemIndex, 1),
+ })
+ }
+ />
+ ),
+ )}
+ </RecordFormMultiItemList>
+ {isInputValueInvalid ? (
+ <Field.Error match role="alert">
+ {t`Enter a valid phone number`}
+ </Field.Error>
+ ) : null}
+ </FormFieldInputContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/StyledRecordFormFieldBox.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/StyledRecordFormFieldBox.tsx
new file mode 100644
index 00000000000..045bfe37ab5
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/StyledRecordFormFieldBox.tsx
@@ -0,0 +1,24 @@
+import { styled } from '@linaria/react';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledRecordFormFieldBox = styled.div<{ hasError?: boolean }>`
+ background-color: ${themeCssVariables.background.transparent.lighter};
+ border-radius: ${themeCssVariables.border.radius.md};
+ box-shadow: inset 0 0 0 1px
+ ${({ hasError }) =>
+ hasError
+ ? themeCssVariables.border.color.danger
+ : themeCssVariables.border.color.medium};
+ box-sizing: border-box;
+ display: flex;
+ flex-direction: column;
+ width: 100%;
+
+ &:has(input:focus-visible) {
+ box-shadow: inset 0 0 0 1px
+ ${({ hasError }) =>
+ hasError
+ ? themeCssVariables.border.color.danger
+ : themeCssVariables.color.blue};
+ }
+`;
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx
index fb5c41f134a..d0bc0bb8d3d 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx
@@ -65,6 +65,42 @@ const tagsFieldMetadataItem: FieldMetadataItem = {
defaultValue: null,
};
+const phonesFieldMetadataItem: FieldMetadataItem = {
+ ...getMockFieldMetadataItemOrThrow({
+ objectMetadataItem: personObjectMetadataItem,
+ fieldName: 'phones',
+ }),
+ label: 'Phones',
+ settings: null,
+ defaultValue: null,
+};
+
+const linkedinFieldMetadataItem: FieldMetadataItem = {
+ ...getMockFieldMetadataItemOrThrow({
+ objectMetadataItem: personObjectMetadataItem,
+ fieldName: 'linkedinLink',
+ }),
+ label: 'Linkedin',
+ settings: null,
+};
+
+const filesFieldMetadataItem: FieldMetadataItem = {
+ ...emailsFieldMetadataItem,
+ id: 'files-field-metadata-id',
+ name: 'attachments',
+ label: 'Attachments',
+ type: FieldMetadataType.FILES,
+ defaultValue: null,
+};
+
+const nameFieldMetadataItem: FieldMetadataItem = {
+ ...getMockFieldMetadataItemOrThrow({
+ objectMetadataItem: personObjectMetadataItem,
+ fieldName: 'name',
+ }),
+ label: 'Name',
+};
+
type RecordFormFieldInputsWithDraftProps = {
fieldMetadataItems: FieldMetadataItem[];
initialDraftRecord?: Partial<ObjectRecord>;
@@ -328,14 +364,12 @@ export const InvalidEmail: Story = {
primaryEmail: '',
additionalEmails: [],
});
- await expect(input).toHaveAttribute('aria-invalid', 'true');
await expect(canvas.getByRole('alert')).toHaveTextContent(
'Enter a valid email',
);
await userEvent.type(input, 'northwind.io');
- await expect(input).not.toHaveAttribute('aria-invalid');
await expect(canvas.queryByRole('alert')).not.toBeInTheDocument();
await expect(args.onFieldValueChange).toHaveBeenLastCalledWith('emails', {
primaryEmail: '[email protected]',
@@ -355,7 +389,6 @@ export const InvalidEmailLeftUnsubmitted: Story = {
await userEvent.type(input, 'lea@');
await userEvent.tab();
- await expect(input).toHaveAttribute('aria-invalid', 'true');
await expect(canvas.getByRole('alert')).toHaveTextContent(
'Enter a valid email',
);
@@ -485,3 +518,212 @@ export const StoredListValues: Story = {
await expect(args.onFieldValueChange).not.toHaveBeenCalled();
},
};
+
+export const Phones: Story = {
+ args: {
+ fieldMetadataItems: [phonesFieldMetadataItem],
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const input = canvas.getByRole('textbox');
+
+ await userEvent.type(input, '+33612345678');
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith('phones', {
+ primaryPhoneNumber: '612345678',
+ primaryPhoneCountryCode: 'FR',
+ primaryPhoneCallingCode: '+33',
+ additionalPhones: [],
+ });
+
+ await userEvent.keyboard('{Enter}');
+
+ await expect(canvas.getByText('+33 6 12 34 56 78')).toBeVisible();
+ await expect(canvas.getByRole('textbox')).toHaveValue('');
+ await expect(canvas.getByRole('textbox')).toHaveFocus();
+ },
+};
+
+export const InvalidPhone: Story = {
+ args: {
+ fieldMetadataItems: [phonesFieldMetadataItem],
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.type(canvas.getByRole('textbox'), '+331{Enter}');
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith('phones', {
+ primaryPhoneNumber: '',
+ primaryPhoneCountryCode: '',
+ primaryPhoneCallingCode: '',
+ additionalPhones: [],
+ });
+ await expect(canvas.getByRole('alert')).toHaveTextContent(
+ 'Enter a valid phone number',
+ );
+ },
+};
+
+export const LinksLabelEdit: Story = {
+ args: {
+ fieldMetadataItems: [linkedinFieldMetadataItem],
+ initialDraftRecord: {
+ linkedinLink: {
+ primaryLinkUrl: 'https://linkedin.com/in/lea',
+ primaryLinkLabel: null,
+ secondaryLinks: [],
+ },
+ },
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole('button', { name: 'More options' }));
+ await userEvent.click(await body.findByRole('menuitem', { name: 'Edit' }));
+
+ await userEvent.type(
+ await canvas.findByRole('textbox', { name: 'Label' }),
+ 'Lea Martin',
+ );
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'linkedinLink',
+ {
+ primaryLinkUrl: 'https://linkedin.com/in/lea',
+ primaryLinkLabel: 'Lea Martin',
+ secondaryLinks: [],
+ },
+ );
+
+ await userEvent.keyboard('{Enter}');
+
+ await expect(canvas.getByText('Lea Martin')).toBeVisible();
+ await expect(
+ canvas.queryByRole('textbox', { name: 'Label' }),
+ ).not.toBeInTheDocument();
+ },
+};
+
+export const InvalidLink: Story = {
+ args: {
+ fieldMetadataItems: [linkedinFieldMetadataItem],
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.type(canvas.getByRole('textbox'), 'not a url');
+ await userEvent.tab();
+
+ await expect(canvas.getByRole('alert')).toHaveTextContent(
+ 'Enter a valid URL',
+ );
+ },
+};
+
+export const FilesRenameAndDelete: Story = {
+ args: {
+ fieldMetadataItems: [filesFieldMetadataItem],
+ initialDraftRecord: {
+ attachments: [
+ {
+ fileId: 'deck-file-id',
+ label: 'deck.pdf',
+ extension: 'pdf',
+ url: 'https://example.com/deck.pdf',
+ },
+ {
+ fileId: 'notes-file-id',
+ label: 'notes.txt',
+ extension: 'txt',
+ url: 'https://example.com/notes.txt',
+ },
+ ],
+ },
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await expect(
+ canvas.getByRole('button', { name: 'Upload file' }),
+ ).toBeVisible();
+
+ await userEvent.click(
+ canvas.getAllByRole('button', { name: 'More options' })[0],
+ );
+ await userEvent.click(await body.findByRole('menuitem', { name: 'Edit' }));
+
+ const labelInput = await canvas.findByDisplayValue('deck.pdf');
+
+ await userEvent.clear(labelInput);
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'attachments',
+ [
+ expect.objectContaining({ label: 'deck.pdf' }),
+ expect.objectContaining({ label: 'notes.txt' }),
+ ],
+ );
+
+ await userEvent.type(labelInput, 'pitch.pdf{Enter}');
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'attachments',
+ [
+ expect.objectContaining({ fileId: 'deck-file-id', label: 'pitch.pdf' }),
+ expect.objectContaining({ fileId: 'notes-file-id' }),
+ ],
+ );
+ await expect(canvas.getByText('pitch.pdf')).toBeVisible();
+
+ await userEvent.click(
+ canvas.getAllByRole('button', { name: 'More options' })[1],
+ );
+ await userEvent.click(
+ await body.findByRole('menuitem', { name: 'Delete' }),
+ );
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'attachments',
+ [expect.objectContaining({ fileId: 'deck-file-id' })],
+ );
+ await expect(canvas.queryByText('notes.txt')).not.toBeInTheDocument();
+ },
+};
+
+export const FullName: Story = {
+ args: {
+ fieldMetadataItems: [nameFieldMetadataItem],
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.type(
+ canvas.getByRole('textbox', { name: 'Name' }),
+ 'Jean de la Fontaine',
+ );
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith('name', {
+ firstName: 'Jean',
+ lastName: 'de la Fontaine',
+ });
+
+ await userEvent.click(canvas.getByRole('button', { name: 'Name details' }));
+
+ const firstNameInput = canvas.getByRole('textbox', { name: 'First name' });
+
+ await expect(firstNameInput).toHaveValue('Jean');
+
+ await userEvent.type(firstNameInput, ' Baptiste');
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith('name', {
+ firstName: 'Jean Baptiste',
+ lastName: 'de la Fontaine',
+ });
+ await expect(canvas.getByRole('textbox', { name: 'Name' })).toHaveValue(
+ 'Jean Baptiste de la Fontaine',
+ );
+ },
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/splitFullNameInputText.test.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/splitFullNameInputText.test.ts
new file mode 100644
index 00000000000..e8f40c5821c
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/splitFullNameInputText.test.ts
@@ -0,0 +1,59 @@
+import { splitFullNameInputText } from '@/object-record/record-form/utils/splitFullNameInputText';
+
+const EMPTY_FULL_NAME = { firstName: '', lastName: '' };
+
+describe('splitFullNameInputText', () => {
+ it('makes the first word the first name and the rest the last name', () => {
+ expect(
+ splitFullNameInputText({
+ text: 'Jean de la Fontaine',
+ currentFullName: EMPTY_FULL_NAME,
+ }),
+ ).toEqual({ firstName: 'Jean', lastName: 'de la Fontaine' });
+ });
+
+ it('keeps a single word as the first name', () => {
+ expect(
+ splitFullNameInputText({
+ text: ' Mary ',
+ currentFullName: EMPTY_FULL_NAME,
+ }),
+ ).toEqual({ firstName: 'Mary', lastName: '' });
+ });
+
+ it('keeps a single word in the last name when only the last name was set', () => {
+ expect(
+ splitFullNameInputText({
+ text: 'Smith',
+ currentFullName: { firstName: '', lastName: 'Smth' },
+ }),
+ ).toEqual({ firstName: '', lastName: 'Smith' });
+ });
+
+ it('returns empty names for blank text', () => {
+ expect(
+ splitFullNameInputText({
+ text: ' ',
+ currentFullName: { firstName: 'Mary', lastName: '' },
+ }),
+ ).toEqual(EMPTY_FULL_NAME);
+ });
+
+ it('keeps a compound first name while the text still starts with it', () => {
+ expect(
+ splitFullNameInputText({
+ text: 'Mary Ann Smyth',
+ currentFullName: { firstName: 'Mary Ann', lastName: 'Smith' },
+ }),
+ ).toEqual({ firstName: 'Mary Ann', lastName: 'Smyth' });
+ });
+
+ it('splits again once the compound first name is edited', () => {
+ expect(
+ splitFullNameInputText({
+ text: 'Marie Ann Smith',
+ currentFullName: { firstName: 'Mary Ann', lastName: 'Smith' },
+ }),
+ ).toEqual({ firstName: 'Marie', lastName: 'Ann Smith' });
+ });
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/splitFullNameInputText.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/splitFullNameInputText.ts
new file mode 100644
index 00000000000..3416eb34e9c
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/splitFullNameInputText.ts
@@ -0,0 +1,41 @@
+import { type FieldFullNameValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { isNonEmptyString } from '@sniptt/guards';
+import { splitFullName } from '~/utils/format/splitFullName';
+
+export const splitFullNameInputText = ({
+ text,
+ currentFullName,
+}: {
+ text: string;
+ currentFullName: FieldFullNameValue;
+}): FieldFullNameValue => {
+ const trimmedText = text.trim();
+ const { firstName: currentFirstName, lastName: currentLastName } =
+ currentFullName;
+
+ const shouldKeepCompoundFirstName =
+ isNonEmptyString(currentFirstName) &&
+ currentFirstName.includes(' ') &&
+ (trimmedText === currentFirstName ||
+ trimmedText.startsWith(`${currentFirstName} `));
+
+ if (shouldKeepCompoundFirstName) {
+ return {
+ firstName: currentFirstName,
+ lastName: trimmedText.slice(currentFirstName.length).trim(),
+ };
+ }
+
+ const shouldKeepSingleWordInLastName =
+ !isNonEmptyString(currentFirstName) &&
+ isNonEmptyString(currentLastName) &&
+ !trimmedText.includes(' ');
+
+ if (shouldKeepSingleWordInLastName) {
+ return { firstName: '', lastName: trimmedText };
+ }
+
+ const [firstName, lastName] = splitFullName(trimmedText);
+
+ return { firstName, lastName };
+};
diff --git a/packages/twenty-shared/src/utils/fieldMetadata/__tests__/isFieldMetadataEligibleForRecordForm.spec.ts b/packages/twenty-shared/src/utils/fieldMetadata/__tests__/isFieldMetadataEligibleForRecordForm.spec.ts
index 219b77e9ad5..b3ce0c48438 100644
--- a/packages/twenty-shared/src/utils/fieldMetadata/__tests__/isFieldMetadataEligibleForRecordForm.spec.ts
+++ b/packages/twenty-shared/src/utils/fieldMetadata/__tests__/isFieldMetadataEligibleForRecordForm.spec.ts
@@ -29,6 +29,15 @@ describe('isFieldMetadataEligibleForRecordForm', () => {
).toBe(false);
});
+ it('accepts a files field', () => {
+ expect(
+ isFieldMetadataEligibleForRecordForm({
+ ...ELIGIBLE_TEXT_FIELD,
+ fieldType: FieldMetadataType.FILES,
+ }),
+ ).toBe(true);
+ });
+
it('rejects the id field', () => {
expect(
isFieldMetadataEligibleForRecordForm({
@@ -44,7 +53,6 @@ describe('isFieldMetadataEligibleForRecordForm', () => {
FieldMetadataType.POSITION,
FieldMetadataType.ACTOR,
FieldMetadataType.RATING,
- FieldMetadataType.FILES,
FieldMetadataType.NUMERIC,
])('rejects the unsupported type %s', (fieldType) => {
expect(
diff --git a/packages/twenty-shared/src/utils/fieldMetadata/isFieldMetadataEligibleForRecordForm.ts b/packages/twenty-shared/src/utils/fieldMetadata/isFieldMetadataEligibleForRecordForm.ts
index 72f06324ec6..3a4f287031e 100644
--- a/packages/twenty-shared/src/utils/fieldMetadata/isFieldMetadataEligibleForRecordForm.ts
+++ b/packages/twenty-shared/src/utils/fieldMetadata/isFieldMetadataEligibleForRecordForm.ts
@@ -8,6 +8,7 @@ const RECORD_FORM_SUPPORTED_FIELD_TYPES: readonly FieldMetadataType[] = [
FieldMetadataType.DATE,
FieldMetadataType.DATE_TIME,
FieldMetadataType.EMAILS,
+ FieldMetadataType.FILES,
FieldMetadataType.FULL_NAME,
FieldMetadataType.LINKS,
FieldMetadataType.MORPH_RELATION,