Skip to content

Commit

Permalink
feat: Added new setting 'Hide conversation after closing' (#30591)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Oct 24, 2023
1 parent 6a5ec53 commit 7429d15
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-spoons-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Added new Omnichannel setting 'Hide conversation after closing'
23 changes: 23 additions & 0 deletions apps/meteor/client/hooks/omnichannel/useOmnichannelCloseRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useRouter, useUserPreference } from '@rocket.chat/ui-contexts';
import { useCallback } from 'react';

export const useOmnichannelCloseRoute = () => {
const hideConversationAfterClosing = useUserPreference<boolean>('omnichannelHideConversationAfterClosing') ?? true;
const router = useRouter();

const navigateHome = useCallback(() => {
if (!hideConversationAfterClosing) {
return;
}

const routeName = router.getRouteName();

if (routeName === 'omnichannel-current-chats') {
router.navigate({ name: 'omnichannel-current-chats' });
} else {
router.navigate({ name: 'home' });
}
}, [hideConversationAfterClosing, router]);

return { navigateHome };
};
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' paddingInline='0.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>
);
};
37 changes: 27 additions & 10 deletions apps/meteor/client/views/room/body/hooks/useGoToHomeOnRemoved.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { isOmnichannelRoom, type IRoom } from '@rocket.chat/core-typings';
import { useRoute, useStream, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';

const IGNORED_ROOMS = ['l', 'v'];
import { useOmnichannelCloseRoute } from '../../../../hooks/omnichannel/useOmnichannelCloseRoute';

export function useGoToHomeOnRemoved(room: IRoom, userId: string | undefined): void {
const homeRouter = useRoute('home');
const queryClient = useQueryClient();
const dispatchToastMessage = useToastMessageDispatch();
const subscribeToNotifyUser = useStream('notify-user');
const t = useTranslation();
const { navigateHome } = useOmnichannelCloseRoute();

useEffect(() => {
if (!userId) {
Expand All @@ -21,19 +22,35 @@ export function useGoToHomeOnRemoved(room: IRoom, userId: string | undefined): v
if (event === 'removed' && subscription.rid === room._id) {
queryClient.invalidateQueries(['rooms', room._id]);

if (!IGNORED_ROOMS.includes(room.t)) {
dispatchToastMessage({
type: 'info',
message: t('You_have_been_removed_from__roomName_', {
roomName: room?.fname || room?.name || '',
}),
});
if (isOmnichannelRoom(room)) {
navigateHome();
return;
}

dispatchToastMessage({
type: 'info',
message: t('You_have_been_removed_from__roomName_', {
roomName: room?.fname || room?.name || '',
}),
});

homeRouter.push({});
}
});

return unSubscribeFromNotifyUser;
}, [userId, homeRouter, subscribeToNotifyUser, room._id, room?.fname, room?.name, t, dispatchToastMessage, queryClient, room.t]);
}, [
userId,
homeRouter,
subscribeToNotifyUser,
room._id,
room?.fname,
room?.name,
t,
dispatchToastMessage,
queryClient,
room.t,
room,
navigateHome,
]);
}
2 changes: 2 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,8 @@
"Omnichannel_sorting_disclaimer": "Omnichannel conversations are sorted by {{sortingMechanism}}, edit a room to apply.",
"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
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 7429d15

Please sign in to comment.