guides.tsx 2.5 KB

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