twenty/packages
dostavic 4cc95d4794
fix: Set field type icon as the default icon for new fields (#7352) (#7579)
Closes #7352

**Summary**

Moved the `defaultIconsByFieldType` mapping from the
`SettingsObjectNewFieldConfigure` component to a separate constants
file. This change improves code organization and maintainability without
changing functionality.

**Changes Made**

- **Created a new constants file:** Added `FieldTypeIcons.ts`, located
in `src/pages/settings/data-model/constants/`, to store the mapping of
`FieldMetadataType` to default icons.
    
```
    // FieldTypeIcons.ts
    
    import { FieldMetadataType } from '~/generated-metadata/graphql';
    
    export const defaultIconsByFieldType: Record<FieldMetadataType, string> = {
      [FieldMetadataType.Address]: 'IconLocation',
      [FieldMetadataType.Boolean]: 'IconCheckbox',
      [FieldMetadataType.Currency]: 'IconCurrency',
      [FieldMetadataType.Date]: 'IconCalendar',
      [FieldMetadataType.DateTime]: 'IconClock',
      [FieldMetadataType.Email]: 'IconMail',
      [FieldMetadataType.FullName]: 'IconUser',
      [FieldMetadataType.Link]: 'IconLink',
      [FieldMetadataType.MultiSelect]: 'IconList',
      [FieldMetadataType.Number]: 'IconNumber',
      [FieldMetadataType.Phone]: 'IconPhone',
      [FieldMetadataType.Rating]: 'IconStar',
      [FieldMetadataType.RawJson]: 'IconCode',
      [FieldMetadataType.Relation]: 'IconRelationOneToMany',
      [FieldMetadataType.Select]: 'IconSelect',
      [FieldMetadataType.Text]: 'IconTypography',
      [FieldMetadataType.Uuid]: 'IconKey',
      [FieldMetadataType.Array]: 'IconCodeDots',
      [FieldMetadataType.Emails]: 'IconMail',
      [FieldMetadataType.Links]: 'IconLink',
      [FieldMetadataType.Phones]: 'IconPhone',
      [FieldMetadataType.Actor]: 'IconUsers',
      [FieldMetadataType.Numeric]: 'IconUsers',
      [FieldMetadataType.Position]: 'IconUsers',
      [FieldMetadataType.RichText]: 'IconUsers',
      [FieldMetadataType.TsVector]: 'IconUsers',
      // Add other field types as needed
    };
```
    
- **Updated the import in the component:** In the file
`SettingsObjectNewFieldConfigure.tsx`, imported the mapping from the new
constants file.
    
    
    ```// SettingsObjectNewFieldConfigure.tsx
    
import { defaultIconsByFieldType } from
'~/pages/settings/data-model/constants/FieldTypeIcons';
    
- **Adjusted form configuration:** Modified `defaultValues` in `useForm`
and `useEffect` to use the imported mapping.
    
```
    `const formConfig = useForm<SettingsDataModelNewFieldFormValues>({
      mode: 'onTouched',
      resolver: zodResolver(
        settingsFieldFormSchema(
          activeObjectMetadataItem?.fields.map((value) => value.name),
        ),
      ),
      defaultValues: {
        type: fieldType,
        icon: defaultIconsByFieldType[fieldType] || 'IconUsers',
        label: '',
        description: '',
      },
    });
    
    useEffect(() => {
      formConfig.setValue('icon', defaultIconsByFieldType[fieldType] || 'IconUsers');
    }, [fieldType, formConfig]);`

---------

Co-authored-by: Your Name <you@example.com>
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
2024-10-11 15:55:33 +02:00
..
twenty-chrome-extension Support for multiple values in the Phone field (#6882) 2024-09-11 11:15:04 +02:00
twenty-docker Updating terraform and k8s files adding redis... (#7425) 2024-10-07 10:23:42 +02:00
twenty-e2e-testing E2E tests (#6717) 2024-08-27 11:07:10 +02:00
twenty-emails 7417 workflows i can send emails using the email account (#7431) 2024-10-08 23:29:09 +02:00
twenty-front fix: Set field type icon as the default icon for new fields (#7352) (#7579) 2024-10-11 15:55:33 +02:00
twenty-postgres Check if user wants to run make postgres-on-linux (#6819) 2024-09-04 16:58:54 +02:00
twenty-server docs: enhance REST API OpenAPI spec with nested filter example (#7366) 2024-10-10 16:35:20 +02:00
twenty-ui Fix for view switcher default icon display (#7029) 2024-10-10 10:12:17 +02:00
twenty-utils Fix docs build in CI (#5826) 2024-06-11 19:06:37 +02:00
twenty-website Added callback url structure for self hosting (#7570) 2024-10-10 17:01:16 +02:00
twenty-zapier Fix zapier tests (#7568) 2024-10-10 16:34:34 +02:00