Skip to content

Commit

Permalink
Control visibility of warning indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Sep 4, 2023
1 parent 586c282 commit 1573099
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/constant/storageKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export const ADDRESS_BOOK_CONFIG = "ADDRESS_BOOK_CONFIG"


/**
* store user decision whether to display the new extension warning
* Date when the user decides to dismiss the new extension warning.
*/
export const NEW_EXTENSION_WARNING_DISMISSED = "NEW_EXTENSION_WARNING_DISMISSED"
export const DISMISSED_NEW_EXTENSION_WARNING = "DISMISSED_NEW_EXTENSION_WARNING"
22 changes: 12 additions & 10 deletions src/popup/component/NewExtensionWarning/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import differenceInDays from 'date-fns/differenceInDays'
import { NEW_EXTENSION_RELEASE_DATE } from '../../../../config'
import differenceInDays from 'date-fns/differenceInDays';
import { NEW_EXTENSION_RELEASE_DATE } from '../../../../config';
import warningIconSrc from '../../../assets/images/warning.svg';
import { getLanguage } from '../../../i18n';
import { NEW_EXTENSION_WARNING_DISMISSED } from "../../../constant/storageKey";
import { saveLocal } from "../../../background/storage/localStorage";
import { DISMISSED_NEW_EXTENSION_WARNING } from '../../../constant/storageKey';
import { saveLocal } from '../../../background/storage/localStorage';
import './index.scss';

const isDismissingEnabled = NEW_EXTENSION_RELEASE_DATE ? differenceInDays(new Date(NEW_EXTENSION_RELEASE_DATE), new Date()) > 3 : true;
const canDismiss = NEW_EXTENSION_RELEASE_DATE
? differenceInDays(new Date(NEW_EXTENSION_RELEASE_DATE), new Date()) > 3
: true;

export const NewExtensionWarning = (props) => {
const handleClick = () => {
saveLocal(NEW_EXTENSION_WARNING_DISMISSED, true)
props.handleClick()
}
saveLocal(DISMISSED_NEW_EXTENSION_WARNING, new Date().toISOString());
props.handleClick();
};

return (
<div className="indicator">
Expand All @@ -21,13 +23,13 @@ export const NewExtensionWarning = (props) => {
</div>
<div className="indicator-content">
{getLanguage('newExtensionNotice')}
{isDismissingEnabled &&
{canDismiss && (
<div>
<button className="indicator-reminder" onClick={handleClick}>
{getLanguage('remindMe')}
</button>
</div>
}
)}
</div>
</div>
);
Expand Down
32 changes: 28 additions & 4 deletions src/reducers/appReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DEFAULT_LANGUAGE, } from "../../config";
import { NEW_EXTENSION_WARNING_DISMISSED } from "../constant/storageKey";
import { getLocal } from "../background/storage/localStorage";
import differenceInDays from 'date-fns/differenceInDays'
import { DEFAULT_LANGUAGE, NEW_EXTENSION_RELEASE_DATE } from "../../config";
import { DISMISSED_NEW_EXTENSION_WARNING } from "../constant/storageKey";
import { getLocal, removeLocal } from "../background/storage/localStorage";

const SET_LANGUAGE = "SET_LANGUAGE"
const HIDE_NEW_EXTENSION_WARNING = "HIDE_NEW_EXTENSION_WARNING"
Expand All @@ -19,9 +20,32 @@ export function hideNewExtensionWarning() {
};
}

function shouldShowNewExtensionWarning() {
const dismissed = getLocal(DISMISSED_NEW_EXTENSION_WARNING);
if (!dismissed || !NEW_EXTENSION_RELEASE_DATE) {
return !dismissed;
}

const dismissedDate = new Date(dismissed);
const releaseDate = new Date(NEW_EXTENSION_RELEASE_DATE);
// Always show the warning if the release date is less than or equal to 3 days away
if (differenceInDays(releaseDate, new Date()) <= 3) {
return true;
}
// Show the warning and reset the dismissed date
// if it was set more than two weeks before the release date
if (differenceInDays(releaseDate, dismissedDate) > 14) {
removeLocal(DISMISSED_NEW_EXTENSION_WARNING);
return true;
}

return false;
}


const initState = {
language: DEFAULT_LANGUAGE,
showNewExtensionWarning: !getLocal(NEW_EXTENSION_WARNING_DISMISSED)
showNewExtensionWarning: shouldShowNewExtensionWarning()
};

const appReducer = (state = initState, action) => {
Expand Down

0 comments on commit 1573099

Please sign in to comment.