Skip to content

Commit 0e36d3c

Browse files
authored
Me/Account: Created a new email verification banner (#103171)
1 parent f0b6cae commit 0e36d3c

File tree

6 files changed

+148
-17
lines changed

6 files changed

+148
-17
lines changed

client/components/banner/index.jsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ export class Banner extends Component {
301301
<PlanPrice rawPrice={ prices[ 1 ] } discounted />
302302
</div>
303303
) }
304+
{ secondaryCallToAction && (
305+
<Button
306+
compact={ compactButton }
307+
href={ secondaryHref }
308+
onClick={ this.handleSecondaryClick }
309+
primary={ false }
310+
>
311+
{ preventWidows( secondaryCallToAction ) }
312+
</Button>
313+
) }
304314
{ callToAction &&
305315
( forceHref ? (
306316
<Button
@@ -323,17 +333,6 @@ export class Banner extends Component {
323333
{ preventWidows( callToAction ) }
324334
</Button>
325335
) ) }
326-
327-
{ secondaryCallToAction && (
328-
<Button
329-
compact={ compactButton }
330-
href={ secondaryHref }
331-
onClick={ this.handleSecondaryClick }
332-
primary={ false }
333-
>
334-
{ preventWidows( secondaryCallToAction ) }
335-
</Button>
336-
) }
337336
</div>
338337
) }
339338
</div>

client/components/banner/style.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,21 @@
204204
font-size: $font-body-extra-small;
205205
}
206206

207+
.email-verification-banner__highlight {
208+
text-transform: none;
209+
}
210+
207211
.banner__action {
208212
align-self: center;
209213
font-size: $font-body-extra-small;
210214
margin: 12px 0 0;
211215
text-align: left;
212216
width: 100%;
213217

218+
.is-primary {
219+
margin-left: 8px;
220+
}
221+
214222
.banner__prices {
215223
display: flex;
216224
justify-content: flex-start;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useSelector } from 'calypso/state';
2+
import { isCurrentUserEmailVerified } from 'calypso/state/current-user/selectors';
3+
import getUserSetting from 'calypso/state/selectors/get-user-setting';
4+
import isPendingEmailChange from 'calypso/state/selectors/is-pending-email-change';
5+
import { isFetchingUserSettings } from 'calypso/state/user-settings/selectors';
6+
7+
export default function useGetEmailToVerify() {
8+
const isVerified = useSelector( isCurrentUserEmailVerified );
9+
const isEmailChangePending = useSelector( isPendingEmailChange );
10+
const settingsKey = isEmailChangePending ? 'new_user_email' : 'user_email';
11+
const email = useSelector( ( state ) => getUserSetting( state, settingsKey ) );
12+
const isFetchingEmail = useSelector( ( state ) => isFetchingUserSettings( state ) );
13+
14+
if ( isFetchingEmail || ( isVerified && ! isEmailChangePending ) ) {
15+
return null;
16+
}
17+
18+
return email;
19+
}

client/me/account/main.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { clearStore } from 'calypso/lib/user/store';
3333
import wpcom from 'calypso/lib/wp';
3434
import AccountEmailField from 'calypso/me/account/account-email-field';
3535
import { withDefaultInterface } from 'calypso/me/account/with-default-interface';
36-
import EmailVerificationBanner from 'calypso/me/email-verification-banner';
36+
import { EmailVerificationBannerV2 } from 'calypso/me/email-verification-banner';
3737
import ReauthRequired from 'calypso/me/reauth-required';
3838
import { recordGoogleEvent, recordTracksEvent } from 'calypso/state/analytics/actions';
3939
import {
@@ -100,6 +100,7 @@ class Account extends Component {
100100
formsSubmitting: {},
101101
usernameAction: 'new',
102102
validationResult: false,
103+
accountSubmitDisable: false,
103104
};
104105

105106
componentDidUpdate() {
@@ -533,6 +534,7 @@ class Account extends Component {
533534

534535
shouldDisableAccountSubmitButton() {
535536
return (
537+
this.state.accountSubmitDisable ||
536538
! this.hasUnsavedUserSettings( ACCOUNT_FIELDS ) ||
537539
this.getDisabledState( ACCOUNT_FORM_NAME ) ||
538540
this.hasEmailValidationError()
@@ -895,7 +897,11 @@ class Account extends Component {
895897
}
896898
) }
897899
/>
898-
<EmailVerificationBanner />
900+
<EmailVerificationBannerV2
901+
setIsBusy={ ( isBusy ) => {
902+
this.state.accountSubmitDisable = isBusy;
903+
} }
904+
/>
899905
<SectionHeader label={ translate( 'Account Information' ) } />
900906
<Card className="account__settings">
901907
<form onChange={ markChanged } onSubmit={ this.saveAccountSettings }>

client/me/email-verification-banner/index.tsx

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { useTranslate } from 'i18n-calypso';
2-
import { useState } from 'react';
1+
import { Substitution, useTranslate } from 'i18n-calypso';
2+
import React, { useCallback, useState } from 'react';
33
import Banner from 'calypso/components/banner';
44
import EmailVerificationDialog from 'calypso/components/email-verification/email-verification-dialog';
5-
import { useSelector } from 'calypso/state';
5+
import useGetEmailToVerify from 'calypso/components/email-verification/hooks/use-get-email-to-verify';
6+
import { emailFormEventEmitter } from 'calypso/me/account/account-email-field';
7+
import { useDispatch, useSelector } from 'calypso/state';
68
import { isCurrentUserEmailVerified } from 'calypso/state/current-user/selectors';
9+
import { errorNotice, successNotice } from 'calypso/state/notices/actions';
710
import isPendingEmailChange from 'calypso/state/selectors/is-pending-email-change';
8-
11+
import { setUserSetting } from 'calypso/state/user-settings/actions';
12+
import { saveUnsavedUserSettings } from 'calypso/state/user-settings/thunks';
913
import './style.scss';
1014

1115
const EmailVerificationBanner: React.FC< {
@@ -54,4 +58,79 @@ const EmailVerificationBanner: React.FC< {
5458
);
5559
};
5660

61+
interface Props {
62+
setIsBusy: ( isBusy: boolean ) => void;
63+
}
64+
65+
const EmailVerificationBannerV2: React.FC< Props > = ( { setIsBusy } ) => {
66+
const dispatch = useDispatch();
67+
const translate = useTranslate();
68+
const emailToVerify = useGetEmailToVerify();
69+
const [ isSendingEmail, setIsSendingEmail ] = useState( false );
70+
71+
const highlightEmailInput = useCallback( () => {
72+
emailFormEventEmitter?.dispatchEvent( new Event( 'highlightInput' ) );
73+
}, [] );
74+
75+
const resendEmailToVerify = useCallback( async () => {
76+
setIsBusy( true );
77+
setIsSendingEmail( true );
78+
try {
79+
dispatch( setUserSetting( 'user_email', emailToVerify ) );
80+
await dispatch( saveUnsavedUserSettings( [ 'user_email' ] ) );
81+
dispatch(
82+
successNotice(
83+
translate(
84+
'We sent an email to %(email)s. Please check your inbox to verify your email.',
85+
{
86+
args: { email: emailToVerify as Substitution },
87+
}
88+
)
89+
)
90+
);
91+
} catch ( err ) {
92+
dispatch(
93+
errorNotice(
94+
err instanceof Error
95+
? err.message
96+
: translate( 'There was an error while resending the email. Please try again.' )
97+
)
98+
);
99+
} finally {
100+
setIsBusy( false );
101+
setIsSendingEmail( false );
102+
}
103+
}, [ dispatch, emailToVerify, setIsBusy, translate ] );
104+
105+
if ( ! emailToVerify ) {
106+
return null;
107+
}
108+
109+
const description = translate(
110+
'Check your inbox at {{strong}}%(email)s{{/strong}} for the confirmation email, or click "Resend email" to get a new one.',
111+
{
112+
args: { email: emailToVerify as Substitution },
113+
components: {
114+
strong: <strong className="email-verification-banner__highlight" />,
115+
},
116+
}
117+
);
118+
119+
return (
120+
<Banner
121+
className="email-verification-banner"
122+
icon="notice"
123+
title={ translate( 'Verify your email' ) }
124+
description={ description }
125+
callToAction={ translate( 'Resend email' ) }
126+
onClick={ resendEmailToVerify }
127+
secondaryCallToAction={ translate( 'Update email' ) }
128+
secondaryOnClick={ highlightEmailInput }
129+
disableHref
130+
isBusy={ isSendingEmail }
131+
/>
132+
);
133+
};
134+
135+
export { EmailVerificationBannerV2 };
57136
export default EmailVerificationBanner;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
@import "@wordpress/base-styles/breakpoints";
2+
13
.email-verification-banner {
24
--color-accent: var(--studio-red);
35
--color-accent-60: var(--studio-red-60);
6+
7+
.banner__action {
8+
display: flex;
9+
}
10+
11+
@media (max-width: $break-xlarge) {
12+
.banner__content {
13+
flex-direction: column;
14+
}
15+
.banner__action {
16+
padding-top: 12px;
17+
width: 100%;
18+
justify-content: flex-end;
19+
}
20+
.banner__icons {
21+
align-self: flex-start;
22+
}
23+
}
424
}

0 commit comments

Comments
 (0)