guides.tsx 2.1 KB

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