Skip to content

Commit

Permalink
Unsupported browser alert
Browse files Browse the repository at this point in the history
  • Loading branch information
cinyecai committed Nov 13, 2024
1 parent 171572f commit cdad446
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 92 deletions.
58 changes: 11 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"ajv": "8.17.1",
"ajv-formats": "3.0.1",
"axios": "1.7.7",
"browser-version-detection": "^2.1.8",
"dompurify": "3.1.7",
"js-file-download": "0.4.12",
"lodash": "4.17.21",
"mixin-deep": "2.0.1",
"moment": "2.30.1",
"noty": "3.2.0-beta",
"oidc-client-ts": "3.1.0",
"outdated-browser-rework": "^3.0.1",
"query-string": "9.1.1",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand Down
1 change: 0 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<div id="outdated"></div>

<!--
This HTML file is a template.
Expand Down
35 changes: 35 additions & 0 deletions src/components/ActionableAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import './Alert.css';
import CloseIcon from '@mui/icons-material/Close';
import { Button } from '@mui/material';

export interface ActionableAlertProps {
id: string;
type: string;
title: string;
description: string;
onClose?: () => void;
actionText: string;
onClick?: () => void;
}

export const ActionableAlert = (props: ActionableAlertProps) => {
const {id, type, title, description, onClose, actionText, onClick} = props;
return (
<div id={`${id}_alert`} className={`alert-wrapper ${type}`} style={{border: '1px solid red', borderRadius: '5px'}}>
{onClose && <span
style={{float: 'right', fontWeight: 'bolder', fontSize: 24, cursor: 'pointer'}}
onClick={onClose} ><CloseIcon/></span> }
{title && <h4 id={`${id}_title`} className="alert-title">{title}</h4>}
{description && <span id={`${id}_description`} className="alert-description">{description}</span>}
{actionText && <Button
variant='outlined'
color='error'
onClick={onClick}
sx={{fontSize: 10, marginTop: 2}}
>
{actionText}
</Button>}
</div>
);
};
39 changes: 28 additions & 11 deletions src/components/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {History} from 'history';
import {OidcUser} from '../libs/auth/oidcBroker';
import {DuosUser} from '../types/model';
import {DuosUserResponse} from '../types/responseTypes';
import {ActionableAlert} from '../components/ActionableAlert';
import {detectBrowser} from 'browser-version-detection/src/browser-detection';

interface SignInButtonProps {
history: History;
Expand All @@ -39,6 +41,13 @@ export const SignInButton = (props: SignInButtonProps) => {
const {history} = props;
const [isLoading, setIsLoading] = useState<boolean>(false);

const browser = detectBrowser(window.navigator);
const browserName = browser.name;
const checkBrowser = () => {
return (!isEmpty(browserName) && browserName !== 'Chrome' && browserName !== 'Firefox');
};
const [showUnsupported, setShowUnsupported] = useState<boolean>(checkBrowser());

// Utility function called in the normal success case and in the undocumented 409 case
// Check for ToS Acceptance - redirect user if not set.
const checkToSAndRedirect = async (redirectPath: string | null) => {
Expand Down Expand Up @@ -205,19 +214,27 @@ export const SignInButton = (props: SignInButtonProps) => {

return (
<div>
{isEmpty(errorDisplay)
? <div>
{showUnsupported ?
<ActionableAlert
id="dialog"
type="danger"
title={'DUOS may not function correctly in this browser.'}
description={'If you are experiencing issues, please try using Google Chrome.'}
onClose={() => setShowUnsupported(false)}
actionText={'Download Chrome now'}
onClick={() => window.open('https://www.google.com/chrome/')}/> :
isEmpty(errorDisplay) ? <div>
{signInElement()}
</div>
: <div className="dialog-alert">
<Alert
id="dialog"
type="danger"
title={(errorDisplay as ErrorInfo).title || 'Error'}
description={(errorDisplay as ErrorInfo).description || ''}
onClose={() => setErrorDisplay({})}
/>
</div>
: <div className="dialog-alert">
<Alert
id="dialog"
type="danger"
title={(errorDisplay as ErrorInfo).title || 'Error'}
description={(errorDisplay as ErrorInfo).description || ''}
onClose={() => setErrorDisplay({})}
/>
</div>
}
</div>
);
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {Auth} from './libs/auth/auth';
import {OidcBroker} from './libs/auth/oidcBroker';
import {unregister} from './registerServiceWorker';
import {BrowserRouter} from 'react-router-dom';
import './outdated-browser-message.js';

const load = async () => {
unregister();
Expand Down
30 changes: 0 additions & 30 deletions src/outdated-browser-message.js

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
}
},
"include": [
"src"
"src",
"types/index.d.ts"
],
"plugins": ["@typescript-eslint", "import"]
}
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "browser-version-detection/src/browser-detection" {
export function detectBrowser(nav: { userAgent: string }): any
}

0 comments on commit cdad446

Please sign in to comment.