From e762e8e1911f25749cabf555a6c93819513397f8 Mon Sep 17 00:00:00 2001 From: Aleksander Nicacio da Silva Date: Tue, 10 Oct 2023 10:48:16 -0300 Subject: [PATCH] chore: changing from setting to user preference --- .../omnichannel/useOmnichannelCloseRoute.ts | 4 +-- .../OmnichannelPreferencesPage.tsx | 5 +++- .../omnichannel/PreferencesGeneral.tsx | 26 +++++++++++++++++++ .../rocketchat-i18n/i18n/en.i18n.json | 1 + .../rocketchat-i18n/i18n/pt-BR.i18n.json | 2 ++ .../server/methods/saveUserPreferences.ts | 1 + apps/meteor/server/settings/omnichannel.ts | 8 ------ .../v1/users/UsersSetPreferenceParamsPOST.ts | 5 ++++ 8 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx diff --git a/apps/meteor/client/hooks/omnichannel/useOmnichannelCloseRoute.ts b/apps/meteor/client/hooks/omnichannel/useOmnichannelCloseRoute.ts index 4246b1e6b7a8..746a62bd87e6 100644 --- a/apps/meteor/client/hooks/omnichannel/useOmnichannelCloseRoute.ts +++ b/apps/meteor/client/hooks/omnichannel/useOmnichannelCloseRoute.ts @@ -1,8 +1,8 @@ -import { useRouter, useSetting } from '@rocket.chat/ui-contexts'; +import { useRouter, useUserPreference } from '@rocket.chat/ui-contexts'; import { useCallback } from 'react'; export const useOmnichannelCloseRoute = () => { - const hideConversationAfterClosing = useSetting('Omnichannel_hide_conversation_after_closing'); + const hideConversationAfterClosing = useUserPreference('omnichannelHideConversationAfterClosing') ?? true; const router = useRouter(); const navigateHome = useCallback(() => { diff --git a/apps/meteor/client/views/account/omnichannel/OmnichannelPreferencesPage.tsx b/apps/meteor/client/views/account/omnichannel/OmnichannelPreferencesPage.tsx index 515446a154f6..d448a180f834 100644 --- a/apps/meteor/client/views/account/omnichannel/OmnichannelPreferencesPage.tsx +++ b/apps/meteor/client/views/account/omnichannel/OmnichannelPreferencesPage.tsx @@ -6,6 +6,7 @@ import { useForm, FormProvider } from 'react-hook-form'; import Page from '../../../components/Page'; import PreferencesConversationTranscript from './PreferencesConversationTranscript'; +import { PreferencesGeneral } from './PreferencesGeneral'; type FormData = { omnichannelTranscriptPDF: boolean; @@ -18,9 +19,10 @@ const OmnichannelPreferencesPage = (): ReactElement => { const omnichannelTranscriptPDF = useUserPreference('omnichannelTranscriptPDF') ?? false; const omnichannelTranscriptEmail = useUserPreference('omnichannelTranscriptEmail') ?? false; + const omnichannelHideConversationAfterClosing = useUserPreference('omnichannelHideConversationAfterClosing') ?? true; const methods = useForm({ - defaultValues: { omnichannelTranscriptPDF, omnichannelTranscriptEmail }, + defaultValues: { omnichannelTranscriptPDF, omnichannelTranscriptEmail, omnichannelHideConversationAfterClosing }, }); const { @@ -48,6 +50,7 @@ const OmnichannelPreferencesPage = (): ReactElement => { + diff --git a/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx b/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx new file mode 100644 index 000000000000..3c7b8fab9d64 --- /dev/null +++ b/apps/meteor/client/views/account/omnichannel/PreferencesGeneral.tsx @@ -0,0 +1,26 @@ +import { Box, 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'; +import React from 'react'; +import { useFormContext } from 'react-hook-form'; + +export const PreferencesGeneral = (): ReactElement => { + const t = useTranslation(); + const { register } = useFormContext(); + const omnichannelHideAfterClosing = useUniqueId(); + + return ( + + + + {t('Omnichannel_hide_conversation_after_closing')} + + + + + {t('Omnichannel_hide_conversation_after_closing_description')} + + + ); +}; diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 3f1b6692820d..40bbcf4c3176 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -3108,6 +3108,7 @@ "Livechat_online": "Omnichannel on-line", "Omnichannel_placed_chat_on_hold": "Chat On Hold: {{comment}}", "Omnichannel_hide_conversation_after_closing": "Hide conversation after closing", + "Omnichannel_hide_conversation_after_closing_description": "After closing the conversation you will be redirected to Home.", "Livechat_Queue": "Omnichannel Queue", "Livechat_registration_form": "Registration Form", "Livechat_registration_form_message": "Registration Form Message", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index 80d17019855c..22bf14dd0524 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -2673,6 +2673,8 @@ "Omnichannel_sorting_disclaimer": "Conversar do Omnichannel são ordenadas por {{sortingMechanism}}, edite a sala para alterar.", "Livechat_online": "Omnichannel online", "Omnichannel_placed_chat_on_hold": "Conversa em espera: {{comment}}", + "Omnichannel_hide_conversation_after_closing": "Ocultar conversa após fechar", + "Omnichannel_hide_conversation_after_closing_description": "Após encerrar a conversa, você será redirecionado para a página inicial.", "Livechat_Queue": "Fila omnichannel", "Livechat_registration_form": "Formulário de registro", "Livechat_registration_form_message": "Mensagem do formulário de registro", diff --git a/apps/meteor/server/methods/saveUserPreferences.ts b/apps/meteor/server/methods/saveUserPreferences.ts index 71abe7bea3b1..814627a745bc 100644 --- a/apps/meteor/server/methods/saveUserPreferences.ts +++ b/apps/meteor/server/methods/saveUserPreferences.ts @@ -86,6 +86,7 @@ export const saveUserPreferences = async (settings: Partial, us fontSize: Match.Optional(String), omnichannelTranscriptEmail: Match.Optional(Boolean), omnichannelTranscriptPDF: Match.Optional(Boolean), + omnichannelHideConversationAfterClosing: Match.Optional(Boolean), notifyCalendarEvents: Match.Optional(Boolean), enableMobileRinging: Match.Optional(Boolean), mentionsWithSymbol: Match.Optional(Boolean), diff --git a/apps/meteor/server/settings/omnichannel.ts b/apps/meteor/server/settings/omnichannel.ts index ab3d093d1189..cc9da5474862 100644 --- a/apps/meteor/server/settings/omnichannel.ts +++ b/apps/meteor/server/settings/omnichannel.ts @@ -429,14 +429,6 @@ export const createOmniSettings = () => enableQuery: omnichannelEnabledQuery, }); - await this.add('Omnichannel_hide_conversation_after_closing', true, { - type: 'boolean', - group: 'Omnichannel', - public: true, - i18nLabel: 'Omnichannel_hide_conversation_after_closing', - enableQuery: omnichannelEnabledQuery, - }); - await this.add('Livechat_registration_form_message', '', { type: 'string', group: 'Omnichannel', diff --git a/packages/rest-typings/src/v1/users/UsersSetPreferenceParamsPOST.ts b/packages/rest-typings/src/v1/users/UsersSetPreferenceParamsPOST.ts index bb32dc27fb04..1c89fdc04d5d 100644 --- a/packages/rest-typings/src/v1/users/UsersSetPreferenceParamsPOST.ts +++ b/packages/rest-typings/src/v1/users/UsersSetPreferenceParamsPOST.ts @@ -49,6 +49,7 @@ export type UsersSetPreferencesParamsPOST = { idleTimeLimit?: number; omnichannelTranscriptEmail?: boolean; omnichannelTranscriptPDF?: boolean; + omnichannelHideConversationAfterClosing?: boolean; enableMobileRinging?: boolean; mentionsWithSymbol?: boolean; }; @@ -242,6 +243,10 @@ const UsersSetPreferencesParamsPostSchema = { type: 'boolean', nullable: true, }, + omnichannelHideConversationAfterClosing: { + type: 'boolean', + nullable: true, + }, enableMobileRinging: { type: 'boolean', nullable: true,