settingsIndex.tsx 10 KB

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