customerOnboardingTasks.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import moment from 'moment-timezone';
  2. import {Tag} from 'sentry/components/core/badge/tag';
  3. import {getOnboardingTasks} from 'sentry/components/onboardingWizard/taskConfig';
  4. import {IconCheckmark, IconClock, IconNot} from 'sentry/icons';
  5. import ResultGrid from 'admin/components/resultGrid';
  6. type Props = Partial<React.ComponentProps<typeof ResultGrid>> & {
  7. orgId: string;
  8. };
  9. type Status = 'complete' | 'pending' | 'skipped';
  10. type StatusTag = {
  11. icon: React.ReactNode;
  12. tagType: React.ComponentProps<typeof Tag>['type'];
  13. };
  14. const tagPriority: Record<Status, StatusTag> = {
  15. pending: {icon: <IconClock size="xs" />, tagType: 'default'},
  16. skipped: {icon: <IconNot size="xs" />, tagType: 'warning'},
  17. complete: {icon: <IconCheckmark size="xs" />, tagType: 'success'},
  18. };
  19. function CustomerOnboardingTasks({orgId, ...props}: Props) {
  20. const allTasks = getOnboardingTasks({organization: {slug: orgId, features: []} as any});
  21. return (
  22. <ResultGrid
  23. path={`/_admin/customers/${orgId}/`}
  24. endpoint={`/internal-stats/${orgId}/onboarding-tasks/`}
  25. method="GET"
  26. defaultParams={{per_page: 10}}
  27. useQueryString={false}
  28. keyForRow={row => row.task}
  29. columns={[
  30. <th key="task">Task</th>,
  31. <th key="status">Status</th>,
  32. <th key="date" style={{width: 250}}>
  33. When
  34. </th>,
  35. ]}
  36. columnsForRow={(row: any) => {
  37. const {completed, task} = row;
  38. const onboardingTask = allTasks.find(t => t.task === task);
  39. if (!onboardingTask?.display) {
  40. return [null];
  41. }
  42. const status = row.status ?? 'pending';
  43. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  44. const {icon, tagType} = tagPriority[status] ?? {};
  45. return [
  46. <td key="task">{onboardingTask.title}</td>,
  47. <td key="status">
  48. <Tag icon={icon} type={tagType}>
  49. {status}
  50. </Tag>
  51. </td>,
  52. <td key="date">{completed && moment(completed).fromNow()}</td>,
  53. ];
  54. }}
  55. {...props}
  56. />
  57. );
  58. }
  59. export default CustomerOnboardingTasks;