onboardingTasks.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import OrganizationActions from 'sentry/actions/organizationActions';
  2. import {Client} from 'sentry/api';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import {OnboardingTask, Organization} from 'sentry/types';
  5. /**
  6. * Update an onboarding task.
  7. *
  8. * If no API client is provided the task will not be updated on the server side
  9. * and will only update in the organization store.
  10. */
  11. export function updateOnboardingTask(
  12. api: Client | null,
  13. organization: Organization,
  14. updatedTask: Partial<Pick<OnboardingTask, 'status' | 'data'>> & {
  15. task: OnboardingTask['task'];
  16. /**
  17. * Marks completion seen. This differs from the OnboardingTask
  18. * completionSeen type as that returns the date completion was seen.
  19. */
  20. completionSeen?: boolean;
  21. }
  22. ) {
  23. if (api !== null) {
  24. api.requestPromise(`/organizations/${organization.slug}/onboarding-tasks/`, {
  25. method: 'POST',
  26. data: updatedTask,
  27. });
  28. }
  29. const hasExistingTask = organization.onboardingTasks.find(
  30. task => task.task === updatedTask.task
  31. );
  32. const user = ConfigStore.get('user');
  33. const onboardingTasks = hasExistingTask
  34. ? organization.onboardingTasks.map(task =>
  35. task.task === updatedTask.task ? {...task, ...updatedTask} : task
  36. )
  37. : [...organization.onboardingTasks, {...updatedTask, user}];
  38. OrganizationActions.update({onboardingTasks});
  39. }