Skip to content
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

feat(organizations): disable email updates for regular organization members TASK-997 #5233

Merged
merged 11 commits into from
Nov 21, 2024
153 changes: 80 additions & 73 deletions jsapp/js/account/security/email/emailSection.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {formatTime, notify} from 'js/utils';
// Styles
import styles from './emailSection.module.scss';
import securityStyles from 'js/account/security/securityRoute.module.scss';
import {useOrganizationQuery} from 'js/account/stripe.api';

interface EmailState {
emails: EmailResponse[];
Expand All @@ -33,6 +34,8 @@ interface EmailState {
export default function EmailSection() {
const [session] = useState(() => sessionStore);

const orgQuery = useOrganizationQuery();

let initialEmail = '';
if ('email' in session.currentAccount) {
initialEmail = session.currentAccount.email;
Expand Down Expand Up @@ -116,6 +119,11 @@ export default function EmailSection() {
const unverifiedEmail = email.emails.find(
(userEmail) => !userEmail.verified && !userEmail.primary
);
const isReady = session.isInitialLoadComplete && 'email' in currentAccount;
// Only users who are members in a MMO cannot change their email
const userCanChangeEmail = orgQuery.data?.is_mmo
? orgQuery.data.request_user_role !== 'member'
: true;

return (
<section className={securityStyles.securitySection}>
Expand All @@ -124,82 +132,81 @@ export default function EmailSection() {
</div>

<div className={cx(securityStyles.securitySectionBody, styles.body)}>
{!session.isPending &&
session.isInitialLoadComplete &&
'email' in currentAccount && (
<TextBox
value={email.newEmail}
placeholder={t('Type new email address')}
onChange={onTextFieldChange.bind(onTextFieldChange)}
type='email'
/>
)}

{unverifiedEmail?.email &&
!session.isPending &&
session.isInitialLoadComplete &&
'email' in currentAccount && (
<>
<div className={styles.unverifiedEmail}>
<Icon name='alert' />
<p className={styles.blurb}>
<strong>
{t('Check your email ##UNVERIFIED_EMAIL##. ').replace(
'##UNVERIFIED_EMAIL##',
unverifiedEmail.email
)}
</strong>

{t(
'A verification link has been sent to confirm your ownership. Once confirmed, this address will replace ##UNVERIFIED_EMAIL##'
).replace('##UNVERIFIED_EMAIL##', currentAccount.email)}
</p>
</div>

<div className={styles.unverifiedEmailButtons}>
<Button
label='Resend'
size='m'
type='secondary'
onClick={resendNewUserEmail.bind(
resendNewUserEmail,
{isReady && userCanChangeEmail ? (
<TextBox
value={email.newEmail}
placeholder={t('Type new email address')}
onChange={onTextFieldChange.bind(onTextFieldChange)}
type='email'
/>
) : (
<div className={styles.emailText}>{email.newEmail}</div>
)}

{unverifiedEmail?.email && isReady && (
<>
<div className={styles.unverifiedEmail}>
<Icon name='alert' />
<p className={styles.blurb}>
<strong>
{t('Check your email ##UNVERIFIED_EMAIL##. ').replace(
'##UNVERIFIED_EMAIL##',
unverifiedEmail.email
)}
/>
<Button
label='Remove'
size='m'
type='secondary-danger'
onClick={deleteNewUserEmail}
/>
</div>

{email.refreshedEmail && (
<label>
{t('Email was sent again: ##TIMESTAMP##').replace(
'##TIMESTAMP##',
email.refreshedEmailDate
)}
</label>
)}
</>
)}
</strong>

{t(
'A verification link has been sent to confirm your ownership. Once confirmed, this address will replace ##UNVERIFIED_EMAIL##'
).replace('##UNVERIFIED_EMAIL##', currentAccount.email)}
</p>
</div>

<div className={styles.unverifiedEmailButtons}>
<Button
label='Resend'
size='m'
type='secondary'
onClick={resendNewUserEmail.bind(
resendNewUserEmail,
unverifiedEmail.email
)}
/>
<Button
label='Remove'
size='m'
type='secondary-danger'
onClick={deleteNewUserEmail}
/>
</div>

{email.refreshedEmail && (
<label>
{t('Email was sent again: ##TIMESTAMP##').replace(
'##TIMESTAMP##',
email.refreshedEmailDate
)}
</label>
)}
</>
)}
</div>
<div className={styles.options}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this container div inside the userCanChangeEmail check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a hack, if the container div is inside of the check then the rest of the row CSS gets unaligned. The only way I saw to fix this was to add conditional styling which I thought looked worse than this. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I wondered if that might be the reason. I'd say we should go with conditional CSS. You're right that it will add some more complexity, but I think it will make it easier for other coders working on this section in the future to know what's going on.

{userCanChangeEmail && (
<form
onSubmit={(e) => {
e.preventDefault();
handleSubmit();
}}
>
<Button
label='Change'
size='m'
type='primary'
onClick={handleSubmit}
/>
</form>
)}
</div>

<form
className={styles.options}
onSubmit={(e) => {
e.preventDefault();
handleSubmit();
}}
>
<Button
label='Change'
size='m'
type='primary'
onClick={handleSubmit}
/>
</form>
</section>
);
}
4 changes: 4 additions & 0 deletions jsapp/js/account/security/email/emailSection.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
display: flex;
gap: 10px;
}

.emailText {
font-weight: 600;
}
Loading