-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) DMS removal disclaimer (#714)
* DMS removal disclaimer * update disclaimer text
- Loading branch information
1 parent
d30b72e
commit 87c2bea
Showing
8 changed files
with
118 additions
and
0 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
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,23 @@ | ||
import { useState, useEffect } from 'react' | ||
|
||
const useCountdown = (initialCount, isActive = true) => { | ||
const [countdown, setCountdown] = useState(initialCount) | ||
|
||
useEffect(() => { | ||
let timer | ||
if (isActive && countdown > 0) { | ||
timer = setInterval(() => { | ||
setCountdown((prevCountdown) => prevCountdown - 1) | ||
}, 1000) | ||
} | ||
return () => { | ||
if (timer) clearInterval(timer) | ||
} | ||
}, [isActive, countdown]) | ||
|
||
const resetCountdown = () => setCountdown(initialCount) | ||
|
||
return { countdown, isFinished: countdown === 0, resetCountdown } | ||
} | ||
|
||
export default useCountdown |
16 changes: 16 additions & 0 deletions
16
src/modals/DMSRemovalDisclaimerModal/DMSRemovalDisclaimerModal.container.js
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,16 @@ | ||
import { connect } from 'react-redux' | ||
|
||
import { changeUIModalState } from '../../redux/actions/ui' | ||
import { UI_MODAL_KEYS } from '../../redux/constants/modals' | ||
import { getUIModalStateForKey } from '../../redux/selectors/ui' | ||
import DMSRemovalDisclaimerModal from './DMSRemovalDisclaimerModal' | ||
|
||
const mapStateToProps = (state = {}) => ({ | ||
visible: getUIModalStateForKey(state, UI_MODAL_KEYS.DMS_REMOVAL_DISCLAIMER), | ||
}) | ||
|
||
const mapDispatchToProps = { | ||
changeUIModalState, | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(DMSRemovalDisclaimerModal) |
64 changes: 64 additions & 0 deletions
64
src/modals/DMSRemovalDisclaimerModal/DMSRemovalDisclaimerModal.js
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,64 @@ | ||
/* eslint-disable jsx-a11y/anchor-has-content */ | ||
import React, { memo } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Trans, useTranslation } from 'react-i18next' | ||
import Modal from '../../ui/Modal' | ||
import { UI_MODAL_KEYS } from '../../redux/constants/modals' | ||
import { DO_NOT_SHOW_DMS_REMOVAL_DISCLAIMER } from '../../redux/reducers/ui' | ||
import useCountdown from '../../hooks/useCountdown' | ||
import { DISCONTINUE_DMS_SUPPORT_ARTICLE_DMS } from '../../redux/config' | ||
|
||
const DMSRemovalDisclaimerModal = ({ changeUIModalState, visible }) => { | ||
const { t } = useTranslation() | ||
const { countdown, isFinished } = useCountdown(10, visible) | ||
|
||
const onSubmit = () => { | ||
if (!isFinished) { | ||
return | ||
} | ||
changeUIModalState(UI_MODAL_KEYS.DMS_REMOVAL_DISCLAIMER, false) | ||
localStorage.setItem(DO_NOT_SHOW_DMS_REMOVAL_DISCLAIMER, 'true') | ||
} | ||
|
||
return ( | ||
<Modal | ||
label={t('dmsRemovalDisclaimerModal.title')} | ||
isCloseButtonShown={isFinished} | ||
isOpen={visible} | ||
onClose={onSubmit} | ||
onSubmit={onSubmit} | ||
> | ||
<Trans | ||
t={t} | ||
i18nKey='dmsRemovalDisclaimerModal.text' | ||
components={{ | ||
url: ( | ||
<a | ||
href={DISCONTINUE_DMS_SUPPORT_ARTICLE_DMS} | ||
target='_blank' | ||
rel='noopener noreferrer' | ||
/> | ||
), | ||
}} | ||
/> | ||
<Modal.Footer> | ||
<Modal.Button | ||
onClick={onSubmit} | ||
primary | ||
disabled={!isFinished} | ||
> | ||
{!isFinished | ||
? `${t('ui.closeBtn')} (${countdown})` | ||
: t('ui.closeBtn')} | ||
</Modal.Button> | ||
</Modal.Footer> | ||
</Modal> | ||
) | ||
} | ||
|
||
DMSRemovalDisclaimerModal.propTypes = { | ||
changeUIModalState: PropTypes.func.isRequired, | ||
visible: PropTypes.bool.isRequired, | ||
} | ||
|
||
export default memo(DMSRemovalDisclaimerModal) |
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,3 @@ | ||
import DMSRemovalDisclaimerModal from './DMSRemovalDisclaimerModal.container' | ||
|
||
export default DMSRemovalDisclaimerModal |
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