Skip to content

Commit

Permalink
Add toast messages
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Sep 14, 2023
1 parent 7d2c64c commit 95f0cbc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/meteor/client/hooks/roomActions/useE2EERoomAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import { e2e } from '../../../app/e2e/client/rocketchat.e2e';
import { useRoom } from '../../views/room/contexts/RoomContext';
import { dispatchToastMessage } from '../../lib/toast';
import { useRoom, useRoomSubscription } from '../../views/room/contexts/RoomContext';
import type { RoomToolboxActionConfig } from '../../views/room/contexts/RoomToolboxContext';
import { useReactiveValue } from '../useReactiveValue';

export const useE2EERoomAction = () => {
const enabled = useSetting('E2E_Enable', false);
const room = useRoom();
const subscription = useRoomSubscription();
const readyToEncrypt = useReactiveValue(useCallback(() => e2e.isReady(), [])) || room.encrypted;
const permittedToToggleEncryption = usePermission('toggle-room-e2e-encryption', room._id);
const permittedToEditRoom = usePermission('edit-room', room._id);
Expand All @@ -21,8 +23,20 @@ export const useE2EERoomAction = () => {

const toggleE2E = useEndpoint('POST', '/v1/rooms.saveRoomSettings');

const action = useMutableCallback(() => {
void toggleE2E({ rid: room._id, encrypted: !room.encrypted });
const action = useMutableCallback(async () => {
const { success } = await toggleE2E({ rid: room._id, encrypted: !room.encrypted });
if (!success) {
return;
}

dispatchToastMessage({
type: 'success',
message: t(room.encrypted ? 'E2E_Encryption_disabled_for_room' : 'E2E_Encryption_enabled_for_room', { roomName: room.name }),
});

if (subscription?.autoTranslate) {
dispatchToastMessage({ type: 'success', message: t('AutoTranslate_Disabled_for_room', { roomName: room.name }) });
}
});

const enabledOnRoom = !!room.encrypted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useLanguage } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useMemo, useEffect, useState, memo } from 'react';
import { useTranslation } from 'react-i18next';

import { useEndpointAction } from '../../../../hooks/useEndpointAction';
import { useEndpointData } from '../../../../hooks/useEndpointData';
import { dispatchToastMessage } from '../../../../lib/toast';
import { useRoom, useRoomSubscription } from '../../contexts/RoomContext';
import { useRoomToolbox } from '../../contexts/RoomToolboxContext';
import AutoTranslate from './AutoTranslate';
Expand All @@ -16,10 +18,12 @@ const AutoTranslateWithData = (): ReactElement => {
const userLanguage = useLanguage();
const [currentLanguage, setCurrentLanguage] = useState(subscription?.autoTranslateLanguage ?? '');
const saveSettings = useEndpointAction('POST', '/v1/autotranslate.saveSettings');
const { t } = useTranslation();

const { value: translateData } = useEndpointData('/v1/autotranslate.getSupportedLanguages', {
params: useMemo(() => ({ targetLanguage: userLanguage }), [userLanguage]),
});
const languagesDict = translateData ? Object.fromEntries(translateData.languages.map((lang) => [lang.language, lang.name])) : {};

const handleChangeLanguage = useMutableCallback((value) => {
setCurrentLanguage(value);
Expand All @@ -29,6 +33,10 @@ const AutoTranslateWithData = (): ReactElement => {
field: 'autoTranslateLanguage',
value,
});
dispatchToastMessage({
type: 'success',
message: t('AutoTranslate_to_language_enabled_for_room', { language: languagesDict[value], roomName: room.name }),
});
});

const handleSwitch = useMutableCallback((event) => {
Expand All @@ -37,6 +45,13 @@ const AutoTranslateWithData = (): ReactElement => {
field: 'autoTranslate',
value: event.target.checked,
});
dispatchToastMessage({
type: 'success',
message: t(event.target.checked ? 'AutoTranslate_to_language_enabled_for_room' : 'AutoTranslate_Disabled_for_room', {
language: languagesDict[currentLanguage],
roomName: room.name,
}),
});
});

useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,14 @@
"AutoTranslate_APIKey": "API Key",
"AutoTranslate_Change_Language_Description": "Changing the auto-translate language does not translate previous messages.",
"AutoTranslate_DeepL": "DeepL",
"AutoTranslate_Disabled_for_room": "Auto-translate disabled for #{{roomName}}",
"AutoTranslate_Enabled": "Enable Auto-Translate",
"AutoTranslate_Enabled_Description": "Enabling auto-translation will allow people with the `auto-translate` permission to have all messages automatically translated into their selected language. Fees may apply.",
"AutoTranslate_Google": "Google",
"AutoTranslate_Microsoft": "Microsoft",
"AutoTranslate_Microsoft_API_Key": "Ocp-Apim-Subscription-Key",
"AutoTranslate_ServiceProvider": "Service Provider",
"AutoTranslate_to_language_enabled_for_room": "Auto-translate to {{language}} enabled for #{{roomName}}",
"Available": "Available",
"Available_agents": "Available agents",
"Available_departments": "Available Departments",
Expand Down Expand Up @@ -1727,6 +1729,8 @@
"Markdown_Marked_Tables": "Enable Marked Tables",
"duplicated-account": "Duplicated account",
"E2E Encryption": "E2E Encryption",
"E2E_Encryption_enabled_for_room": "End-to-end encryption enabled for #{{roomName}}",
"E2E_Encryption_disabled_for_room": "End-to-end encryption disabled for #{{roomName}}",
"Markdown_Parser": "Markdown Parser",
"Markdown_SupportSchemesForLink": "Markdown Support Schemes for Link",
"E2E Encryption_Description": "Keep conversations private, ensuring only the sender and intended recipients are able to read them.",
Expand Down
3 changes: 3 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 @@ -633,12 +633,14 @@
"AutoTranslate_APIKey": "Key da API",
"AutoTranslate_Change_Language_Description": "Alterar o idioma de tradução automática não traduz mensagens anteriores.",
"AutoTranslate_DeepL": "DeepL",
"AutoTranslate_Disabled_for_room": "Tradução automática desabilitada para #{{roomName}}",
"AutoTranslate_Enabled": "Habilitar tradução automática",
"AutoTranslate_Enabled_Description": "Habilitar a tradução automática implicará em permitir que as pessoas com a permissão `auto-translate` tenham todas as suas mensagens automaticamente traduzidas para seu idioma. Taxas podem ser cobradas.",
"AutoTranslate_Google": "Google",
"AutoTranslate_Microsoft": "Microsoft",
"AutoTranslate_Microsoft_API_Key": "Ocp-Apim-Subscription-Key",
"AutoTranslate_ServiceProvider": "Provedor de serviço",
"AutoTranslate_to_language_enabled_for_room": "Tradução automática para {{language}} habilitada para #{{roomName}}",
"Available": "Disponível",
"Available_agents": "Agentes disponíveis",
"Available_departments": "Departamentos disponíveis",
Expand Down Expand Up @@ -1517,6 +1519,7 @@
"Markdown_Marked_Tables": "Ativar tabelas marcadas",
"duplicated-account": "Conta duplicada",
"E2E Encryption": "Criptografia E2E",
"E2E_Encryption_enabled_for_room": "Criptografia E2E habilitada para #{{roomName}}",
"Markdown_Parser": "Parser de marcação",
"Markdown_SupportSchemesForLink": "Esquemas de links compatíveis com marcação",
"Markdown_SupportSchemesForLink_Description": "Lista de esquemas permitidos separados por vírgulas",
Expand Down

0 comments on commit 95f0cbc

Please sign in to comment.