guides.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 {trackAnalyticsEvent} from 'sentry/utils/analytics';
  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. const data = {
  52. eventKey: 'assistant.guide_finished',
  53. eventName: 'Assistant Guide Finished',
  54. guide,
  55. organization_id: orgId,
  56. user_id: parseInt(user.id, 10),
  57. };
  58. trackAnalyticsEvent(data);
  59. }
  60. export function recordDismiss(guide: string, step: number, orgId: string | null) {
  61. api.request('/assistant/', {
  62. method: 'PUT',
  63. data: {
  64. guide,
  65. status: 'dismissed',
  66. },
  67. });
  68. const user = ConfigStore.get('user');
  69. if (!user) {
  70. return;
  71. }
  72. const data = {
  73. eventKey: 'assistant.guide_dismissed',
  74. eventName: 'Assistant Guide Dismissed',
  75. guide,
  76. step,
  77. organization_id: orgId,
  78. user_id: parseInt(user.id, 10),
  79. };
  80. trackAnalyticsEvent(data);
  81. }