Skip to content

Commit

Permalink
chore: changing from setting to user preference
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Oct 10, 2023
1 parent eece364 commit e762e8e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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<boolean>('omnichannelHideConversationAfterClosing') ?? true;
const router = useRouter();

const navigateHome = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,9 +19,10 @@ const OmnichannelPreferencesPage = (): ReactElement => {

const omnichannelTranscriptPDF = useUserPreference<boolean>('omnichannelTranscriptPDF') ?? false;
const omnichannelTranscriptEmail = useUserPreference<boolean>('omnichannelTranscriptEmail') ?? false;
const omnichannelHideConversationAfterClosing = useUserPreference<boolean>('omnichannelHideConversationAfterClosing') ?? true;

const methods = useForm({
defaultValues: { omnichannelTranscriptPDF, omnichannelTranscriptEmail },
defaultValues: { omnichannelTranscriptPDF, omnichannelTranscriptEmail, omnichannelHideConversationAfterClosing },
});

const {
Expand Down Expand Up @@ -48,6 +50,7 @@ const OmnichannelPreferencesPage = (): ReactElement => {
<Box maxWidth='x600' w='full' alignSelf='center'>
<Accordion>
<FormProvider {...methods}>
<PreferencesGeneral />
<PreferencesConversationTranscript />
</FormProvider>
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<FieldGroup marginBlockEnd='1.5rem'>
<Field>
<Box display='flex' alignItems='center' flexDirection='row' justifyContent='spaceBetween' flexGrow={1}>
<FieldLabel htmlFor={omnichannelHideAfterClosing}>{t('Omnichannel_hide_conversation_after_closing')}</FieldLabel>
<FieldRow>
<ToggleSwitch id={omnichannelHideAfterClosing} {...register('omnichannelHideConversationAfterClosing')} />
</FieldRow>
</Box>
<FieldHint>{t('Omnichannel_hide_conversation_after_closing_description')}</FieldHint>
</Field>
</FieldGroup>
);
};
1 change: 1 addition & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/server/methods/saveUserPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const saveUserPreferences = async (settings: Partial<UserPreferences>, 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),
Expand Down
8 changes: 0 additions & 8 deletions apps/meteor/server/settings/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type UsersSetPreferencesParamsPOST = {
idleTimeLimit?: number;
omnichannelTranscriptEmail?: boolean;
omnichannelTranscriptPDF?: boolean;
omnichannelHideConversationAfterClosing?: boolean;
enableMobileRinging?: boolean;
mentionsWithSymbol?: boolean;
};
Expand Down Expand Up @@ -242,6 +243,10 @@ const UsersSetPreferencesParamsPostSchema = {
type: 'boolean',
nullable: true,
},
omnichannelHideConversationAfterClosing: {
type: 'boolean',
nullable: true,
},
enableMobileRinging: {
type: 'boolean',
nullable: true,
Expand Down

0 comments on commit e762e8e

Please sign in to comment.