mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
FSL-1.0-Apache-2.0 grants us the code, not the name. "Sentry" is Functional Software's trademark, so every place the running app says it to a user -- page titles, onboarding, empty states, toasts, settings copy, the self-hosted footer -- now says Sentinel. Attribution is the other half of the deal and stays untouched: upstream copyright headers, LICENSE, NOTICE. So does anything where the mark is a fact rather than a brand -- @sentry/* packages, sentry-cli, the wizard and bundler plugins, docs.sentry.io, the whole gettingStartedDocs tree. Renaming those would leave instructions that no longer work. Nothing structural moved. No import, identifier, route path, feature flag, API field or test id changed; the diff is 312 lines in and 312 out. Colocated specs were updated in lockstep with the copy they assert. Marketing and community links point at hanzo.ai, only where a real page exists to point at. Co-authored-by: Hanzo Dev <[email protected]>
241 lines
8.0 KiB
TypeScript
241 lines
8.0 KiB
TypeScript
import {Fragment} from 'react';
|
||
import styled from '@emotion/styled';
|
||
import groupBy from 'lodash/groupBy';
|
||
import orderBy from 'lodash/orderBy';
|
||
import moment from 'moment';
|
||
|
||
import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
|
||
import DateTime from 'sentry/components/dateTime';
|
||
import EmptyMessage from 'sentry/components/emptyMessage';
|
||
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 Switch from 'sentry/components/switchButton';
|
||
import {IconToggle} from 'sentry/icons';
|
||
import {t, tct} from 'sentry/locale';
|
||
import {space} from 'sentry/styles/space';
|
||
import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
|
||
import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
|
||
import TextBlock from 'sentry/views/settings/components/text/textBlock';
|
||
|
||
const ENDPOINT = '/users/me/subscriptions/';
|
||
|
||
export type Subscription = {
|
||
email: string;
|
||
listDescription: string;
|
||
listId: number;
|
||
listName: string;
|
||
subscribed: boolean;
|
||
subscribedDate: string | null;
|
||
unsubscribedDate: string | null;
|
||
};
|
||
|
||
type State = DeprecatedAsyncView['state'] & {
|
||
subscriptions: Subscription[];
|
||
};
|
||
|
||
class AccountSubscriptions extends DeprecatedAsyncView<
|
||
DeprecatedAsyncView['props'],
|
||
State
|
||
> {
|
||
getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
|
||
return [['subscriptions', ENDPOINT]];
|
||
}
|
||
|
||
getTitle() {
|
||
return t('Subscriptions');
|
||
}
|
||
|
||
handleToggle = (
|
||
subscription: Subscription,
|
||
email: string,
|
||
listId: number,
|
||
_e: React.MouseEvent
|
||
) => {
|
||
const subscribed = !subscription.subscribed;
|
||
const oldSubscriptions = this.state.subscriptions;
|
||
|
||
this.setState(state => {
|
||
const newSubscriptions = [...state.subscriptions];
|
||
const index = newSubscriptions.findIndex(
|
||
sub => sub.listId === listId && sub.email === email
|
||
);
|
||
newSubscriptions[index] = {
|
||
...subscription,
|
||
subscribed,
|
||
subscribedDate: new Date().toString(),
|
||
};
|
||
return {
|
||
...state,
|
||
subscriptions: newSubscriptions,
|
||
};
|
||
});
|
||
|
||
this.api.request(ENDPOINT, {
|
||
method: 'PUT',
|
||
data: {
|
||
listId: subscription.listId,
|
||
subscribed,
|
||
},
|
||
success: () => {
|
||
addSuccessMessage(
|
||
`${subscribed ? 'Subscribed' : 'Unsubscribed'} to ${subscription.listName}`
|
||
);
|
||
},
|
||
error: () => {
|
||
addErrorMessage(
|
||
`Unable to ${subscribed ? '' : 'un'}subscribe to ${subscription.listName}`
|
||
);
|
||
this.setState({subscriptions: oldSubscriptions});
|
||
},
|
||
});
|
||
};
|
||
|
||
renderBody() {
|
||
// Group by does not guarantee order, so we sort by email
|
||
const subGroups = orderBy(
|
||
Object.entries(groupBy(this.state.subscriptions, sub => sub.email)),
|
||
([email]) => email
|
||
);
|
||
|
||
return (
|
||
<div>
|
||
<SettingsPageHeader title={this.getTitle()} />
|
||
<TextBlock>
|
||
{t(`Sentinel is committed to respecting your inbox. Our goal is to
|
||
provide useful content and resources that make fixing errors less
|
||
painful. Enjoyable even.`)}
|
||
</TextBlock>
|
||
|
||
<TextBlock>
|
||
{t(`As part of our compliance with the EU’s General Data Protection
|
||
Regulation (GDPR), starting on 25 May 2018, we’ll only email you
|
||
according to the marketing categories to which you’ve explicitly
|
||
opted-in.`)}
|
||
</TextBlock>
|
||
|
||
<Panel>
|
||
{this.state.subscriptions.length ? (
|
||
<div>
|
||
<PanelHeader>{t('Subscription')}</PanelHeader>
|
||
<PanelBody>
|
||
{subGroups.map(([email, subscriptions]) => (
|
||
<Fragment key={email}>
|
||
{subGroups.length > 1 && (
|
||
<Heading>
|
||
<IconToggle /> {t('Subscriptions for %s', email)}
|
||
</Heading>
|
||
)}
|
||
|
||
{subscriptions
|
||
.sort((a, b) => a.listId - b.listId)
|
||
.map(subscription => (
|
||
<PanelItem center key={subscription.listId}>
|
||
<SubscriptionDetails
|
||
htmlFor={`${subscription.email}-${subscription.listId}`}
|
||
aria-label={subscription.listName}
|
||
>
|
||
<SubscriptionName>{subscription.listName}</SubscriptionName>
|
||
{subscription.listDescription && (
|
||
<Description>{subscription.listDescription}</Description>
|
||
)}
|
||
{subscription.subscribed ? (
|
||
<SubscribedDescription>
|
||
<div>
|
||
{tct('[email] on [date]', {
|
||
email: subscription.email,
|
||
date: (
|
||
<DateTime
|
||
date={moment(subscription.subscribedDate!)}
|
||
/>
|
||
),
|
||
})}
|
||
</div>
|
||
</SubscribedDescription>
|
||
) : (
|
||
<SubscribedDescription>
|
||
{t('Not currently subscribed')}
|
||
</SubscribedDescription>
|
||
)}
|
||
</SubscriptionDetails>
|
||
<div>
|
||
<Switch
|
||
id={`${subscription.email}-${subscription.listId}`}
|
||
isActive={subscription.subscribed}
|
||
size="lg"
|
||
toggle={this.handleToggle.bind(
|
||
this,
|
||
subscription,
|
||
email,
|
||
subscription.listId
|
||
)}
|
||
/>
|
||
</div>
|
||
</PanelItem>
|
||
))}
|
||
</Fragment>
|
||
))}
|
||
</PanelBody>
|
||
</div>
|
||
) : (
|
||
<EmptyMessage>{t("There's no subscription backend present.")}</EmptyMessage>
|
||
)}
|
||
</Panel>
|
||
<TextBlock>
|
||
{t(`We’re applying GDPR consent and privacy policies to all Sentinel
|
||
contacts, regardless of location. You’ll be able to manage your
|
||
subscriptions here and from an Unsubscribe link in the footer of
|
||
all marketing emails.`)}
|
||
</TextBlock>
|
||
|
||
<TextBlock>
|
||
{tct(
|
||
'Please contact [email:[email protected]] with any questions or suggestions.',
|
||
{email: <a href="mailto:[email protected]" />}
|
||
)}
|
||
</TextBlock>
|
||
</div>
|
||
);
|
||
}
|
||
}
|
||
|
||
const Heading = styled(PanelItem)`
|
||
display: grid;
|
||
grid-template-columns: max-content 1fr;
|
||
gap: ${space(1)};
|
||
align-items: center;
|
||
font-size: ${p => p.theme.fontSizeMedium};
|
||
padding: ${space(1.5)} ${space(2)};
|
||
background: ${p => p.theme.backgroundSecondary};
|
||
color: ${p => p.theme.subText};
|
||
`;
|
||
|
||
const SubscriptionDetails = styled('label')`
|
||
font-weight: initial;
|
||
padding-right: ${space(2)};
|
||
width: 85%;
|
||
|
||
@media (min-width: ${p => p.theme.breakpoints.small}) {
|
||
width: 75%;
|
||
}
|
||
@media (min-width: ${p => p.theme.breakpoints.large}) {
|
||
width: 50%;
|
||
}
|
||
`;
|
||
|
||
const SubscriptionName = styled('div')`
|
||
font-size: ${p => p.theme.fontSizeMedium};
|
||
`;
|
||
const Description = styled('div')`
|
||
font-size: ${p => p.theme.fontSizeSmall};
|
||
color: ${p => p.theme.subText};
|
||
margin-top: ${space(0.5)};
|
||
`;
|
||
|
||
const SubscribedDescription = styled(Description)`
|
||
color: ${p => p.theme.subText};
|
||
`;
|
||
|
||
export default AccountSubscriptions;
|