-
Notifications
You must be signed in to change notification settings - Fork 43
[APT-1573] [APT-1574]: Subscriber notification for private Github links #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a9667e6
Initial commit
oredavids 8126552
Merge branch 'master' of github.com:gruntwork-io/docs into subscriber…
oredavids 926f79c
Adds skeleton subscriber notice for private Github links
oredavids 09edc2c
Updated text and added repo name to modal. Also added initial css file
eak12913 847dca3
Initial commit
oredavids ef2037e
Adds skeleton subscriber notice for private Github links
oredavids d09b3cb
Updated text and added repo name to modal. Also added initial css file
eak12913 efddf16
Add modal and button styles
ebeneliason d991e40
Merge branch 'subscriber-notification' of https://github.com/gruntwor…
eak12913 f96d6f6
[APT-1574] Added ability to dismiss the private GitHub warning forever
eak12913 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,46 @@ | ||
.mainContainer { | ||
max-width: 420px; | ||
margin: auto; | ||
background: #f9fbfc; | ||
padding: 2em; | ||
border-radius: 6px; | ||
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.25); | ||
display: flex; | ||
flex-direction: column; | ||
justify-self: center; | ||
align-self: center; | ||
} | ||
|
||
html[data-theme="dark"] .mainContainer { | ||
background-color: var(--ifm-background-surface-color); | ||
} | ||
|
||
.buttonsContainer { | ||
flex: auto; | ||
text-align: right; | ||
font-weight: 600; | ||
margin-top: 1rem; | ||
} | ||
|
||
.buttonsContainer > * { | ||
margin-right: 1rem; | ||
} | ||
|
||
.overlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: rgba(255, 255, 255, 0.75); | ||
z-index: 999; | ||
display: flex; | ||
} | ||
|
||
html[data-theme="dark"] .overlay { | ||
background-color: rgba(0, 0, 0, 0.75); | ||
} | ||
|
||
input[type="checkbox"] { | ||
margin-right: 0.5rem; | ||
} |
This file contains hidden or 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,129 @@ | ||
import React, { useEffect } from "react" | ||
import ModalCmp from "react-modal" | ||
import { DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY } from "../theme/Root" | ||
import styles from "./Modal.module.css" | ||
|
||
interface ModalProps { | ||
externalLink: string | ||
showModal: boolean | ||
children?: React.ReactNode | ||
shouldCloseOnEsc?: boolean | ||
shouldAcceptOnEnter?: boolean | ||
shouldCloseOnOverlayClick?: boolean | ||
handleCancelRequest: () => void | ||
handleAcceptRequest?: () => void | ||
} | ||
|
||
export const idOfNoticeLink = "notice" | ||
|
||
if (typeof window !== "undefined") { | ||
ModalCmp.setAppElement("body") | ||
} | ||
|
||
export const SubscriptionNoticeModal: React.FC<ModalProps> = ({ | ||
externalLink, | ||
showModal, | ||
shouldCloseOnEsc = true, | ||
shouldAcceptOnEnter = false, | ||
shouldCloseOnOverlayClick = true, | ||
handleCancelRequest, | ||
handleAcceptRequest, | ||
}) => { | ||
const onRequestClose = () => { | ||
// If the user checked to never see this notice but subsequently cancels we will disregard their selection. We will | ||
// only stop showing this notice if they check the box and then proceed to GitHub | ||
if(window.localStorage.getItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)) { | ||
window.localStorage.removeItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY) | ||
} | ||
|
||
handleCancelRequest() | ||
} | ||
|
||
const gitHubRepoName = externalLink.match( | ||
/https:\/\/github.com\/gruntwork-io\/(.*?)\/.*/ | ||
) | ||
|
||
// function to check if there's any active button (focus on the button) to avoid conflicts with shouldAcceptOnEnter property | ||
const checkIfAnyActiveButton = () => { | ||
const activeElement = document.activeElement | ||
if (activeElement && activeElement.tagName.toLowerCase() === "button") { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
useEffect(() => { | ||
if (showModal) { | ||
document.body.style.overflow = "hidden" | ||
} | ||
const timer = setTimeout(() => { | ||
if (!showModal) { | ||
document.body.style.overflow = "unset" | ||
} | ||
}, 300) | ||
return () => clearTimeout(timer) | ||
}, [showModal]) | ||
|
||
useEffect(() => { | ||
const listener = (e: any) => { | ||
const code = e.key | ||
if ( | ||
code === "Enter" && | ||
handleAcceptRequest && | ||
shouldAcceptOnEnter && | ||
showModal && | ||
!checkIfAnyActiveButton() | ||
) { | ||
e.preventDefault() | ||
handleAcceptRequest() | ||
} | ||
} | ||
document.addEventListener("keydown", listener, false) | ||
return () => { | ||
document.removeEventListener("keydown", listener, false) | ||
} | ||
}) | ||
|
||
const setDontWarnMe = (event) => { | ||
event.stopPropagation() | ||
if(!window.localStorage.getItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)) { | ||
window.localStorage.setItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY, "true") | ||
} else { | ||
window.localStorage.removeItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY) | ||
} | ||
} | ||
|
||
return ( | ||
<ModalCmp | ||
isOpen={showModal} | ||
preventScroll={true} | ||
onRequestClose={onRequestClose} | ||
shouldCloseOnEsc={shouldCloseOnEsc} | ||
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick} | ||
closeTimeoutMS={0} | ||
className={styles.mainContainer} | ||
overlayClassName={styles.overlay} | ||
> | ||
<h2>For Subscribers Only</h2> | ||
<p> | ||
This link leads to the private{" "} | ||
{gitHubRepoName && gitHubRepoName.length >= 1 && ( | ||
<code>{gitHubRepoName[1]}</code> | ||
)}{" "} | ||
repository visible only to subscribers; everyone else will see a 404. | ||
</p> | ||
<div> | ||
<input type="checkbox" onClick={setDontWarnMe} /> | ||
<label>Don't warn me again</label> | ||
</div> | ||
<div className={styles.buttonsContainer}> | ||
<a onClick={() => onRequestClose()} href="#"> | ||
Cancel | ||
</a> | ||
<a id={idOfNoticeLink} href={externalLink} target="_blank"> | ||
Continue to GitHub | ||
</a> | ||
</div> | ||
</ModalCmp> | ||
) | ||
} |
This file contains hidden or 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 hidden or 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,59 @@ | ||
import React, { useState, useEffect } from "react" | ||
import { | ||
SubscriptionNoticeModal, | ||
idOfNoticeLink, | ||
} from "/src/components/Modal.tsx" | ||
|
||
const gruntworkRepos = "https://github.com/gruntwork-io" | ||
|
||
export const DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY = "dontWarnGitHubLinks" | ||
|
||
function Root({ children }) { | ||
const [displaySubscriberNotice, setDisplaySubscriberNotice] = useState(false) | ||
const [externalLink, setExternalLink] = useState("") | ||
|
||
useEffect(() => { | ||
const listener = (event) => { | ||
if (event.target.id === idOfNoticeLink) { | ||
setDisplaySubscriberNotice(false) | ||
return | ||
} | ||
const dontWarn = window.localStorage.getItem( | ||
DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY | ||
) | ||
|
||
if (dontWarn) { | ||
setDisplaySubscriberNotice(false) | ||
return | ||
} | ||
|
||
if (event.target.href && event.target.href.includes(gruntworkRepos)) { | ||
event.preventDefault() | ||
console.log | ||
setExternalLink(event.target.href) | ||
setDisplaySubscriberNotice(true) | ||
} | ||
} | ||
|
||
window.addEventListener("click", listener) | ||
|
||
// use-effect cleanup | ||
return () => window.removeEventListener("click", listener) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<SubscriptionNoticeModal | ||
showModal={displaySubscriberNotice} | ||
externalLink={externalLink} | ||
handleCancelRequest={() => { | ||
setDisplaySubscriberNotice(false) | ||
setExternalLink("") | ||
}} | ||
/> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export default Root |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is intentional - Is there a particular reason for disregarding it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can discuss this quickly next time we speak - but for the purpose of this PR we do want to have that behavior. It's a slightly better user experience as it applies your wishes only after you've chosen to follow the link forward. Otherwise you can get into a s situation where you dind't mean to dismiss the thing and never see it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏾