useClusterAnalytics.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import api from "shared/api";
  2. export const useClusterAnalytics = (): {
  3. reportToAnalytics: ({
  4. step,
  5. projectId,
  6. awsAccountId,
  7. cloudFormationUrl,
  8. errorMessage,
  9. loginUrl,
  10. externalId,
  11. provider,
  12. cloudProviderCredentialIdentifier,
  13. region,
  14. clusterName,
  15. }: {
  16. step: string;
  17. projectId: number;
  18. awsAccountId?: string;
  19. cloudFormationUrl?: string;
  20. errorMessage?: string;
  21. loginUrl?: string;
  22. externalId?: string;
  23. provider?: string;
  24. cloudProviderCredentialIdentifier?: string;
  25. region?: string;
  26. clusterName?: string;
  27. }) => Promise<void>;
  28. } => {
  29. const reportToAnalytics = async ({
  30. step,
  31. projectId,
  32. awsAccountId = "",
  33. cloudFormationUrl = "",
  34. errorMessage = "",
  35. loginUrl = "",
  36. externalId = "",
  37. region = "",
  38. provider = "",
  39. cloudProviderCredentialIdentifier = "",
  40. clusterName = "",
  41. }: {
  42. step: string;
  43. projectId: number;
  44. awsAccountId?: string;
  45. cloudFormationUrl?: string;
  46. errorMessage?: string;
  47. loginUrl?: string;
  48. externalId?: string;
  49. region?: string;
  50. provider?: string;
  51. cloudProviderCredentialIdentifier?: string;
  52. clusterName?: string;
  53. }): Promise<void> => {
  54. await api
  55. .updateOnboardingStep(
  56. "<token>",
  57. {
  58. step,
  59. account_id: awsAccountId,
  60. cloudformation_url: cloudFormationUrl,
  61. error_message: errorMessage,
  62. login_url: loginUrl,
  63. external_id: externalId,
  64. region,
  65. provider,
  66. cloud_provider_credential_identifier:
  67. cloudProviderCredentialIdentifier,
  68. cluster_name: clusterName,
  69. },
  70. {
  71. project_id: projectId,
  72. }
  73. )
  74. .catch(() => ({})); // do not care about error here
  75. };
  76. return {
  77. reportToAnalytics,
  78. };
  79. };