settingsIndex.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 useApi from 'sentry/utils/useApi';
  21. import withLatestContext from 'sentry/utils/withLatestContext';
  22. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  23. const LINKS = {
  24. DOCUMENTATION: 'https://docs.sentry.io/',
  25. DOCUMENTATION_PLATFORMS: 'https://docs.sentry.io/platforms/',
  26. DOCUMENTATION_QUICKSTART: 'https://docs.sentry.io/platform-redirect/?next=/',
  27. DOCUMENTATION_CLI: 'https://docs.sentry.io/product/cli/',
  28. DOCUMENTATION_API: 'https://docs.sentry.io/api/',
  29. API: '/settings/account/api/',
  30. MANAGE: '/manage/',
  31. FORUM: 'https://forum.sentry.io/',
  32. GITHUB_ISSUES: 'https://github.com/getsentry/sentry/issues',
  33. SERVICE_STATUS: 'https://status.sentry.io/',
  34. };
  35. const HOME_ICON_SIZE = 56;
  36. interface SettingsIndexProps extends RouteComponentProps<{}, {}> {
  37. organization: Organization;
  38. }
  39. function SettingsIndex({organization, ...props}: SettingsIndexProps) {
  40. const api = useApi();
  41. useEffect(() => {
  42. // if there is no org in context, SidebarDropdown uses an org from `withLatestContext`
  43. // (which queries the org index endpoint instead of org details)
  44. // and does not have `access` info
  45. if (organization && typeof organization.access === 'undefined') {
  46. fetchOrganizationDetails(api, organization.slug, {
  47. setActive: true,
  48. loadProjects: true,
  49. });
  50. }
  51. }, [api, organization]);
  52. const user = ConfigStore.get('user');
  53. const isSelfHosted = ConfigStore.get('isSelfHosted');
  54. const organizationSettingsUrl =
  55. (organization && `/settings/${organization.slug}/`) || '';
  56. const supportLinkProps = {
  57. isSelfHosted,
  58. organizationSettingsUrl,
  59. };
  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="purple300">
  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. <li>
  201. <HomeLink to={LINKS.API}>{t('Auth Tokens')}</HomeLink>
  202. </li>
  203. <li>
  204. <HomeLink to={`${organizationSettingsUrl}developer-settings/`}>
  205. {t('Your Integrations')}
  206. </HomeLink>
  207. </li>
  208. <li>
  209. <ExternalHomeLink href={LINKS.DOCUMENTATION_API}>
  210. {t('Documentation')}
  211. </ExternalHomeLink>
  212. </li>
  213. </ul>
  214. </HomePanelBody>
  215. </GridPanel>
  216. );
  217. return (
  218. <SentryDocumentTitle
  219. title={organization ? `${organization.slug} Settings` : 'Settings'}
  220. >
  221. <SettingsLayout {...props}>
  222. <GridLayout>
  223. <DemoModeGate>{myAccount}</DemoModeGate>
  224. {orgSettings}
  225. {documentation}
  226. {support}
  227. <DemoModeGate>{apiKeys} </DemoModeGate>
  228. </GridLayout>
  229. </SettingsLayout>
  230. </SentryDocumentTitle>
  231. );
  232. }
  233. export default withLatestContext(SettingsIndex);
  234. const GridLayout = styled('div')`
  235. display: grid;
  236. grid-template-columns: 1fr 1fr 1fr;
  237. gap: ${space(2)};
  238. `;
  239. const GridPanel = styled(Panel)`
  240. margin-bottom: 0;
  241. `;
  242. const HomePanelHeader = styled(PanelHeader)`
  243. background: ${p => p.theme.background};
  244. font-size: ${p => p.theme.fontSizeExtraLarge};
  245. align-items: center;
  246. text-transform: unset;
  247. padding: ${space(4)};
  248. `;
  249. const HomePanelBody = styled(PanelBody)`
  250. padding: 30px;
  251. h3 {
  252. font-size: 14px;
  253. }
  254. ul {
  255. margin: 0;
  256. li {
  257. line-height: 1.6;
  258. /* Bullet color */
  259. color: ${p => p.theme.gray200};
  260. }
  261. }
  262. `;
  263. const HomeIconContainer = styled('div')<{color?: string}>`
  264. background: ${p => p.theme[p.color || 'gray300']};
  265. color: ${p => p.theme.white};
  266. width: ${HOME_ICON_SIZE}px;
  267. height: ${HOME_ICON_SIZE}px;
  268. border-radius: ${HOME_ICON_SIZE}px;
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. `;
  273. const linkCss = ({theme}: {theme: Theme}) => css`
  274. color: ${theme.purple300};
  275. &:hover {
  276. color: ${theme.purple300};
  277. }
  278. `;
  279. const linkIconCss = css`
  280. overflow: hidden;
  281. width: 100%;
  282. display: grid;
  283. grid-template-rows: max-content max-content;
  284. gap: ${space(1.5)};
  285. align-items: center;
  286. justify-items: center;
  287. justify-content: center;
  288. `;
  289. const HomeLink = styled(Link)`
  290. ${linkCss}
  291. `;
  292. const ExternalHomeLink = styled(ExternalLink)`
  293. ${linkCss}
  294. `;
  295. const HomeLinkIcon = styled(HomeLink)`
  296. ${linkIconCss}
  297. `;
  298. const ExternalHomeLinkIcon = styled(ExternalLink)`
  299. ${linkIconCss}
  300. `;
  301. interface SupportLinkProps extends Omit<LinkProps, 'ref' | 'to'> {
  302. isSelfHosted: boolean;
  303. organizationSettingsUrl: string;
  304. icon?: boolean;
  305. }
  306. function SupportLink({
  307. isSelfHosted,
  308. icon,
  309. organizationSettingsUrl,
  310. ...props
  311. }: SupportLinkProps) {
  312. if (isSelfHosted) {
  313. const SelfHostedLink = icon ? ExternalHomeLinkIcon : ExternalHomeLink;
  314. return <SelfHostedLink href={LINKS.FORUM} {...props} />;
  315. }
  316. const SelfHostedLink = icon ? HomeLinkIcon : HomeLink;
  317. return <SelfHostedLink to={`${organizationSettingsUrl}support`} {...props} />;
  318. }
  319. const OrganizationName = styled('div')`
  320. line-height: 1.1em;
  321. ${p => p.theme.overflowEllipsis};
  322. `;