guides.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import * as Sentry from '@sentry/react';
  2. import {Client} from 'sentry/api';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import GuideStore from 'sentry/stores/guideStore';
  5. import {Organization} from 'sentry/types';
  6. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  7. import {getTourTask, isDemoWalkthrough} from 'sentry/utils/demoMode';
  8. import {demoEndModal} from './modal';
  9. import {updateOnboardingTask} from './onboardingTasks';
  10. const api = new Client();
  11. export async function fetchGuides() {
  12. try {
  13. const data = await api.requestPromise('/assistant/');
  14. GuideStore.fetchSucceeded(data);
  15. } catch (err) {
  16. if (err.status !== 401 && err.status !== 403) {
  17. Sentry.captureException(err);
  18. }
  19. }
  20. }
  21. export function registerAnchor(target: string) {
  22. GuideStore.registerAnchor(target);
  23. }
  24. export function unregisterAnchor(target: string) {
  25. GuideStore.unregisterAnchor(target);
  26. }
  27. export function nextStep() {
  28. GuideStore.nextStep();
  29. }
  30. export function setForceHide(forceHide: boolean) {
  31. GuideStore.setForceHide(forceHide);
  32. }
  33. export function toStep(step: number) {
  34. GuideStore.toStep(step);
  35. }
  36. export function closeGuide(dismissed?: boolean) {
  37. GuideStore.closeGuide(dismissed);
  38. }
  39. export function dismissGuide(guide: string, step: number, orgId: string | null) {
  40. recordDismiss(guide, step, orgId);
  41. closeGuide(true);
  42. }
  43. export function recordFinish(
  44. guide: string,
  45. orgId: string | null,
  46. orgSlug: string | null,
  47. org: Organization | null
  48. ) {
  49. api.request('/assistant/', {
  50. method: 'PUT',
  51. data: {
  52. guide,
  53. status: 'viewed',
  54. },
  55. });
  56. const tourTask = getTourTask(guide);
  57. if (isDemoWalkthrough() && tourTask && org) {
  58. const {tour, task} = tourTask;
  59. updateOnboardingTask(api, org, {task, status: 'complete', completionSeen: true});
  60. demoEndModal({tour, orgSlug});
  61. }
  62. const user = ConfigStore.get('user');
  63. if (!user) {
  64. return;
  65. }
  66. trackAdvancedAnalyticsEvent('assistant.guide_finished', {
  67. organization: orgId,
  68. guide,
  69. });
  70. }
  71. export function recordDismiss(guide: string, step: number, orgId: string | null) {
  72. api.request('/assistant/', {
  73. method: 'PUT',
  74. data: {
  75. guide,
  76. status: 'dismissed',
  77. },
  78. });
  79. const user = ConfigStore.get('user');
  80. if (!user) {
  81. return;
  82. }
  83. trackAdvancedAnalyticsEvent('assistant.guide_dismissed', {
  84. organization: orgId,
  85. guide,
  86. step,
  87. });
  88. }