// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useCallback, useMemo} from 'react'; import {useIntl} from 'react-intl'; import SettingContainer from '@components/settings/container'; import SettingItem from '@components/settings/item'; import {General, Screens} from '@constants'; import useAndroidHardwareBackHandler from '@hooks/android_back_handler'; import {t} from '@i18n'; import {popTopScreen} from '@screens/navigation'; import {gotoSettingsScreen} from '@screens/settings/config'; import {getEmailInterval, getEmailIntervalTexts, getNotificationProps} from '@utils/user'; import type UserModel from '@typings/database/models/servers/user'; import type {AvailableScreens} from '@typings/screens/navigation'; const mentionTexts = { crtOn: { id: t('notification_settings.mentions'), defaultMessage: 'Mentions', }, crtOff: { id: t('notification_settings.mentions_replies'), defaultMessage: 'Mentions and Replies', }, }; type NotificationsProps = { componentId: AvailableScreens; currentUser?: UserModel; emailInterval: string; enableAutoResponder: boolean; enableEmailBatching: boolean; isCRTEnabled: boolean; sendEmailNotifications: boolean; } const Notifications = ({ componentId, currentUser, emailInterval, enableAutoResponder, enableEmailBatching, isCRTEnabled, sendEmailNotifications, }: NotificationsProps) => { const intl = useIntl(); const notifyProps = useMemo(() => getNotificationProps(currentUser), [currentUser?.notifyProps]); const emailIntervalPref = useMemo(() => getEmailInterval( sendEmailNotifications && notifyProps?.email === 'true', enableEmailBatching, parseInt(emailInterval, 10), ).toString(), [emailInterval, enableEmailBatching, notifyProps, sendEmailNotifications]); const goToNotificationSettingsMentions = useCallback(() => { const screen = Screens.SETTINGS_NOTIFICATION_MENTION; const id = isCRTEnabled ? t('notification_settings.mentions') : t('notification_settings.mentions_replies'); const defaultMessage = isCRTEnabled ? 'Mentions' : 'Mentions and Replies'; const title = intl.formatMessage({id, defaultMessage}); gotoSettingsScreen(screen, title); }, [isCRTEnabled]); const goToNotificationSettingsPush = useCallback(() => { const screen = Screens.SETTINGS_NOTIFICATION_PUSH; const title = intl.formatMessage({ id: 'notification_settings.push_notification', defaultMessage: 'Push Notifications', }); gotoSettingsScreen(screen, title); }, []); const goToNotificationAutoResponder = useCallback(() => { const screen = Screens.SETTINGS_NOTIFICATION_AUTO_RESPONDER; const title = intl.formatMessage({ id: 'notification_settings.auto_responder', defaultMessage: 'Automatic Replies', }); gotoSettingsScreen(screen, title); }, []); const goToEmailSettings = useCallback(() => { const screen = Screens.SETTINGS_NOTIFICATION_EMAIL; const title = intl.formatMessage({id: 'notification_settings.email', defaultMessage: 'Email Notifications'}); gotoSettingsScreen(screen, title); }, []); useAndroidHardwareBackHandler(componentId, () => { popTopScreen(componentId); }); return ( {enableAutoResponder && ( )} ); }; export default Notifications;