import evaluateBrowserVersion from '@digigov/ui/app/OutdatedBrowserBanner/hooks/evaluateBrowserVersion'; const DEFAULT_BROWSER_SUPPORT = { Chrome: 57, // Includes Chrome for mobile devices Edge: 39, Safari: 10, 'Mobile Safari': 10, Firefox: 50, Opera: 50, IE: 0, }; const browserUpdateLinks = { Chrome: 'https://www.google.com/chrome/', Edge: 'https://www.microsoft.com/en-us/edge', Safari: 'https://www.apple.com/safari/', 'Mobile Safari': 'https://www.apple.com/safari/', Firefox: 'https://www.mozilla.org/en-US/firefox/new/', Opera: 'https://www.opera.com/download', }; const browserNames = Object.keys(DEFAULT_BROWSER_SUPPORT); export function useOutdatedBrowserCheck( browserSupport: Record = DEFAULT_BROWSER_SUPPORT ): [boolean, string] { const currentBrowser = evaluateBrowserVersion(); if (!currentBrowser.version || !currentBrowser.name) { return [true, browserUpdateLinks.Chrome]; } const currentBrowserVersion = parseInt(currentBrowser.version); const currentBrowserName = currentBrowser.name; if (browserNames.indexOf(currentBrowser.name) > -1) { // this checks if browser is IE if (browserSupport[currentBrowserName] === 0) { return [true, browserUpdateLinks.Chrome]; } else { if (currentBrowserVersion >= browserSupport[currentBrowserName]) { // TODO: check if number return [false, '']; } else { return [true, browserUpdateLinks[currentBrowserName]]; } } } else { return [true, browserUpdateLinks.Chrome]; } } export default useOutdatedBrowserCheck;