From f566fe3ba63c85faf8d1fe26c9958794acc31797 Mon Sep 17 00:00:00 2001 From: dougfabris Date: Thu, 7 Dec 2023 11:25:54 -0300 Subject: [PATCH 1/8] chore: `Field` normalization --- .../CreateDiscussion/CreateDiscussion.tsx | 16 +- .../Omnichannel/modals/CloseChatModal.tsx | 206 ++++++------- .../CreateChannel/CreateChannelModal.tsx | 62 ++-- .../header/CreateTeam/CreateTeamModal.tsx | 52 ++-- .../accessibility/AccessibilityPage.tsx | 86 +++--- .../AccountFeaturePreviewPage.tsx | 8 +- .../PreferencesConversationTranscript.tsx | 20 +- .../omnichannel/PreferencesGeneral.tsx | 10 +- .../PreferencesMessagesSection.tsx | 194 ++++++------- .../PreferencesNotificationsSection.tsx | 106 ++++--- .../preferences/PreferencesSoundSection.tsx | 4 +- .../PreferencesUserPresenceSection.tsx | 22 +- .../tokens/AccountTokensTable/AddToken.tsx | 61 ++-- .../views/admin/emailInbox/EmailInboxForm.tsx | 18 +- .../incoming/IncomingWebhookForm.tsx | 52 ++-- .../outgoing/OutgoingWebhookForm.tsx | 128 ++++----- .../client/views/admin/mailer/MailerPage.tsx | 2 +- .../views/admin/oauthApps/EditOauthApp.tsx | 6 +- .../views/admin/oauthApps/OAuthAddApp.tsx | 6 +- .../views/admin/permissions/RoleForm.tsx | 18 +- .../client/views/admin/rooms/EditRoom.tsx | 176 ++++++------ .../admin/settings/ResetSettingButton.tsx | 2 +- .../settings/inputs/BooleanSettingInput.tsx | 11 +- .../views/admin/users/AdminUserForm.tsx | 134 ++++----- .../RegisterWorkspaceSetupStepOneModal.tsx | 29 +- .../views/admin/workspace/WorkspaceRoute.tsx | 8 +- .../omnichannel/appearance/AppearanceForm.tsx | 125 ++++---- .../customFields/EditCustomFields.tsx | 33 +-- .../departments/EditDepartment.tsx | 77 ++--- .../omnichannel/triggers/EditTrigger.tsx | 33 +-- .../AutoTranslate/AutoTranslate.tsx | 2 +- .../Info/EditRoomInfo/EditRoomInfo.tsx | 270 ++++++++---------- .../components/MessageSearchForm.tsx | 2 +- .../components/NotificationToggle.tsx | 12 +- .../PruneMessages/PruneMessages.tsx | 10 +- .../Threads/components/ThreadChat.tsx | 8 +- .../additionalForms/BusinessHoursMultiple.js | 24 +- .../CustomFieldsAdditionalForm.tsx | 38 ++- .../components/cannedResponseForm.tsx | 98 +++---- .../rocketchat-i18n/i18n/en.i18n.json | 1 + 40 files changed, 989 insertions(+), 1181 deletions(-) diff --git a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx index 95c4c7b2c437..c191fb150873 100644 --- a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx +++ b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx @@ -141,16 +141,14 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug )} - + {t('Encrypted')} - - } - /> - - + } + /> + diff --git a/apps/meteor/client/components/Omnichannel/modals/CloseChatModal.tsx b/apps/meteor/client/components/Omnichannel/modals/CloseChatModal.tsx index 67d650186680..d16172ddc7fc 100644 --- a/apps/meteor/client/components/Omnichannel/modals/CloseChatModal.tsx +++ b/apps/meteor/client/components/Omnichannel/modals/CloseChatModal.tsx @@ -136,113 +136,113 @@ const CloseChatModal = ({ } }, [transcriptEmail, setValue, visitorEmail, subject, t]); - return commentRequired || tagRequired || canSendTranscript ? ( - }> - - - {t('Wrap_up_conversation')} - - - - {t('Close_room_description')} - - - {t('Comment')} - - - - {errors.comment?.message} - - - - {errors.tags?.message} - - {canSendTranscript && ( - <> - - - {t('Chat_transcript')} - - {canSendTranscriptPDF && ( - - - - - {t('Omnichannel_transcript_pdf')} - - + if (commentRequired || tagRequired || canSendTranscript) { + return ( + }> + + + {t('Wrap_up_conversation')} + + + + {t('Close_room_description')} + + + {t('Comment')} + + + + {errors.comment?.message} + + + + {errors.tags?.message} + + {canSendTranscript && ( + <> + + + {t('Chat_transcript')} - )} - {canSendTranscriptEmail && ( - <> + {canSendTranscriptPDF && ( - - - {t('Omnichannel_transcript_email')} - + {t('Omnichannel_transcript_pdf')} + - {transcriptEmail && ( - <> - - {t('Contact_email')} - - - - - - {t('Subject')} - - - - {errors.subject?.message} - - - )} - - )} - - - {canSendTranscriptPDF && canSendTranscriptEmail - ? t('These_options_affect_this_conversation_only_To_set_default_selections_go_to_My_Account_Omnichannel') - : t('This_option_affect_this_conversation_only_To_set_default_selection_go_to_My_Account_Omnichannel')} - - - - )} - - - - - - - - - - ) : ( + )} + {canSendTranscriptEmail && ( + <> + + + {t('Omnichannel_transcript_email')} + + + + {transcriptEmail && ( + <> + + {t('Contact_email')} + + + + + + {t('Subject')} + + + + {errors.subject?.message} + + + )} + + )} + + + {canSendTranscriptPDF && canSendTranscriptEmail + ? t('These_options_affect_this_conversation_only_To_set_default_selections_go_to_My_Account_Omnichannel') + : t('This_option_affect_this_conversation_only_To_set_default_selection_go_to_My_Account_Omnichannel')} + + + + )} + + + + + + + + + + ); + } + + return ( + /> ); }; diff --git a/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx b/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx index f693648d0deb..2708e6e0a1e3 100644 --- a/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx +++ b/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx @@ -240,13 +240,8 @@ const CreateChannelModal = ({ teamId = '', onClose }: CreateChannelModalProps): {t('Channel_what_is_this_channel_about')} - - - {t('Private')} - - {isPrivate ? t('Only_invited_users_can_acess_this_channel') : t('Everyone_can_access_this_channel')} - - + + {t('Private')} )} /> - + + + {isPrivate ? t('Only_invited_users_can_acess_this_channel') : t('Everyone_can_access_this_channel')} + - - - {t('Federation_Matrix_Federated')} - {t(getFederationHintKey(federatedModule, federationEnabled))} - + + {t('Federation_Matrix_Federated')} )} /> - + + {t(getFederationHintKey(federatedModule, federationEnabled))} - - - {t('Read_only')} - - {readOnly ? t('Only_authorized_users_can_write_new_messages') : t('All_users_in_the_channel_can_write_new_messages')} - - + + {t('Read_only')} )} /> - + + + {readOnly ? t('Only_authorized_users_can_write_new_messages') : t('All_users_in_the_channel_can_write_new_messages')} + - - - {t('Encrypted')} - - {isPrivate ? t('Encrypted_channel_Description') : t('Encrypted_not_available')} - - + + {t('Encrypted')} )} /> - + + + {isPrivate ? t('Encrypted_channel_Description') : t('Encrypted_not_available')} + - - - {t('Broadcast')} - {t('Broadcast_channel_Description')} - + + {t('Broadcast')} )} /> - + + {t('Broadcast_channel_Description')} {t('Add_members')} diff --git a/apps/meteor/client/sidebar/header/CreateTeam/CreateTeamModal.tsx b/apps/meteor/client/sidebar/header/CreateTeam/CreateTeamModal.tsx index af91766e918b..115a8563f393 100644 --- a/apps/meteor/client/sidebar/header/CreateTeam/CreateTeamModal.tsx +++ b/apps/meteor/client/sidebar/header/CreateTeam/CreateTeamModal.tsx @@ -207,13 +207,8 @@ const CreateTeamModal = ({ onClose }: { onClose: () => void }): ReactElement => - - - {t('Teams_New_Private_Label')} - - {isPrivate ? t('Teams_New_Private_Description_Enabled') : t('Teams_New_Private_Description_Disabled')} - - + + {t('Teams_New_Private_Label')} void }): ReactElement => )} /> - + + + {isPrivate ? t('Teams_New_Private_Description_Enabled') : t('Teams_New_Private_Description_Disabled')} + - - - {t('Teams_New_Read_only_Label')} - - {readOnly ? t('Only_authorized_users_can_write_new_messages') : t('Teams_New_Read_only_Description')} - - + + {t('Teams_New_Read_only_Label')} void }): ReactElement => /> )} /> - + + + {readOnly ? t('Only_authorized_users_can_write_new_messages') : t('Teams_New_Read_only_Description')} + - - - {t('Teams_New_Encrypted_Label')} - - {isPrivate ? t('Teams_New_Encrypted_Description_Enabled') : t('Teams_New_Encrypted_Description_Disabled')} - - + + {t('Teams_New_Encrypted_Label')} void }): ReactElement => /> )} /> - + + + {isPrivate ? t('Teams_New_Encrypted_Description_Enabled') : t('Teams_New_Encrypted_Description_Disabled')} + - - - {t('Teams_New_Broadcast_Label')} - {t('Teams_New_Broadcast_Description')} - + + {t('Teams_New_Broadcast_Label')} void }): ReactElement => )} /> - + + {t('Teams_New_Broadcast_Description')} diff --git a/apps/meteor/client/views/account/accessibility/AccessibilityPage.tsx b/apps/meteor/client/views/account/accessibility/AccessibilityPage.tsx index 041215b0ebaa..38e67e38d13d 100644 --- a/apps/meteor/client/views/account/accessibility/AccessibilityPage.tsx +++ b/apps/meteor/client/views/account/accessibility/AccessibilityPage.tsx @@ -95,20 +95,18 @@ const AccessibilityPage = () => { {themes.map(({ id, title, description }, index) => { return ( - + {t(title)} - - ( - onChange(id)} checked={value === id} /> - )} - /> - - + ( + onChange(id)} checked={value === id} /> + )} + /> + {t(description)} @@ -134,18 +132,16 @@ const AccessibilityPage = () => { {t('Adjustable_font_size_description')} - + {t('Mentions_with_@_symbol')} - - ( - - )} - /> - - + ( + + )} + /> + { - + {t('Show_usernames')} + ( + onChange(!(e.target as HTMLInputElement).checked)} + /> + )} + /> + + {t('Show_or_hide_the_username_of_message_authors')} + + {displayRolesEnabled && ( + + {t('Show_roles')} ( onChange(!(e.target as HTMLInputElement).checked)} @@ -184,28 +198,6 @@ const AccessibilityPage = () => { )} /> - - {t('Show_or_hide_the_username_of_message_authors')} - - {displayRolesEnabled && ( - - - {t('Show_roles')} - - ( - onChange(!(e.target as HTMLInputElement).checked)} - /> - )} - /> - - {t('Show_or_hide_the_user_roles_of_message_authors')} )} diff --git a/apps/meteor/client/views/account/featurePreview/AccountFeaturePreviewPage.tsx b/apps/meteor/client/views/account/featurePreview/AccountFeaturePreviewPage.tsx index 29b2a796953e..63e4563ade13 100644 --- a/apps/meteor/client/views/account/featurePreview/AccountFeaturePreviewPage.tsx +++ b/apps/meteor/client/views/account/featurePreview/AccountFeaturePreviewPage.tsx @@ -106,12 +106,10 @@ const AccountFeaturePreviewPage = () => { {features.map((feature) => ( - + {t(feature.i18n)} - - - - + + {feature.description && {t(feature.description)}} {feature.imageUrl && } diff --git a/apps/meteor/client/views/account/omnichannel/PreferencesConversationTranscript.tsx b/apps/meteor/client/views/account/omnichannel/PreferencesConversationTranscript.tsx index 8b11367775dd..8cf34b6a56d4 100644 --- a/apps/meteor/client/views/account/omnichannel/PreferencesConversationTranscript.tsx +++ b/apps/meteor/client/views/account/omnichannel/PreferencesConversationTranscript.tsx @@ -23,7 +23,7 @@ const PreferencesConversationTranscript = () => { - + {t('Omnichannel_transcript_pdf')} @@ -33,14 +33,12 @@ const PreferencesConversationTranscript = () => { - - - - + + {t('Accounts_Default_User_Preferences_omnichannelTranscriptPDF_Description')} - + {t('Omnichannel_transcript_email')} @@ -51,14 +49,8 @@ const PreferencesConversationTranscript = () => { )} - - - - + + {t('Accounts_Default_User_Preferences_omnichannelTranscriptEmail_Description')} diff --git a/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx b/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx index 67c06bd2c5b2..2f58ed305be4 100644 --- a/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx +++ b/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx @@ -1,4 +1,4 @@ -import { Box, Field, FieldGroup, FieldHint, FieldLabel, FieldRow, ToggleSwitch } from '@rocket.chat/fuselage'; +import { Field, FieldGroup, FieldHint, FieldLabel, FieldRow, ToggleSwitch } from '@rocket.chat/fuselage'; import { useUniqueId } from '@rocket.chat/fuselage-hooks'; import { useTranslation } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; @@ -13,12 +13,10 @@ export const PreferencesGeneral = (): ReactElement => { return ( - + {t('Omnichannel_hide_conversation_after_closing')} - - - - + + {t('Omnichannel_hide_conversation_after_closing_description')} diff --git a/apps/meteor/client/views/account/preferences/PreferencesMessagesSection.tsx b/apps/meteor/client/views/account/preferences/PreferencesMessagesSection.tsx index 3edfabf23ac5..b8b4366cf4ff 100644 --- a/apps/meteor/client/views/account/preferences/PreferencesMessagesSection.tsx +++ b/apps/meteor/client/views/account/preferences/PreferencesMessagesSection.tsx @@ -1,5 +1,5 @@ import type { SelectOption } from '@rocket.chat/fuselage'; -import { FieldRow, FieldLink, FieldHint, FieldLabel, Accordion, Field, Select, FieldGroup, ToggleSwitch, Box } from '@rocket.chat/fuselage'; +import { FieldRow, FieldLink, FieldHint, FieldLabel, Accordion, Field, Select, FieldGroup, ToggleSwitch } from '@rocket.chat/fuselage'; import { useUniqueId } from '@rocket.chat/fuselage-hooks'; import { useTranslation } from '@rocket.chat/ui-contexts'; import React, { useMemo } from 'react'; @@ -43,38 +43,34 @@ const PreferencesMessagesSection = () => { - + {t('Unread_Tray_Icon_Alert')} - - ( - - )} - /> - - + ( + + )} + /> + - + {t('Always_show_thread_replies_in_main_channel')} - - ( - - )} - /> - - + ( + + )} + /> + {t('Accounts_Default_User_Preferences_showThreadsInMainChannel_Description')} @@ -105,74 +101,64 @@ const PreferencesMessagesSection = () => { {t('Go_to_accessibility_and_appearance')} - + {t('Use_Emojis')} - - ( - - )} - /> - - + ( + + )} + /> + - + {t('Convert_Ascii_Emojis')} - - ( - - )} - /> - - + ( + + )} + /> + - + {t('Auto_Load_Images')} - - ( - - )} - /> - - + ( + + )} + /> + - + {t('Save_Mobile_Bandwidth')} - - ( - - )} - /> - - + ( + + )} + /> + - + {t('Collapse_Embedded_Media_By_Default')} - - ( - - )} - /> - - + ( + + )} + /> + {t('Hide_usernames')} @@ -183,32 +169,28 @@ const PreferencesMessagesSection = () => { {t('Go_to_accessibility_and_appearance')} - + {t('Hide_flextab')} - - ( - - )} - /> - - + ( + + )} + /> + - + {t('Display_avatars')} - - ( - - )} - /> - - + ( + + )} + /> + {t('Enter_Behaviour')} diff --git a/apps/meteor/client/views/account/preferences/PreferencesNotificationsSection.tsx b/apps/meteor/client/views/account/preferences/PreferencesNotificationsSection.tsx index 1dfcdf917c2d..ddac7fda145b 100644 --- a/apps/meteor/client/views/account/preferences/PreferencesNotificationsSection.tsx +++ b/apps/meteor/client/views/account/preferences/PreferencesNotificationsSection.tsx @@ -1,6 +1,6 @@ import type { INotificationDesktop } from '@rocket.chat/core-typings'; import type { SelectOption } from '@rocket.chat/fuselage'; -import { Accordion, Field, FieldLabel, FieldRow, FieldHint, Select, FieldGroup, ToggleSwitch, Button, Box } from '@rocket.chat/fuselage'; +import { Accordion, Field, FieldLabel, FieldRow, FieldHint, Select, FieldGroup, ToggleSwitch, Button } from '@rocket.chat/fuselage'; import { useUniqueId } from '@rocket.chat/fuselage-hooks'; import type { TranslationKey } from '@rocket.chat/ui-contexts'; import { useUserPreference, useSetting, useTranslation } from '@rocket.chat/ui-contexts'; @@ -113,24 +113,22 @@ const PreferencesNotificationsSection = () => { - + {t('Notification_RequireInteraction')} - - ( - - )} - /> - - + ( + + )} + /> + {t('Only_works_with_chrome_version_greater_50')} @@ -182,57 +180,51 @@ const PreferencesNotificationsSection = () => { {showNewLoginEmailPreference && ( - + {t('Receive_Login_Detection_Emails')} - - ( - - )} - /> - - + ( + + )} + /> + {t('Receive_Login_Detection_Emails_Description')} )} {showCalendarPreference && ( - + {t('Notify_Calendar_Events')} - - ( - - )} - /> - - + ( + + )} + /> + )} {showMobileRinging && ( - + {t('VideoConf_Mobile_Ringing')} - - ( - - )} - /> - - + ( + + )} + /> + )} diff --git a/apps/meteor/client/views/account/preferences/PreferencesSoundSection.tsx b/apps/meteor/client/views/account/preferences/PreferencesSoundSection.tsx index 223d67fd7f95..8306e2941b00 100644 --- a/apps/meteor/client/views/account/preferences/PreferencesSoundSection.tsx +++ b/apps/meteor/client/views/account/preferences/PreferencesSoundSection.tsx @@ -62,9 +62,9 @@ const PreferencesSoundSection = () => { /> - - {t('Mute_Focused_Conversations')} + + {t('Mute_Focused_Conversations')} { - + {t('Enable_Auto_Away')} - - ( - - )} - /> - - + ( + + )} + /> + {t('Idle_Time_Limit')} diff --git a/apps/meteor/client/views/account/tokens/AccountTokensTable/AddToken.tsx b/apps/meteor/client/views/account/tokens/AccountTokensTable/AddToken.tsx index 97d2a8163cab..71fd2933f431 100644 --- a/apps/meteor/client/views/account/tokens/AccountTokensTable/AddToken.tsx +++ b/apps/meteor/client/views/account/tokens/AccountTokensTable/AddToken.tsx @@ -1,33 +1,41 @@ -import { Box, TextInput, Button, Field, FieldGroup, FieldLabel, FieldRow, Margins, CheckBox } from '@rocket.chat/fuselage'; -import { useUniqueId } from '@rocket.chat/fuselage-hooks'; +import type { SelectOption } from '@rocket.chat/fuselage'; +import { Box, TextInput, Button, Margins, Select } from '@rocket.chat/fuselage'; import { useSetModal, useToastMessageDispatch, useUserId, useMethod, useTranslation } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import React, { useCallback, useMemo, useEffect } from 'react'; -import { useForm } from 'react-hook-form'; +import { Controller, useForm } from 'react-hook-form'; import GenericModal from '../../../../components/GenericModal'; -const AddToken = ({ reload, ...props }: { reload: () => void }): ReactElement => { +const AddToken = ({ reload }: { reload: () => void }): ReactElement => { const t = useTranslation(); const userId = useUserId(); + const setModal = useSetModal(); const createTokenFn = useMethod('personalAccessTokens:generateToken'); const dispatchToastMessage = useToastMessageDispatch(); - const bypassTwoFactorCheckboxId = useUniqueId(); - const setModal = useSetModal(); - const initialValues = useMemo(() => ({ name: '', bypassTwoFactor: false }), []); + const initialValues = useMemo(() => ({ name: '', bypassTwoFactor: 'require' }), []); const { register, resetField, handleSubmit, - formState: { isDirty, isSubmitted, submitCount }, + control, + formState: { isSubmitted, submitCount }, } = useForm({ defaultValues: initialValues }); + const twoFactorAuthOptions: SelectOption[] = useMemo( + () => [ + ['require', t('Require_Two_Factor_Authentication')], + ['bypass', t('Ignore_Two_Factor_Authentication')], + ], + [t], + ); + const handleAddToken = useCallback( - async ({ name: tokenName, bypassTwoFactor }: typeof initialValues) => { + async ({ name: tokenName, bypassTwoFactor }) => { try { - const token = await createTokenFn({ tokenName, bypassTwoFactor }); + const token = await createTokenFn({ tokenName, bypassTwoFactor: bypassTwoFactor === 'bypass' }); setModal( setModal(null)} onClose={() => setModal(null)}> @@ -54,22 +62,23 @@ const AddToken = ({ reload, ...props }: { reload: () => void }): ReactElement => }, [isSubmitted, submitCount, reload, resetField]); return ( - - - - - - - - - - - {t('Ignore_Two_Factor_Authentication')} - - - + + + + + +