Commit ef82e4c0 authored by Tom Quirk's avatar Tom Quirk

Address maintainer feedback

- check localStorage is available before persisting/retrieving alert
- remove unnecessary async call
parent d0500d6a
import AccessorUtilities from '~/lib/utils/accessor';
import { ALERT_LOCALSTORAGE_KEY } from './constants';
/**
* Persist alert data to localStorage.
*/
export const persistAlert = ({ title, message, linkUrl, variant } = {}) => {
if (!AccessorUtilities.isLocalStorageAccessSafe()) {
return;
}
const payload = JSON.stringify({ title, message, linkUrl, variant });
localStorage.setItem(ALERT_LOCALSTORAGE_KEY, payload);
};
......@@ -12,9 +17,13 @@ export const persistAlert = ({ title, message, linkUrl, variant } = {}) => {
* Return alert data from localStorage.
*/
export const retrieveAlert = () => {
const initialAlertJSON = window.localStorage.getItem(ALERT_LOCALSTORAGE_KEY);
if (!AccessorUtilities.isLocalStorageAccessSafe()) {
return null;
}
const initialAlertJSON = localStorage.getItem(ALERT_LOCALSTORAGE_KEY);
// immediately clean up
window.localStorage.removeItem(ALERT_LOCALSTORAGE_KEY);
localStorage.removeItem(ALERT_LOCALSTORAGE_KEY);
if (!initialAlertJSON) {
return null;
......
......@@ -127,7 +127,7 @@ describe('JiraConnectApp', () => {
});
describe('when alert is set in localStoage', () => {
it('renders alert on mount', async () => {
it('renders alert on mount', () => {
persistAlert({ message: 'error message' });
createComponent();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment