settingsIndex.tsx 9.8 KB

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