onboarding.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {RouteContextInterface} from 'react-router';
  2. import {Organization, Project} from 'sentry/types';
  3. import {OnboardingState} from 'sentry/views/onboarding/types';
  4. import type {AvatarUser} from './user';
  5. export enum OnboardingTaskKey {
  6. FIRST_PROJECT = 'create_project',
  7. FIRST_EVENT = 'send_first_event',
  8. INVITE_MEMBER = 'invite_member',
  9. SECOND_PLATFORM = 'setup_second_platform',
  10. USER_CONTEXT = 'setup_user_context',
  11. RELEASE_TRACKING = 'setup_release_tracking',
  12. SOURCEMAPS = 'setup_sourcemaps',
  13. USER_REPORTS = 'setup_user_reports',
  14. ISSUE_TRACKER = 'setup_issue_tracker',
  15. ALERT_RULE = 'setup_alert_rules',
  16. FIRST_TRANSACTION = 'setup_transactions',
  17. METRIC_ALERT = 'setup_metric_alert_rules',
  18. USER_SELECTED_PROJECTS = 'setup_userselected_projects',
  19. /// Customized card that shows the selected integrations during onboarding
  20. INTEGRATIONS = 'integrations',
  21. /// Regular card that tells the user to setup integrations if no integrations were selected during onboarding
  22. FIRST_INTEGRATION = 'setup_integrations',
  23. }
  24. export type OnboardingSupplementComponentProps = {
  25. onCompleteTask: () => void;
  26. task: OnboardingTask;
  27. };
  28. export type OnboardingCustomComponentProps = {
  29. onboardingState: OnboardingState | null;
  30. organization: Organization;
  31. projects: Project[];
  32. setOnboardingState: (state: OnboardingState | null) => void;
  33. task: OnboardingTask;
  34. };
  35. interface OnboardingTaskDescriptorBase {
  36. description: string;
  37. /**
  38. * Should the onboarding task currently be displayed
  39. */
  40. display: boolean;
  41. /**
  42. * A list of require task keys that must have been completed before these
  43. * tasks may be completed.
  44. */
  45. requisites: OnboardingTaskKey[];
  46. /**
  47. * Can this task be skipped?
  48. */
  49. skippable: boolean;
  50. task: OnboardingTaskKey;
  51. title: string;
  52. /**
  53. * An extra component that may be rendered within the onboarding task item.
  54. */
  55. SupplementComponent?: React.ComponentType<OnboardingSupplementComponentProps>;
  56. /**
  57. * If a render function was provided, it will be used to render the entire card,
  58. * and the card will be rendered before any other cards regardless of completion status.
  59. * the render function is therefore responsible for determining the completion status
  60. * of the card by returning null when it's completed.
  61. *
  62. * Note that this should not be given a react component.
  63. */
  64. renderCard?: (props: OnboardingCustomComponentProps) => JSX.Element | null;
  65. /**
  66. * Joins with this task id for server-side onboarding state.
  67. * This allows you to create alias for exising onboarding tasks or create multiple
  68. * tasks for the same server-side task.
  69. */
  70. serverTask?: string;
  71. }
  72. interface OnboardingTypeDescriptorWithAction extends OnboardingTaskDescriptorBase {
  73. action: (props: RouteContextInterface) => void;
  74. actionType: 'action';
  75. }
  76. interface OnboardingTypeDescriptorWithExternal extends OnboardingTaskDescriptorBase {
  77. actionType: 'app' | 'external';
  78. location: string;
  79. }
  80. export type OnboardingTaskDescriptor =
  81. | OnboardingTypeDescriptorWithAction
  82. | OnboardingTypeDescriptorWithExternal;
  83. export interface OnboardingTaskStatus {
  84. status: 'skipped' | 'pending' | 'complete';
  85. task: OnboardingTaskKey;
  86. completionSeen?: string | boolean;
  87. data?: {[key: string]: string};
  88. dateCompleted?: string;
  89. user?: AvatarUser | null;
  90. }
  91. interface OnboardingTaskWithAction
  92. extends OnboardingTaskStatus,
  93. OnboardingTypeDescriptorWithAction {
  94. /**
  95. * Onboarding tasks that are currently incomplete and must be completed
  96. * before this task should be completed.
  97. */
  98. requisiteTasks: OnboardingTaskDescriptor[];
  99. }
  100. interface OnboardingTaskWithExternal
  101. extends OnboardingTaskStatus,
  102. OnboardingTypeDescriptorWithExternal {
  103. /**
  104. * Onboarding tasks that are currently incomplete and must be completed
  105. * before this task should be completed.
  106. */
  107. requisiteTasks: OnboardingTaskDescriptor[];
  108. }
  109. export type OnboardingTask = OnboardingTaskWithAction | OnboardingTaskWithExternal;