settingsIndex.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. import {useEffect} from 'react';
  2. import type {Theme} from '@emotion/react';
  3. import {css} 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 type {LinkProps} from 'sentry/components/links/link';
  11. import Link from 'sentry/components/links/link';
  12. import LoadingIndicator from 'sentry/components/loadingIndicator';
  13. import Panel from 'sentry/components/panels/panel';
  14. import PanelBody from 'sentry/components/panels/panelBody';
  15. import PanelHeader from 'sentry/components/panels/panelHeader';
  16. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  17. import {IconDocs, IconLock, IconStack, IconSupport} from 'sentry/icons';
  18. import {t} from 'sentry/locale';
  19. import ConfigStore from 'sentry/stores/configStore';
  20. import {space} from 'sentry/styles/space';
  21. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  22. import type {Organization} from 'sentry/types/organization';
  23. import useApi from 'sentry/utils/useApi';
  24. import {useUser} from 'sentry/utils/useUser';
  25. import withLatestContext from 'sentry/utils/withLatestContext';
  26. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  27. const LINKS = {
  28. DOCUMENTATION: 'https://docs.sentry.io/',
  29. DOCUMENTATION_PLATFORMS: 'https://docs.sentry.io/platforms/',
  30. DOCUMENTATION_QUICKSTART: 'https://docs.sentry.io/platform-redirect/?next=/',
  31. DOCUMENTATION_CLI: 'https://docs.sentry.io/cli/',
  32. DOCUMENTATION_API: 'https://docs.sentry.io/api/',
  33. API: '/settings/account/api/',
  34. MANAGE: '/manage/',
  35. FORUM: 'https://forum.sentry.io/',
  36. GITHUB_ISSUES: 'https://github.com/getsentry/sentry/issues',
  37. SERVICE_STATUS: 'https://status.sentry.io/',
  38. };
  39. const HOME_ICON_SIZE = 56;
  40. interface SettingsIndexProps extends RouteComponentProps<{}, {}> {
  41. organization: Organization;
  42. }
  43. function SettingsIndex({organization, ...props}: SettingsIndexProps) {
  44. const api = useApi();
  45. useEffect(() => {
  46. // if there is no org in context, SidebarDropdown uses an org from `withLatestContext`
  47. // (which queries the org index endpoint instead of org details)
  48. // and does not have `access` info
  49. if (organization && typeof organization.access === 'undefined') {
  50. fetchOrganizationDetails(api, organization.slug, {
  51. setActive: true,
  52. loadProjects: true,
  53. });
  54. }
  55. }, [api, organization]);
  56. const user = useUser();
  57. const isSelfHosted = ConfigStore.get('isSelfHosted');
  58. const organizationSettingsUrl =
  59. (organization && `/settings/${organization.slug}/`) || '';
  60. const supportLinkProps = {
  61. isSelfHosted,
  62. organizationSettingsUrl,
  63. };
  64. const myAccount = (
  65. <GridPanel>
  66. <HomePanelHeader>
  67. <HomeLinkIcon to="/settings/account/">
  68. <UserAvatar user={user} size={HOME_ICON_SIZE} />
  69. {t('My Account')}
  70. </HomeLinkIcon>
  71. </HomePanelHeader>
  72. <HomePanelBody>
  73. <h3>{t('Quick links')}:</h3>
  74. <ul>
  75. <li>
  76. <HomeLink to="/settings/account/security/">
  77. {t('Change my password')}
  78. </HomeLink>
  79. </li>
  80. <li>
  81. <HomeLink to="/settings/account/notifications/">
  82. {t('Notification Preferences')}
  83. </HomeLink>
  84. </li>
  85. <li>
  86. <HomeLink to="/settings/account/">{t('Change my avatar')}</HomeLink>
  87. </li>
  88. </ul>
  89. </HomePanelBody>
  90. </GridPanel>
  91. );
  92. const orgSettings = (
  93. <GridPanel>
  94. {!organization && <LoadingIndicator overlay hideSpinner />}
  95. <HomePanelHeader>
  96. <HomeLinkIcon to={organizationSettingsUrl}>
  97. {organization ? (
  98. <OrganizationAvatar organization={organization} size={HOME_ICON_SIZE} />
  99. ) : (
  100. <HomeIconContainer color="green300">
  101. <IconStack size="lg" />
  102. </HomeIconContainer>
  103. )}
  104. <OrganizationName>
  105. {organization ? organization.slug : t('No Organization')}
  106. </OrganizationName>
  107. </HomeLinkIcon>
  108. </HomePanelHeader>
  109. <HomePanelBody>
  110. <h3>{t('Quick links')}:</h3>
  111. <ul>
  112. <li>
  113. <HomeLink to={`${organizationSettingsUrl}projects/`}>
  114. {t('Projects')}
  115. </HomeLink>
  116. </li>
  117. <li>
  118. <HomeLink to={`${organizationSettingsUrl}teams/`}>{t('Teams')}</HomeLink>
  119. </li>
  120. <li>
  121. <HomeLink to={`${organizationSettingsUrl}members/`}>{t('Members')}</HomeLink>
  122. </li>
  123. </ul>
  124. </HomePanelBody>
  125. </GridPanel>
  126. );
  127. const documentation = (
  128. <GridPanel>
  129. <HomePanelHeader>
  130. <ExternalHomeLinkIcon href={LINKS.DOCUMENTATION}>
  131. <HomeIconContainer color="pink300">
  132. <IconDocs size="lg" />
  133. </HomeIconContainer>
  134. {t('Documentation')}
  135. </ExternalHomeLinkIcon>
  136. </HomePanelHeader>
  137. <HomePanelBody>
  138. <h3>{t('Quick links')}:</h3>
  139. <ul>
  140. <li>
  141. <ExternalHomeLink href={LINKS.DOCUMENTATION_QUICKSTART}>
  142. {t('Quickstart Guide')}
  143. </ExternalHomeLink>
  144. </li>
  145. <li>
  146. <ExternalHomeLink href={LINKS.DOCUMENTATION_PLATFORMS}>
  147. {t('Platforms & Frameworks')}
  148. </ExternalHomeLink>
  149. </li>
  150. <li>
  151. <ExternalHomeLink href={LINKS.DOCUMENTATION_CLI}>
  152. {t('Sentry CLI')}
  153. </ExternalHomeLink>
  154. </li>
  155. </ul>
  156. </HomePanelBody>
  157. </GridPanel>
  158. );
  159. const support = (
  160. <GridPanel>
  161. <HomePanelHeader>
  162. <SupportLink icon {...supportLinkProps}>
  163. <HomeIconContainer color="activeText">
  164. <IconSupport size="lg" />
  165. </HomeIconContainer>
  166. {t('Support')}
  167. </SupportLink>
  168. </HomePanelHeader>
  169. <HomePanelBody>
  170. <h3>{t('Quick links')}:</h3>
  171. <ul>
  172. <li>
  173. <SupportLink {...supportLinkProps}>
  174. {isSelfHosted ? t('Community Forums') : t('Contact Support')}
  175. </SupportLink>
  176. </li>
  177. <li>
  178. <ExternalHomeLink href={LINKS.GITHUB_ISSUES}>
  179. {t('Sentry on GitHub')}
  180. </ExternalHomeLink>
  181. </li>
  182. <li>
  183. <ExternalHomeLink href={LINKS.SERVICE_STATUS}>
  184. {t('Service Status')}
  185. </ExternalHomeLink>
  186. </li>
  187. </ul>
  188. </HomePanelBody>
  189. </GridPanel>
  190. );
  191. const apiKeys = (
  192. <GridPanel>
  193. <HomePanelHeader>
  194. <HomeLinkIcon to={LINKS.API}>
  195. <HomeIconContainer>
  196. <IconLock size="lg" locked />
  197. </HomeIconContainer>
  198. {t('API Keys')}
  199. </HomeLinkIcon>
  200. </HomePanelHeader>
  201. <HomePanelBody>
  202. <h3>{t('Quick links')}:</h3>
  203. <ul>
  204. <li>
  205. <HomeLink to={`${organizationSettingsUrl}auth-tokens/`}>
  206. {t('Organization Auth Tokens')}
  207. </HomeLink>
  208. </li>
  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. `;