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 {Button} from 'sentry/components/button'; import ButtonBar from 'sentry/components/buttonBar'; import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent'; import Form, {FormProps} from 'sentry/components/forms/form'; import JsonForm from 'sentry/components/forms/jsonForm'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import Panel from 'sentry/components/panels/panel'; import PanelBody from 'sentry/components/panels/panelBody'; import PanelHeader from 'sentry/components/panels/panelHeader'; import PanelItem from 'sentry/components/panels/panelItem'; 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 DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; const ENDPOINT = '/users/me/emails/'; type Props = DeprecatedAsyncView['props']; type State = DeprecatedAsyncView['state'] & { emails: UserEmail[]; }; class AccountEmails extends DeprecatedAsyncView { getTitle() { return t('Emails'); } getEndpoints() { return []; } handleSubmitSuccess: FormProps['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 DeprecatedAsyncComponent { 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; }; function EmailRow({ email, onRemove, onVerify, onSetPrimary, isVerified, isPrimary, hideRemove, }: EmailRowProps) { return ( {email} {!isVerified && {t('Unverified')}} {isPrimary && {t('Primary')}} {!isPrimary && isVerified && ( )} {!isVerified && ( )} {!hideRemove && !isPrimary && (