settingsIndex.tsx 10 KB

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