guides.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import GuideActions from 'sentry/actions/guideActions';
  2. import {Client} from 'sentry/api';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  5. const api = new Client();
  6. export function fetchGuides() {
  7. api.request('/assistant/?v2', {
  8. method: 'GET',
  9. success: data => {
  10. GuideActions.fetchSucceeded(data);
  11. },
  12. });
  13. }
  14. export function registerAnchor(target: string) {
  15. GuideActions.registerAnchor(target);
  16. }
  17. export function unregisterAnchor(target: string) {
  18. GuideActions.unregisterAnchor(target);
  19. }
  20. export function nextStep() {
  21. GuideActions.nextStep();
  22. }
  23. export function toStep(step: number) {
  24. GuideActions.toStep(step);
  25. }
  26. export function closeGuide(dismissed?: boolean) {
  27. GuideActions.closeGuide(dismissed);
  28. }
  29. export function dismissGuide(guide: string, step: number, orgId: string | null) {
  30. recordDismiss(guide, step, orgId);
  31. closeGuide(true);
  32. }
  33. export function recordFinish(guide: string, orgId: string | null) {
  34. api.request('/assistant/', {
  35. method: 'PUT',
  36. data: {
  37. guide,
  38. status: 'viewed',
  39. },
  40. });
  41. const user = ConfigStore.get('user');
  42. if (!user) {
  43. return;
  44. }
  45. const data = {
  46. eventKey: 'assistant.guide_finished',
  47. eventName: 'Assistant Guide Finished',
  48. guide,
  49. organization_id: orgId,
  50. user_id: parseInt(user.id, 10),
  51. };
  52. trackAnalyticsEvent(data);
  53. }
  54. export function recordDismiss(guide: string, step: number, orgId: string | null) {
  55. api.request('/assistant/', {
  56. method: 'PUT',
  57. data: {
  58. guide,
  59. status: 'dismissed',
  60. },
  61. });
  62. const user = ConfigStore.get('user');
  63. if (!user) {
  64. return;
  65. }
  66. const data = {
  67. eventKey: 'assistant.guide_dismissed',
  68. eventName: 'Assistant Guide Dismissed',
  69. guide,
  70. step,
  71. organization_id: orgId,
  72. user_id: parseInt(user.id, 10),
  73. };
  74. trackAnalyticsEvent(data);
  75. }