Files
jitsi-meet/react/features/notifications/actions.js
virtuacoplenny 510334fa7f ref(notifications): convert some dialogs to error or warning notifica… (#1991)
* ref(notifications): convert some dialogs to error or warning notifications

- Expand the configurability of the Notification component so warnings
  and errors can be displayed.
- Allow Notification to take in arbitrary text for the body.
- Rename defaultTitleKey to titleKey for consistency with descriptionKey.

* ref(notifications): remove openReportDialog method

openReportDialog is a wrapper around showError that adds
a logger statement. It is being called in one place only
so remove the method and have that one place call logger.

* ref(notifications): UI.showTrackNotWorkingDialog takes a boolean

Change UI.showTrackNotWorkingDialog so it takes a boolean
arguments instead of the entire track. A small refactor so
the method needs to know less.

* [squash] Fixes eslint errors

* WiP: Fixes desktop sharing error strings and adds support button

* [squash] Fix icons appearances

* [squash] Fix translate titles and messages

* [squash] fix(translation): Fixes incorrect password string

* [squash] fix(recording): Fixes recording message

* [squash] fix(warning): Turns some warnings to errors and makes support link optional.

* [squash] fix(translation): Addressing language comments

* [squash] Fixes jsdoc and formatting

* [squash] fix(noopener): Fixes window.open noopener

* [squash] fix(constants): Extract constants and refactor NotificationWithToggle

* [squash] fix(lang): Fixes camera and mic error titles

* [squash] fix(supportLink): Renames addSupportLink to hideErrorSupportLink
2017-11-03 14:05:03 -05:00

129 lines
3.2 KiB
JavaScript

import jitsiLocalStorage from '../../../modules/util/JitsiLocalStorage';
import {
HIDE_NOTIFICATION,
SET_NOTIFICATIONS_ENABLED,
SHOW_NOTIFICATION
} from './actionTypes';
import {
Notification,
NotificationWithToggle
} from './components';
import { NOTIFICATION_TYPE } from './constants';
/**
* Removes the notification with the passed in id.
*
* @param {string} uid - The unique identifier for the notification to be
* removed.
* @returns {{
* type: HIDE_NOTIFICATION,
* uid: number
* }}
*/
export function hideNotification(uid) {
return {
type: HIDE_NOTIFICATION,
uid
};
}
/**
* Stops notifications from being displayed.
*
* @param {boolean} enabled - Whether or not notifications should display.
* @returns {{
* type: SET_NOTIFICATIONS_ENABLED,
* enabled: boolean
* }}
*/
export function setNotificationsEnabled(enabled) {
return {
type: SET_NOTIFICATIONS_ENABLED,
enabled
};
}
/**
* Queues an error notification for display.
*
* @param {Object} props - The props needed to show the notification component.
* @returns {Object}
*/
export function showErrorNotification(props) {
return showNotification(Notification, {
...props,
appearance: NOTIFICATION_TYPE.ERROR
});
}
/**
* Queues a notification for display.
*
* @param {ReactComponent} component - The notification component to be
* displayed.
* @param {Object} props - The props needed to show the notification component.
* @param {number} timeout - How long the notification should display before
* automatically being hidden.
* @returns {{
* type: SHOW_NOTIFICATION,
* component: ReactComponent,
* props: Object,
* timeout: number,
* uid: number
* }}
*/
export function showNotification(component, props = {}, timeout) {
return {
type: SHOW_NOTIFICATION,
component,
props,
timeout,
uid: window.Date.now()
};
}
/**
* Queues a warning notification for display.
*
* @param {Object} props - The props needed to show the notification component.
* @returns {Object}
*/
export function showWarningNotification(props) {
return showNotification(Notification, {
...props,
appearance: NOTIFICATION_TYPE.WARNING
});
}
/**
* Displays a notification unless the passed in persistenceKey value exists in
* local storage and has been set to "true".
*
* @param {string} persistenceKey - The local storage key to look up for whether
* or not the notification should display.
* @param {Object} props - The props needed to show the notification component.
* @returns {Function}
*/
export function maybeShowNotificationWithDoNotDisplay(persistenceKey, props) {
return dispatch => {
if (jitsiLocalStorage.getItem(persistenceKey) === 'true') {
return;
}
const newProps = Object.assign({}, props, {
onToggleSubmit: isToggled => {
jitsiLocalStorage.setItem(persistenceKey, isToggled);
}
});
dispatch({
type: SHOW_NOTIFICATION,
component: NotificationWithToggle,
props: newProps,
uid: window.Date.now()
});
};
}