onboardingHovercard.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import {updateOnboardingTask} from 'app/actionCreators/onboardingTasks';
  5. import {Client} from 'app/api';
  6. import Button from 'app/components/button';
  7. import Hovercard from 'app/components/hovercard';
  8. import {t} from 'app/locale';
  9. import space from 'app/styles/space';
  10. import {OnboardingTaskKey, Organization} from 'app/types';
  11. import withApi from 'app/utils/withApi';
  12. type Props = {
  13. api: Client;
  14. organization: Organization;
  15. location: Location;
  16. children: React.ReactNode;
  17. };
  18. type State = {
  19. dismissed: boolean;
  20. };
  21. class OnboardingHovercard extends React.Component<Props, State> {
  22. state: State = {
  23. dismissed: false,
  24. };
  25. get shouldShowHovercard() {
  26. const {organization} = this.props;
  27. const {dismissed} = this.state;
  28. const hasCompletedTask = organization.onboardingTasks.find(
  29. task => task.task === OnboardingTaskKey.ALERT_RULE && task.status === 'complete'
  30. );
  31. const query = this.props.location?.query || {};
  32. return (
  33. !hasCompletedTask &&
  34. !dismissed &&
  35. Object.prototype.hasOwnProperty.call(query, 'onboardingTask')
  36. );
  37. }
  38. skipTask = () => {
  39. const {api, organization} = this.props;
  40. updateOnboardingTask(api, organization, {
  41. task: OnboardingTaskKey.ALERT_RULE,
  42. status: 'complete',
  43. data: {accepted_defaults: true},
  44. });
  45. this.setState({dismissed: true});
  46. };
  47. render() {
  48. const {children, organization: _org, location: _location, ...props} = this.props;
  49. if (!this.shouldShowHovercard) {
  50. return children;
  51. }
  52. const hovercardBody = (
  53. <HovercardBody>
  54. <h1>{t('Configure custom alerting')}</h1>
  55. <p>
  56. {t(
  57. `Add custom alert rules to configure under what conditions
  58. you receive notifications from Sentry.`
  59. )}
  60. </p>
  61. <Button size="xsmall" onClick={this.skipTask}>
  62. {t('The default rule looks good!')}
  63. </Button>
  64. </HovercardBody>
  65. );
  66. return (
  67. <Hovercard show position="left" body={hovercardBody} {...props}>
  68. {children}
  69. </Hovercard>
  70. );
  71. }
  72. }
  73. const HovercardBody = styled('div')`
  74. h1 {
  75. font-size: ${p => p.theme.fontSizeLarge};
  76. margin-bottom: ${space(1.5)};
  77. }
  78. p {
  79. font-size: ${p => p.theme.fontSizeMedium};
  80. }
  81. `;
  82. export default withApi(OnboardingHovercard);