settingsIndex.tsx 9.7 KB

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