-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SSO: Show modal on disconnection #88552
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91d4ba3
Setup SSO disable modal
heavyweight 6293485
SurveyModal: minor improvements
heavyweight 1cc80b1
Merge branch 'trunk' into add/sso-survey-modal
heavyweight fd7569f
SurveyModal: change useState import
heavyweight ac1d32c
SSO: show modal only for en
heavyweight 0471bed
Merge branch 'trunk' into add/sso-survey-modal
heavyweight f596a0e
SurveyModal: fix typo
heavyweight f66cd63
SurveyModal: add optional heading support
heavyweight 3e5d3a0
Update content padding
agrullon95 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 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,49 @@ | ||
# SurveyModal | ||
|
||
Simple modal component that links to a survey. | ||
|
||
## Example Usage | ||
|
||
```js | ||
import { useState } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import SurveyModal from 'calypso/components/survey-modal'; | ||
import surveyImage from 'calypso/assets/images/illustrations/illustration-seller.svg'; | ||
|
||
function MyComponent() { | ||
const [ isModalVisible, setIsModalVisible ] = useState( false ); | ||
|
||
return <> | ||
<div>Content</div> | ||
{ isModalVisible && | ||
ReactDOM.createPortal( | ||
<SurveyModal | ||
name="sso-disable" | ||
url="https://wordpressdotcom.survey.fm/sso-disable-survey?initiated-from=calypso" | ||
heading={ translate( 'SSO Survey' ) } | ||
title={ translate( 'Hi there!' ) } | ||
description={ translate( | ||
`Spare a moment? We'd love to hear why you want to disable SSO in a quick survey.` | ||
) } | ||
surveyImage={ surveyImage } | ||
dismissText={ translate( 'Remind later' ) } | ||
confirmText={ translate( 'Take survey' ) } | ||
/>, | ||
document.body | ||
) }; | ||
</> | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
- `name` - (string) The name to use for cookie management. Recommended to use Kebap case. | ||
- `className` - (string) Additional className for the modal. | ||
- `url` - (string) The url to which the confirm button links to. | ||
- `heading` - (string) Heading of the modal | ||
- `title` - _optional_ (string) Title text | ||
- `surveyImage` - _optional_ (string) Image to display in the modal | ||
- `description` - (string) Description text | ||
- `dismissText` - (string) Text for the dismiss button | ||
- `confirmText` - (string) Text for the confirm button |
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,100 @@ | ||
import { Gridicon } from '@automattic/components'; | ||
import { Button } from '@wordpress/components'; | ||
import classNames from 'classnames'; | ||
import cookie from 'cookie'; | ||
import PropTypes from 'prop-types'; | ||
import { useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { getCurrentUserId } from 'calypso/state/current-user/selectors'; | ||
import './style.scss'; | ||
|
||
const SurveyModal = ( { | ||
name, | ||
className, | ||
url, | ||
heading, | ||
title, | ||
surveyImage, | ||
description, | ||
dismissText, | ||
confirmText, | ||
} ) => { | ||
const userId = useSelector( getCurrentUserId ); | ||
const href = new URL( url ); | ||
href.searchParams.set( 'user-id', userId ); | ||
|
||
const [ hideNotice, setHideNotice ] = useState( | ||
'dismissed' === cookie.parse( document.cookie )?.sso_survey | ||
); | ||
|
||
const setSurveyCookie = ( value, maxAge ) => { | ||
document.cookie = cookie.serialize( name, value, { | ||
path: '/', | ||
maxAge, | ||
} ); | ||
}; | ||
|
||
const onClose = () => { | ||
setSurveyCookie( 'dismissed', 365 * 24 * 60 * 60 ); // 1 year | ||
setHideNotice( true ); | ||
}; | ||
|
||
if ( hideNotice ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={ classNames( 'modal-survey-notice', className ) }> | ||
<Button className="modal-survey-notice__backdrop" onClick={ onClose } /> | ||
<div className="modal-survey-notice__popup"> | ||
<div className="modal-survey-notice__popup-head"> | ||
<div className="modal-survey-notice__popup-head-title">{ heading }</div> | ||
<Button onClick={ onClose } className="modal-survey-notice__popup-head-close"> | ||
<Gridicon icon="cross" size={ 16 } /> | ||
</Button> | ||
</div> | ||
{ surveyImage && ( | ||
<div className="modal-survey-notice__popup-img"> | ||
<img src={ surveyImage } alt={ heading } /> | ||
</div> | ||
) } | ||
|
||
<div className="modal-survey-notice__popup-content"> | ||
{ title && <div className="modal-survey-notice__popup-content-title">{ title }</div> } | ||
<div className="modal-survey-notice__popup-content-description">{ description }</div> | ||
<div className="modal-survey-notice__popup-content-buttons"> | ||
<Button | ||
className="dmodal-survey-notice__popup-content-buttons-cancel" | ||
onClick={ onClose } | ||
> | ||
{ dismissText } | ||
</Button> | ||
<Button | ||
className="modal-survey-notice__popup-content-buttons-ok" | ||
href={ href.toString() } | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
onClick={ onClose } | ||
> | ||
{ confirmText } | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
SurveyModal.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
className: PropTypes.string, | ||
url: PropTypes.string.isRequired, | ||
heading: PropTypes.string.isRequired, | ||
title: PropTypes.string, | ||
surveyImage: PropTypes.string, | ||
description: PropTypes.string.isRequired, | ||
dismissText: PropTypes.string.isRequired, | ||
confirmText: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default SurveyModal; |
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,108 @@ | ||
.modal-survey-notice { | ||
position: fixed; | ||
left: 0; | ||
top: 0; | ||
height: 100%; | ||
width: 100%; | ||
z-index: 1000; | ||
|
||
.modal-survey-notice__backdrop { | ||
background: var(--studio-black); | ||
opacity: 0.2; | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
cursor: default; | ||
} | ||
|
||
|
||
.modal-survey-notice__popup { | ||
position: absolute; | ||
right: 25px; | ||
bottom: 25px; | ||
width: 416px; | ||
max-width: calc(100% - 50px); | ||
z-index: 2; | ||
border-radius: 2px; | ||
box-shadow: 0 3px 1px 0 rgba(0, 0, 0, 0.04), 0 3px 8px 0 rgba(0, 0, 0, 0.12); | ||
overflow: hidden; | ||
|
||
.modal-survey-notice__popup-head { | ||
background: #0675c4; | ||
border-bottom: 1px solid #f6f7f7; | ||
height: 56px; | ||
padding: 0 14px 0 16px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
|
||
.modal-survey-notice__popup-head-title { | ||
color: var(--studio-white); | ||
font-size: rem(14px); | ||
font-weight: 500; | ||
line-height: 20px; | ||
letter-spacing: -0.15px; | ||
} | ||
|
||
.modal-survey-notice__popup-head-close svg { | ||
fill: var(--studio-white); | ||
} | ||
} | ||
|
||
.modal-survey-notice__popup-img { | ||
background: #0675c4; | ||
padding-bottom: 57.9%; | ||
height: 0; | ||
|
||
img { | ||
width: 100%; | ||
display: block; | ||
} | ||
} | ||
|
||
.modal-survey-notice__popup-content { | ||
padding: 18px 24px 30px; | ||
agrullon95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
background: var(--studio-white); | ||
|
||
.modal-survey-notice__popup-content-title { | ||
font-size: rem(16px); | ||
font-weight: 500; | ||
line-height: 24px; | ||
letter-spacing: -0.32px; | ||
padding-bottom: 8px; | ||
} | ||
|
||
.modal-survey-notice__popup-content-description { | ||
font-size: rem(14px); | ||
line-height: 20px; | ||
letter-spacing: -0.15px; | ||
padding-bottom: 18px; | ||
} | ||
|
||
.modal-survey-notice__popup-content-buttons { | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
.modal-survey-notice__popup-content-buttons-ok { | ||
padding: 8px 14px; | ||
background: var(--studio-blue-50); | ||
color: var(--studio-white); | ||
font-size: rem(14px); | ||
line-height: 20px; | ||
letter-spacing: -0.15px; | ||
} | ||
|
||
.modal-survey-notice__popup-content-buttons-cancel { | ||
padding: 8px 14px; | ||
color: var(--studio-blue-50); | ||
text-align: center; | ||
font-size: rem(14px); | ||
line-height: 20px; | ||
letter-spacing: -0.15px; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Can we use the one from @WordPress?