[MM-60964] Update permissions banner button text and dismiss behaviour (#29134)

Этот коммит содержится в:
M-ZubairAhmed
2024-11-05 14:34:06 +00:00
коммит произвёл GitHub
родитель fbee99e870
Коммит 1b3403e641
8 изменённых файлов: 35 добавлений и 13 удалений

Просмотреть файл

@@ -254,6 +254,8 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr
DesktopApp.signalLogout(); DesktopApp.signalLogout();
} }
BrowserStore.clearHideNotificationPermissionRequestBanner();
WebsocketActions.close(); WebsocketActions.close();
clearUserCookie(); clearUserCookie();

Просмотреть файл

@@ -15,7 +15,7 @@ exports[`NotificationPermissionBar should render the NotificationPermissionNever
We need your permission to show notifications in the browser. We need your permission to show notifications in the browser.
</span> </span>
<button> <button>
Enable notifications Manage notification preferences
</button> </button>
</div> </div>
<a <a

Просмотреть файл

@@ -51,7 +51,7 @@ describe('NotificationPermissionBar', () => {
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
expect(screen.getByText('We need your permission to show notifications in the browser.')).toBeInTheDocument(); expect(screen.getByText('We need your permission to show notifications in the browser.')).toBeInTheDocument();
expect(screen.getByText('Enable notifications')).toBeInTheDocument(); expect(screen.getByText('Manage notification preferences')).toBeInTheDocument();
}); });
test('should call requestNotificationPermission and hide the bar when the button is clicked in NotificationPermissionNeverGrantedBar', async () => { test('should call requestNotificationPermission and hide the bar when the button is clicked in NotificationPermissionNeverGrantedBar', async () => {
@@ -64,7 +64,7 @@ describe('NotificationPermissionBar', () => {
expect(screen.getByText('We need your permission to show notifications in the browser.')).toBeInTheDocument(); expect(screen.getByText('We need your permission to show notifications in the browser.')).toBeInTheDocument();
await waitFor(async () => { await waitFor(async () => {
userEvent.click(screen.getByText('Enable notifications')); userEvent.click(screen.getByText('Manage notification preferences'));
}); });
expect(utilsNotifications.requestNotificationPermission).toHaveBeenCalled(); expect(utilsNotifications.requestNotificationPermission).toHaveBeenCalled();

Просмотреть файл

@@ -4,13 +4,15 @@
import React, {useCallback, useState} from 'react'; import React, {useCallback, useState} from 'react';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import BrowserStore from 'stores/browser_store';
import AnnouncementBar from 'components/announcement_bar/default_announcement_bar'; import AnnouncementBar from 'components/announcement_bar/default_announcement_bar';
import {AnnouncementBarTypes} from 'utils/constants'; import {AnnouncementBarTypes} from 'utils/constants';
import {requestNotificationPermission} from 'utils/notifications'; import {requestNotificationPermission} from 'utils/notifications';
export default function NotificationPermissionNeverGrantedBar() { export default function NotificationPermissionNeverGrantedBar() {
const [show, setShow] = useState(true); const [show, setShow] = useState(!BrowserStore.getHideNotificationPermissionRequestBanner());
const handleClick = useCallback(async () => { const handleClick = useCallback(async () => {
try { try {
@@ -25,9 +27,10 @@ export default function NotificationPermissionNeverGrantedBar() {
}, []); }, []);
const handleClose = useCallback(() => { const handleClose = useCallback(() => {
// If the user closes the bar, don't show the notification bar any more for the rest of the session, but
// show it again on app refresh.
setShow(false); setShow(false);
// Close the bar and don't show it again for the rest of the session.
BrowserStore.setHideNotificationPermissionRequestBanner();
}, []); }, []);
if (!show) { if (!show) {
@@ -36,8 +39,6 @@ export default function NotificationPermissionNeverGrantedBar() {
return ( return (
<AnnouncementBar <AnnouncementBar
showCloseButton={true}
handleClose={handleClose}
type={AnnouncementBarTypes.ANNOUNCEMENT} type={AnnouncementBarTypes.ANNOUNCEMENT}
message={ message={
<FormattedMessage <FormattedMessage
@@ -48,12 +49,14 @@ export default function NotificationPermissionNeverGrantedBar() {
ctaText={ ctaText={
<FormattedMessage <FormattedMessage
id='announcementBar.notification.permissionNeverGrantedBar.cta' id='announcementBar.notification.permissionNeverGrantedBar.cta'
defaultMessage='Enable notifications' defaultMessage='Manage notification preferences'
/> />
} }
showCTA={true} showCTA={true}
showLinkAsButton={true} showLinkAsButton={true}
onButtonClick={handleClick} onButtonClick={handleClick}
showCloseButton={true}
handleClose={handleClose}
/> />
); );
} }

Просмотреть файл

@@ -4,21 +4,24 @@
import React, {useCallback, useState} from 'react'; import React, {useCallback, useState} from 'react';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import BrowserStore from 'stores/browser_store';
import AnnouncementBar from 'components/announcement_bar/default_announcement_bar'; import AnnouncementBar from 'components/announcement_bar/default_announcement_bar';
import {AnnouncementBarTypes} from 'utils/constants'; import {AnnouncementBarTypes} from 'utils/constants';
export default function UnsupportedNotificationAnnouncementBar() { export default function UnsupportedNotificationAnnouncementBar() {
const [show, setShow] = useState(true); const [show, setShow] = useState(!BrowserStore.getHideNotificationPermissionRequestBanner());
const handleClick = useCallback(async () => { const handleClick = useCallback(async () => {
window.open('https://mattermost.com/pl/pc-web-requirements', '_blank', 'noopener,noreferrer'); window.open('https://mattermost.com/pl/pc-web-requirements', '_blank', 'noopener,noreferrer');
}, []); }, []);
const handleClose = useCallback(() => { const handleClose = useCallback(() => {
// If the user closes the bar, don't show the notification bar any more for the rest of the session, but
// show it again on app refresh.
setShow(false); setShow(false);
// Close the bar and don't show it again for the rest of the session.
BrowserStore.setHideNotificationPermissionRequestBanner();
}, []); }, []);
if (!show) { if (!show) {

Просмотреть файл

@@ -2898,7 +2898,7 @@
"announcement_bar.warn.contact_support_text": "To renew your license, contact support at support@mattermost.com.", "announcement_bar.warn.contact_support_text": "To renew your license, contact support at support@mattermost.com.",
"announcement_bar.warn.no_internet_connection": "Looks like you do not have access to the internet.", "announcement_bar.warn.no_internet_connection": "Looks like you do not have access to the internet.",
"announcement_bar.warn.renew_license_contact_sales": "Contact sales", "announcement_bar.warn.renew_license_contact_sales": "Contact sales",
"announcementBar.notification.permissionNeverGrantedBar.cta": "Enable notifications", "announcementBar.notification.permissionNeverGrantedBar.cta": "Manage notification preferences",
"announcementBar.notification.permissionNeverGrantedBar.message": "We need your permission to show notifications in the browser.", "announcementBar.notification.permissionNeverGrantedBar.message": "We need your permission to show notifications in the browser.",
"announcementBar.notification.unsupportedBar.cta": "Update your browser", "announcementBar.notification.unsupportedBar.cta": "Update your browser",
"announcementBar.notification.unsupportedBar.message": "Your browser does not support browser notifications.", "announcementBar.notification.unsupportedBar.message": "Your browser does not support browser notifications.",

Просмотреть файл

@@ -95,7 +95,20 @@ class BrowserStoreClass {
clearLandingPreference(siteUrl?: string) { clearLandingPreference(siteUrl?: string) {
localStorage.removeItem(StoragePrefixes.LANDING_PREFERENCE + String(siteUrl)); localStorage.removeItem(StoragePrefixes.LANDING_PREFERENCE + String(siteUrl));
} }
getHideNotificationPermissionRequestBanner() {
return localStorage.getItem(StoragePrefixes.HIDE_NOTIFICATION_PERMISSION_REQUEST_BANNER) === 'true';
}
setHideNotificationPermissionRequestBanner() {
localStorage.setItem(StoragePrefixes.HIDE_NOTIFICATION_PERMISSION_REQUEST_BANNER, 'true');
}
clearHideNotificationPermissionRequestBanner() {
localStorage.removeItem(StoragePrefixes.HIDE_NOTIFICATION_PERMISSION_REQUEST_BANNER);
}
} }
const BrowserStore = new BrowserStoreClass(); const BrowserStore = new BrowserStoreClass();
export default BrowserStore; export default BrowserStore;

Просмотреть файл

@@ -876,6 +876,7 @@ export const StoragePrefixes = {
INLINE_IMAGE_VISIBLE: 'isInlineImageVisible_', INLINE_IMAGE_VISIBLE: 'isInlineImageVisible_',
DELINQUENCY: 'delinquency_', DELINQUENCY: 'delinquency_',
HIDE_JOINED_CHANNELS: 'hideJoinedChannels', HIDE_JOINED_CHANNELS: 'hideJoinedChannels',
HIDE_NOTIFICATION_PERMISSION_REQUEST_BANNER: 'hideNotificationPermissionRequestBanner',
}; };
export const LandingPreferenceTypes = { export const LandingPreferenceTypes = {