diff --git a/.changeset/violet-bikes-brake.md b/.changeset/violet-bikes-brake.md new file mode 100644 index 0000000000000..3fe3152289754 --- /dev/null +++ b/.changeset/violet-bikes-brake.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/i18n": patch +--- + +Fixes issue where a invalid `Accounts_CustomFieldsToShowInUserInfo` value would break the ui diff --git a/apps/meteor/client/hooks/useUserCustomFields.spec.tsx b/apps/meteor/client/hooks/useUserCustomFields.spec.tsx new file mode 100644 index 0000000000000..4c38adc2f3e8a --- /dev/null +++ b/apps/meteor/client/hooks/useUserCustomFields.spec.tsx @@ -0,0 +1,23 @@ +import { mockAppRoot } from '@rocket.chat/mock-providers'; +import { renderHook, waitFor } from '@testing-library/react'; + +import { useUserCustomFields } from './useUserCustomFields'; + +it('should not break with invalid Accounts_CustomFieldsToShowInUserInfo setting', async () => { + const { result } = renderHook( + () => + useUserCustomFields({ + prop: 'value', + }), + { + legacyRoot: true, + wrapper: mockAppRoot() + .withSetting('Accounts_CustomFieldsToShowInUserInfo', '{"Invalid": "Object", "InvalidProperty": "Invalid" }') + .build(), + }, + ); + + await waitFor(() => !!result.current); + + expect(result.current).toEqual(undefined); +}); diff --git a/apps/meteor/client/hooks/useUserCustomFields.ts b/apps/meteor/client/hooks/useUserCustomFields.ts index b66f8c4da7e84..ad21d836ee7c8 100644 --- a/apps/meteor/client/hooks/useUserCustomFields.ts +++ b/apps/meteor/client/hooks/useUserCustomFields.ts @@ -27,6 +27,11 @@ export const useUserCustomFields = (customFields: CustomField): CustomFieldDispl return undefined; } + if (!Array.isArray(customFieldsToShowObj)) { + console.warn('Invalid customFieldsToShowInUserInfo value'); + return undefined; + } + const customFieldsToShow = customFieldsToShowObj.map((value) => { if (!value) { return undefined; diff --git a/apps/meteor/server/settings/accounts.ts b/apps/meteor/server/settings/accounts.ts index fea95815e4419..b2c51b7978755 100644 --- a/apps/meteor/server/settings/accounts.ts +++ b/apps/meteor/server/settings/accounts.ts @@ -237,6 +237,7 @@ export const createAccountSettings = () => await this.add('Accounts_CustomFieldsToShowInUserInfo', '', { type: 'string', public: true, + i18nDescription: 'Accounts_CustomFieldsToShowInUserInfo_Description', }); await this.add('Accounts_LoginExpiration', 90, { type: 'int', diff --git a/packages/i18n/src/locales/en.i18n.json b/packages/i18n/src/locales/en.i18n.json index 4ac4e83ec8f0f..6478106c15d7e 100644 --- a/packages/i18n/src/locales/en.i18n.json +++ b/packages/i18n/src/locales/en.i18n.json @@ -108,6 +108,7 @@ "Accounts_BlockedUsernameList_Description": "Comma-separated list of blocked usernames (case-insensitive)", "Accounts_CustomFields_Description": "Should be a valid JSON where keys are the field names containing a dictionary of field settings. Example: \n`{\"role\":{ \"type\": \"select\", \"defaultValue\": \"student\", \"options\": [\"teacher\", \"student\"], \"required\": true, \"modifyRecordField\": { \"array\": true, \"field\": \"roles\" } }, \"twitter\": { \"type\": \"text\", \"required\": true, \"minLength\": 2, \"maxLength\": 10 }}`", "Accounts_CustomFieldsToShowInUserInfo": "Custom Fields to Show in User Info", + "Accounts_CustomFieldsToShowInUserInfo_Description": "Value must be an array of objects where the key is the label and the value the field name. Example: `[{\"Role Label\": \"role\"}, {\"Twitter Label\": \"twitter\"}]` more info at [Custom Fields](https://docs.rocket.chat/docs/custom-fields)", "Accounts_Default_User_Preferences": "Default User Preferences", "Accounts_Default_User_Preferences_audioNotifications": "Audio Notifications Default Alert", "Accounts_Default_User_Preferences_alsoSendThreadToChannel_Description": "Allow users to select the Also send to channel behavior",