forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account activation pop up added: (openedx#425)
VAN-435
- Loading branch information
Adeel Ehsan
authored
Jun 4, 2021
1 parent
5c204ad
commit 07b82b1
Showing
7 changed files
with
193 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ TERMS_OF_SERVICE_URL='' | |
TWITTER_HASHTAG='' | ||
TWITTER_URL='' | ||
USER_INFO_COOKIE_NAME='' | ||
SESSION_COOKIE_DOMAIN='' |
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
135 changes: 135 additions & 0 deletions
135
src/alerts/logistration-alert/AccountActivationAlert.jsx
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,135 @@ | ||
import React, { useState } from 'react'; | ||
import Cookies from 'js-cookie'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { getAuthenticatedUser } from '@edx/frontend-platform/auth'; | ||
import { | ||
AlertModal, | ||
Button, | ||
Spinner, | ||
Icon, | ||
} from '@edx/paragon'; | ||
import { Check, ArrowForward } from '@edx/paragon/icons'; | ||
import { FormattedMessage, injectIntl } from '@edx/frontend-platform/i18n'; | ||
import { sendActivationEmail } from '../../courseware/data'; | ||
|
||
function AccountActivationAlert() { | ||
const [showModal, setShowModal] = useState(false); | ||
const [showSpinner, setShowSpinner] = useState(false); | ||
const [showCheck, setShowCheck] = useState(false); | ||
const handleOnClick = () => { | ||
setShowSpinner(true); | ||
setShowCheck(false); | ||
sendActivationEmail().then(() => { | ||
setShowSpinner(false); | ||
setShowCheck(true); | ||
}); | ||
}; | ||
|
||
const showAccountActivationAlert = Cookies.get('show-account-activation-popup'); | ||
if (showAccountActivationAlert !== undefined) { | ||
Cookies.remove('show-account-activation-popup', { path: '/', domain: process.env.SESSION_COOKIE_DOMAIN }); | ||
// extra check to make sure cookie was removed before updating the state. Updating the state without removal | ||
// of cookie would make it infinit rendering | ||
if (Cookies.get('show-account-activation-popup') === undefined) { | ||
setShowModal(true); | ||
} | ||
} | ||
|
||
const title = ( | ||
<h3> | ||
<FormattedMessage | ||
id="account-activation.alert.title" | ||
defaultMessage="Activate your account so you can log back in" | ||
description="Title for account activation alert which is shown after the registration" | ||
/> | ||
</h3> | ||
); | ||
|
||
const button = ( | ||
<Button | ||
variant="primary" | ||
className="" | ||
onClick={() => setShowModal(false)} | ||
> | ||
<FormattedMessage | ||
id="account-activation.alert.button" | ||
defaultMessage="Continue to {siteName}" | ||
description="account activation alert continue button" | ||
values={{ | ||
siteName: getConfig().SITE_NAME, | ||
}} | ||
/> | ||
<Icon src={ArrowForward} className="ml-1 d-inline-block align-bottom" /> | ||
</Button> | ||
); | ||
|
||
const children = () => { | ||
let bodyContent = null; | ||
const message = ( | ||
<FormattedMessage | ||
id="account-activation.alert.message" | ||
defaultMessage="We sent an email to {boldEmail} with a link to activate your account. Can’t find it? Check your spam folder or | ||
{sendEmailTag}." | ||
description="Message for account activation alert which is shown after the registration" | ||
values={{ | ||
boldEmail: <b>{getAuthenticatedUser().email}</b>, | ||
sendEmailTag: ( | ||
// eslint-disable-next-line jsx-a11y/anchor-is-valid | ||
<a href="#" role="button" onClick={handleOnClick}> | ||
<FormattedMessage | ||
id="account-activation.resend.link" | ||
defaultMessage="resend the email" | ||
description="Message for resend link in account activation alert which is shown after the registration" | ||
/> | ||
</a> | ||
), | ||
}} | ||
/> | ||
); | ||
bodyContent = ( | ||
<div> | ||
{message} | ||
</div> | ||
); | ||
|
||
if (!showCheck && showSpinner) { | ||
bodyContent = ( | ||
<div> | ||
{message} | ||
<Spinner | ||
animation="border" | ||
variant="secondary" | ||
style={{ height: '1.5rem', width: '1.5rem' }} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
if (showCheck && !showSpinner) { | ||
bodyContent = ( | ||
<div> | ||
{message} | ||
<Icon | ||
src={Check} | ||
style={{ height: '1.7rem', width: '1.25rem' }} | ||
className="text-success-500 d-inline-block position-fixed" | ||
/> | ||
</div> | ||
); | ||
} | ||
return bodyContent; | ||
}; | ||
|
||
return ( | ||
<AlertModal | ||
isOpen={showModal} | ||
title={title} | ||
footerNode={button} | ||
onClose={() => ({})} | ||
> | ||
{children()} | ||
</AlertModal> | ||
); | ||
} | ||
|
||
export default injectIntl(AccountActivationAlert); |
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
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