-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1537 from clpetersonucf/issue/improved-invalid-lo…
…gin-states-updated Improved invalid login states
- Loading branch information
Showing
5 changed files
with
70 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react' | ||
import Modal from './modal' | ||
|
||
const InvalidLoginModal = ({onClose}) => ( | ||
<Modal onClose={onClose} ignoreClose={true} smaller={true} alert={true}> | ||
<div> | ||
<span className='alert-title'> | ||
Your Session is No Longer Valid | ||
</span> | ||
<p className='alert-description'>Your session with Materia is considered invalid and you have been logged out. You'll have to log back in to see this content.</p> | ||
<span className='buttons'> | ||
<a className='action_button' | ||
onClick={onClose}> | ||
Okay | ||
</a> | ||
</span> | ||
</div> | ||
</Modal> | ||
) | ||
|
||
export default InvalidLoginModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,45 @@ | ||
import React from 'react' | ||
import { createPortal } from 'react-dom'; | ||
import React, { useRef, useEffect } from 'react' | ||
import { createPortal } from 'react-dom' | ||
|
||
import './modal.scss' | ||
|
||
class Modal extends React.Component { | ||
constructor( props ) { | ||
super( props ) | ||
// create an element div for this modal | ||
this.modalRef = React.createRef() | ||
this.element = document.createElement( 'div' ) | ||
this.clickOutsideListener = this.clickOutsideListener.bind(this) | ||
const Modal = (props) => { | ||
|
||
// We get hold of the div with the id modal that we have created in index.html | ||
this.modalRoot = document.getElementById( 'modal' ) | ||
} | ||
const innerModalRef = useRef(null) | ||
|
||
clickOutsideListener(event){ | ||
const clickOutsideListener = (event) => { | ||
// Do nothing if clicking ref's element or descendent elements | ||
if (!this.modalRef.current || this.modalRef.current.contains(event.target)) { | ||
return | ||
} | ||
if (!innerModalRef.current || innerModalRef.current.contains(event.target)) return | ||
if (props.ignoreClose != true) props.onClose() | ||
} | ||
|
||
if (this.props.ignoreClose !== true) { | ||
this.props.onClose() | ||
} | ||
}; | ||
useEffect(() => { | ||
|
||
componentDidMount() { | ||
this.modalRoot.appendChild( this.element ) | ||
document.addEventListener('mousedown', this.clickOutsideListener) | ||
document.addEventListener('touchstart', this.clickOutsideListener) | ||
} | ||
document.addEventListener('mouseup', clickOutsideListener) | ||
document.addEventListener('touchend', clickOutsideListener) | ||
|
||
componentWillUnmount() { | ||
this.modalRoot.removeChild( this.element ) | ||
document.removeEventListener('mousedown', this.clickOutsideListener) | ||
document.removeEventListener('touchstart', this.clickOutsideListener) | ||
} | ||
return () => { | ||
document.removeEventListener('mouseup', clickOutsideListener) | ||
document.removeEventListener('touchend', clickOutsideListener) | ||
} | ||
|
||
render() { | ||
const stuff = ( | ||
<> | ||
<div className={`modal-overlay ${this.props.alert ? 'alert' : ''}`} id='modal-overlay'></div> | ||
|
||
<div ref={this.modalRef} className={`modal ${this.props.smaller ? 'small' : ''} ${this.props.noGutter ? 'no-gutter' : ''}`} id='inner-modal'> | ||
<span className='close-button' | ||
id='close-button' | ||
aria-label={`close${this.props.testId ? `-${this.props.testId}-` : '-'}modal`} | ||
onClick={this.props.onClose}>X</span> | ||
<div className={`modal-guts ${this.props.noGutter ? 'no-gutter' : ''}`}> | ||
{this.props.children} | ||
</div> | ||
},[]) | ||
|
||
const modal = | ||
(<> | ||
<div className={`modal-overlay ${props.alert ? 'alert' : ''}`} id='modal-overlay'></div> | ||
<div ref={innerModalRef} className={`modal ${props.smaller ? 'small' : ''} ${props.noGutter ? 'no-gutter' : ''}`} id='inner-modal'> | ||
<span className='close-button' | ||
id='close-button' | ||
aria-label={`close${props.testId ? `-${props.testId}-` : '-'}modal`} | ||
onClick={props.onClose}>X</span> | ||
<div className={`modal-guts ${props.noGutter ? 'no-gutter' : ''}`}> | ||
{props.children} | ||
</div> | ||
</> | ||
) | ||
return createPortal( stuff, this.element ); | ||
} | ||
</div> | ||
</>) | ||
|
||
return createPortal(modal, document.getElementById('modal')) | ||
} | ||
|
||
export default Modal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters