guides.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  6. const api = new Client();
  7. export async function fetchGuides() {
  8. try {
  9. const data = await api.requestPromise('/assistant/');
  10. GuideStore.fetchSucceeded(data);
  11. } catch (err) {
  12. if (err.status !== 401 && err.status !== 403) {
  13. Sentry.captureException(err);
  14. }
  15. }
  16. }
  17. export function registerAnchor(target: string) {
  18. GuideStore.registerAnchor(target);
  19. }
  20. export function unregisterAnchor(target: string) {
  21. GuideStore.unregisterAnchor(target);
  22. }
  23. export function nextStep() {
  24. GuideStore.nextStep();
  25. }
  26. export function setForceHide(forceHide: boolean) {
  27. GuideStore.setForceHide(forceHide);
  28. }
  29. export function toStep(step: number) {
  30. GuideStore.toStep(step);
  31. }
  32. export function closeGuide(dismissed?: boolean) {
  33. GuideStore.closeGuide(dismissed);
  34. }
  35. export function dismissGuide(guide: string, step: number, orgId: string | null) {
  36. recordDismiss(guide, step, orgId);
  37. closeGuide(true);
  38. }
  39. export function recordFinish(guide: string, orgId: string | null) {
  40. api.request('/assistant/', {
  41. method: 'PUT',
  42. data: {
  43. guide,
  44. status: 'viewed',
  45. },
  46. });
  47. const user = ConfigStore.get('user');
  48. if (!user) {
  49. return;
  50. }
  51. trackAdvancedAnalyticsEvent('assistant.guide_finished', {
  52. organization: orgId,
  53. guide,
  54. });
  55. }
  56. export function recordDismiss(guide: string, step: number, orgId: string | null) {
  57. api.request('/assistant/', {
  58. method: 'PUT',
  59. data: {
  60. guide,
  61. status: 'dismissed',
  62. },
  63. });
  64. const user = ConfigStore.get('user');
  65. if (!user) {
  66. return;
  67. }
  68. trackAdvancedAnalyticsEvent('assistant.guide_dismissed', {
  69. organization: orgId,
  70. guide,
  71. step,
  72. });
  73. }