settingsIndex.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. import {useEffect} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import {css, Theme} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import {fetchOrganizationDetails} from 'sentry/actionCreators/organizations';
  6. import DemoModeGate from 'sentry/components/acl/demoModeGate';
  7. import OrganizationAvatar from 'sentry/components/avatar/organizationAvatar';
  8. import UserAvatar from 'sentry/components/avatar/userAvatar';
  9. import ExternalLink from 'sentry/components/links/externalLink';
  10. import Link, {LinkProps} from 'sentry/components/links/link';
  11. import LoadingIndicator from 'sentry/components/loadingIndicator';
  12. import Panel from 'sentry/components/panels/panel';
  13. import PanelBody from 'sentry/components/panels/panelBody';
  14. import PanelHeader from 'sentry/components/panels/panelHeader';
  15. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  16. import {IconDocs, IconLock, IconStack, IconSupport} from 'sentry/icons';
  17. import {t} from 'sentry/locale';
  18. import ConfigStore from 'sentry/stores/configStore';
  19. import {space} from 'sentry/styles/space';
  20. import {Organization} from 'sentry/types';
  21. import useApi from 'sentry/utils/useApi';
  22. import withLatestContext from 'sentry/utils/withLatestContext';
  23. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  24. const LINKS = {
  25. DOCUMENTATION: 'https://docs.sentry.io/',
  26. DOCUMENTATION_PLATFORMS: 'https://docs.sentry.io/platforms/',
  27. DOCUMENTATION_QUICKSTART: 'https://docs.sentry.io/platform-redirect/?next=/',
  28. DOCUMENTATION_CLI: 'https://docs.sentry.io/product/cli/',
  29. DOCUMENTATION_API: 'https://docs.sentry.io/api/',
  30. API: '/settings/account/api/',
  31. MANAGE: '/manage/',
  32. FORUM: 'https://forum.sentry.io/',
  33. GITHUB_ISSUES: 'https://github.com/getsentry/sentry/issues',
  34. SERVICE_STATUS: 'https://status.sentry.io/',
  35. };
  36. const HOME_ICON_SIZE = 56;
  37. interface SettingsIndexProps extends RouteComponentProps<{}, {}> {
  38. organization: Organization;
  39. }
  40. function SettingsIndex({organization, ...props}: SettingsIndexProps) {
  41. const api = useApi();
  42. useEffect(() => {
  43. // if there is no org in context, SidebarDropdown uses an org from `withLatestContext`
  44. // (which queries the org index endpoint instead of org details)
  45. // and does not have `access` info
  46. if (organization && typeof organization.access === 'undefined') {
  47. fetchOrganizationDetails(api, organization.slug, {
  48. setActive: true,
  49. loadProjects: true,
  50. });
  51. }
  52. }, [api, organization]);
  53. const user = ConfigStore.get('user');
  54. const isSelfHosted = ConfigStore.get('isSelfHosted');
  55. const organizationSettingsUrl =
  56. (organization && `/settings/${organization.slug}/`) || '';
  57. const supportLinkProps = {
  58. isSelfHosted,
  59. organizationSettingsUrl,
  60. };
  61. const myAccount = (
  62. <GridPanel>
  63. <HomePanelHeader>
  64. <HomeLinkIcon to="/settings/account/">
  65. <UserAvatar user={user} size={HOME_ICON_SIZE} />
  66. {t('My Account')}
  67. </HomeLinkIcon>
  68. </HomePanelHeader>
  69. <HomePanelBody>
  70. <h3>{t('Quick links')}:</h3>
  71. <ul>
  72. <li>
  73. <HomeLink to="/settings/account/security/">
  74. {t('Change my password')}
  75. </HomeLink>
  76. </li>
  77. <li>
  78. <HomeLink to="/settings/account/notifications/">
  79. {t('Notification Preferences')}
  80. </HomeLink>
  81. </li>
  82. <li>
  83. <HomeLink to="/settings/account/">{t('Change my avatar')}</HomeLink>
  84. </li>
  85. </ul>
  86. </HomePanelBody>
  87. </GridPanel>
  88. );
  89. const orgSettings = (
  90. <GridPanel>
  91. {!organization && <LoadingIndicator overlay hideSpinner />}
  92. <HomePanelHeader>
  93. <HomeLinkIcon to={organizationSettingsUrl}>
  94. {organization ? (
  95. <OrganizationAvatar organization={organization} size={HOME_ICON_SIZE} />
  96. ) : (
  97. <HomeIconContainer color="green300">
  98. <IconStack size="lg" />
  99. </HomeIconContainer>
  100. )}
  101. <OrganizationName>
  102. {organization ? organization.slug : t('No Organization')}
  103. </OrganizationName>
  104. </HomeLinkIcon>
  105. </HomePanelHeader>
  106. <HomePanelBody>
  107. <h3>{t('Quick links')}:</h3>
  108. <ul>
  109. <li>
  110. <HomeLink to={`${organizationSettingsUrl}projects/`}>
  111. {t('Projects')}
  112. </HomeLink>
  113. </li>
  114. <li>
  115. <HomeLink to={`${organizationSettingsUrl}teams/`}>{t('Teams')}</HomeLink>
  116. </li>
  117. <li>
  118. <HomeLink to={`${organizationSettingsUrl}members/`}>{t('Members')}</HomeLink>
  119. </li>
  120. </ul>
  121. </HomePanelBody>
  122. </GridPanel>
  123. );
  124. const documentation = (
  125. <GridPanel>
  126. <HomePanelHeader>
  127. <ExternalHomeLinkIcon href={LINKS.DOCUMENTATION}>
  128. <HomeIconContainer color="pink300">
  129. <IconDocs size="lg" />
  130. </HomeIconContainer>
  131. {t('Documentation')}
  132. </ExternalHomeLinkIcon>
  133. </HomePanelHeader>
  134. <HomePanelBody>
  135. <h3>{t('Quick links')}:</h3>
  136. <ul>
  137. <li>
  138. <ExternalHomeLink href={LINKS.DOCUMENTATION_QUICKSTART}>
  139. {t('Quickstart Guide')}
  140. </ExternalHomeLink>
  141. </li>
  142. <li>
  143. <ExternalHomeLink href={LINKS.DOCUMENTATION_PLATFORMS}>
  144. {t('Platforms & Frameworks')}
  145. </ExternalHomeLink>
  146. </li>
  147. <li>
  148. <ExternalHomeLink href={LINKS.DOCUMENTATION_CLI}>
  149. {t('Sentry CLI')}
  150. </ExternalHomeLink>
  151. </li>
  152. </ul>
  153. </HomePanelBody>
  154. </GridPanel>
  155. );
  156. const support = (
  157. <GridPanel>
  158. <HomePanelHeader>
  159. <SupportLink icon {...supportLinkProps}>
  160. <HomeIconContainer color="activeText">
  161. <IconSupport size="lg" />
  162. </HomeIconContainer>
  163. {t('Support')}
  164. </SupportLink>
  165. </HomePanelHeader>
  166. <HomePanelBody>
  167. <h3>{t('Quick links')}:</h3>
  168. <ul>
  169. <li>
  170. <SupportLink {...supportLinkProps}>
  171. {isSelfHosted ? t('Community Forums') : t('Contact Support')}
  172. </SupportLink>
  173. </li>
  174. <li>
  175. <ExternalHomeLink href={LINKS.GITHUB_ISSUES}>
  176. {t('Sentry on GitHub')}
  177. </ExternalHomeLink>
  178. </li>
  179. <li>
  180. <ExternalHomeLink href={LINKS.SERVICE_STATUS}>
  181. {t('Service Status')}
  182. </ExternalHomeLink>
  183. </li>
  184. </ul>
  185. </HomePanelBody>
  186. </GridPanel>
  187. );
  188. const apiKeys = (
  189. <GridPanel>
  190. <HomePanelHeader>
  191. <HomeLinkIcon to={LINKS.API}>
  192. <HomeIconContainer>
  193. <IconLock size="lg" isSolid />
  194. </HomeIconContainer>
  195. {t('API Keys')}
  196. </HomeLinkIcon>
  197. </HomePanelHeader>
  198. <HomePanelBody>
  199. <h3>{t('Quick links')}:</h3>
  200. <ul>
  201. <li>
  202. <HomeLink to={`${organizationSettingsUrl}auth-tokens/`}>
  203. {t('Organization Auth Tokens')}
  204. </HomeLink>
  205. </li>
  206. <li>
  207. <HomeLink to={LINKS.API}>{t('User Auth Tokens')}</HomeLink>
  208. </li>
  209. <li>
  210. <HomeLink to={`${organizationSettingsUrl}developer-settings/`}>
  211. {t('Custom Integrations')}
  212. </HomeLink>
  213. </li>
  214. <li>
  215. <ExternalHomeLink href={LINKS.DOCUMENTATION_API}>
  216. {t('Documentation')}
  217. </ExternalHomeLink>
  218. </li>
  219. </ul>
  220. </HomePanelBody>
  221. </GridPanel>
  222. );
  223. return (
  224. <SentryDocumentTitle
  225. title={organization ? `${organization.slug} Settings` : 'Settings'}
  226. >
  227. <SettingsLayout {...props}>
  228. <GridLayout>
  229. <DemoModeGate>{myAccount}</DemoModeGate>
  230. {orgSettings}
  231. {documentation}
  232. {support}
  233. <DemoModeGate>{apiKeys} </DemoModeGate>
  234. </GridLayout>
  235. </SettingsLayout>
  236. </SentryDocumentTitle>
  237. );
  238. }
  239. export default withLatestContext(SettingsIndex);
  240. const GridLayout = styled('div')`
  241. display: grid;
  242. grid-template-columns: 1fr 1fr 1fr;
  243. gap: ${space(2)};
  244. `;
  245. const GridPanel = styled(Panel)`
  246. margin-bottom: 0;
  247. `;
  248. const HomePanelHeader = styled(PanelHeader)`
  249. background: ${p => p.theme.background};
  250. font-size: ${p => p.theme.fontSizeExtraLarge};
  251. align-items: center;
  252. text-transform: unset;
  253. padding: ${space(4)};
  254. `;
  255. const HomePanelBody = styled(PanelBody)`
  256. padding: 30px;
  257. h3 {
  258. font-size: 14px;
  259. }
  260. ul {
  261. margin: 0;
  262. li {
  263. line-height: 1.6;
  264. /* Bullet color */
  265. color: ${p => p.theme.gray200};
  266. }
  267. }
  268. `;
  269. const HomeIconContainer = styled('div')<{color?: string}>`
  270. background: ${p => p.theme[p.color || 'gray300']};
  271. color: ${p => p.theme.white};
  272. width: ${HOME_ICON_SIZE}px;
  273. height: ${HOME_ICON_SIZE}px;
  274. border-radius: ${HOME_ICON_SIZE}px;
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. `;
  279. const linkCss = ({theme}: {theme: Theme}) => css`
  280. color: ${theme.activeText};
  281. &:hover {
  282. color: ${theme.activeText};
  283. }
  284. `;
  285. const linkIconCss = css`
  286. overflow: hidden;
  287. width: 100%;
  288. display: grid;
  289. grid-template-rows: max-content max-content;
  290. gap: ${space(1.5)};
  291. align-items: center;
  292. justify-items: center;
  293. justify-content: center;
  294. `;
  295. const HomeLink = styled(Link)`
  296. ${linkCss}
  297. `;
  298. const ExternalHomeLink = styled(ExternalLink)`
  299. ${linkCss}
  300. `;
  301. const HomeLinkIcon = styled(HomeLink)`
  302. ${linkIconCss}
  303. `;
  304. const ExternalHomeLinkIcon = styled(ExternalLink)`
  305. ${linkIconCss}
  306. `;
  307. interface SupportLinkProps extends Omit<LinkProps, 'ref' | 'to'> {
  308. isSelfHosted: boolean;
  309. organizationSettingsUrl: string;
  310. icon?: boolean;
  311. }
  312. function SupportLink({
  313. isSelfHosted,
  314. icon,
  315. organizationSettingsUrl,
  316. ...props
  317. }: SupportLinkProps) {
  318. if (isSelfHosted) {
  319. const SelfHostedLink = icon ? ExternalHomeLinkIcon : ExternalHomeLink;
  320. return <SelfHostedLink href={LINKS.FORUM} {...props} />;
  321. }
  322. const SelfHostedLink = icon ? HomeLinkIcon : HomeLink;
  323. return <SelfHostedLink to={`${organizationSettingsUrl}support`} {...props} />;
  324. }
  325. const OrganizationName = styled('div')`
  326. line-height: 1.1em;
  327. ${p => p.theme.overflowEllipsis};
  328. `;