import {Fragment} from 'react'; import styled from '@emotion/styled'; import {addErrorMessage} from 'sentry/actionCreators/indicator'; import {RequestOptions} from 'sentry/api'; import AlertLink from 'sentry/components/alertLink'; import AsyncComponent from 'sentry/components/asyncComponent'; import Button from 'sentry/components/button'; import ButtonBar from 'sentry/components/buttonBar'; import Form from 'sentry/components/forms/form'; import JsonForm from 'sentry/components/forms/jsonForm'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import {Panel, PanelBody, PanelHeader, PanelItem} from 'sentry/components/panels'; import Tag from 'sentry/components/tag'; import accountEmailsFields from 'sentry/data/forms/accountEmails'; import {IconDelete, IconStack} from 'sentry/icons'; import {t} from 'sentry/locale'; import space from 'sentry/styles/space'; import {UserEmail} from 'sentry/types'; import AsyncView from 'sentry/views/asyncView'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; const ENDPOINT = '/users/me/emails/'; type Props = AsyncView['props']; type State = AsyncView['state'] & { emails: UserEmail[]; }; class AccountEmails extends AsyncView { getTitle() { return t('Emails'); } getEndpoints() { return []; } handleSubmitSuccess: Form['props']['onSubmitSuccess'] = (_change, model, id) => { if (id === undefined) { return; } model.setValue(id, ''); this.remountComponent(); }; renderBody() { return (
}> {t('Want to change how many emails you get? Use the notifications panel.')}
); } } export default AccountEmails; export class EmailAddresses extends AsyncComponent { getEndpoints(): ReturnType { return [['emails', ENDPOINT]]; } doApiCall(endpoint: string, requestParams: RequestOptions) { this.setState({loading: true, emails: []}, () => this.api .requestPromise(endpoint, requestParams) .then(() => this.remountComponent()) .catch(err => { this.remountComponent(); if (err?.responseJSON?.email) { addErrorMessage(err.responseJSON.email); } }) ); } handleSetPrimary = (email: string) => this.doApiCall(ENDPOINT, { method: 'PUT', data: {email}, }); handleRemove = (email: string) => this.doApiCall(ENDPOINT, { method: 'DELETE', data: {email}, }); handleVerify = (email: string) => this.doApiCall(`${ENDPOINT}confirm/`, { method: 'POST', data: {email}, }); render() { const {emails, loading} = this.state; const primary = emails?.find(({isPrimary}) => isPrimary); const secondary = emails?.filter(({isPrimary}) => !isPrimary); if (loading) { return ( {t('Email Addresses')} ); } return ( {t('Email Addresses')} {primary && ( )} {secondary?.map(emailObj => ( ))} ); } } type EmailRowProps = { email: string; onRemove: (email: string, e: React.MouseEvent) => void; onVerify: (email: string, e: React.MouseEvent) => void; hideRemove?: boolean; isPrimary?: boolean; isVerified?: boolean; onSetPrimary?: (email: string, e: React.MouseEvent) => void; }; const EmailRow = ({ email, onRemove, onVerify, onSetPrimary, isVerified, isPrimary, hideRemove, }: EmailRowProps) => ( {email} {!isVerified && {t('Unverified')}} {isPrimary && {t('Primary')}} {!isPrimary && isVerified && ( )} {!isVerified && ( )} {!hideRemove && !isPrimary && (