ShareButton.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div @click.stop>
  3. <button class="tab" :class="menuVisible ? 'tab-active' : ''" @click="toggleMenu">
  4. Share
  5. <Icon name="share" class="ml-2" />
  6. </button>
  7. <div
  8. class="dropdown z-10 right-0 top-full p-4 overflow-visible"
  9. :class="{ hidden: !menuVisible }"
  10. @click.stop
  11. style="min-width: 18rem; margin-right: -1px"
  12. >
  13. <div class="flex items-center mb-4">
  14. <svg class="w-4 h-5 mr-2" viewBox="0 0 682 1024">
  15. <polygon
  16. style="fill:#51DB9E"
  17. points="235.3,510.5 21.5,387 21.5,140.2 236.5,264.1 "
  18. />
  19. <polygon
  20. style="fill:#7900F5"
  21. points="235.3,1004.8 21.5,881.4 21.5,634.5 234.8,757.9 "
  22. />
  23. <polygon
  24. style="fill:#94F2C8"
  25. points="448.9,386.9 21.5,140.2 235.3,16.7 663.2,263.4 "
  26. />
  27. <polygon
  28. style="fill:#A475F4"
  29. points="234.8,757.9 21.5,634.5 235.3,511 449.1,634.5 "
  30. />
  31. </svg>
  32. <h5 class="text-left font-semibold uppercase tracking-wider whitespace-no-wrap">
  33. {{ sharedErrorUrls ? 'Shared' : 'Share' }} on Flare
  34. </h5>
  35. <a
  36. class="ml-auto underline"
  37. target="_blank"
  38. href="https://flareapp.io/docs/ignition-for-laravel/sharing-errors"
  39. title="Flare documentation"
  40. >Docs
  41. </a>
  42. </div>
  43. <div v-if="sharedErrorUrls">
  44. <ShareLinks
  45. :publicUrl="sharedErrorUrls.public_url"
  46. :ownerUrl="sharedErrorUrls.owner_url"
  47. />
  48. </div>
  49. <ShareForm
  50. v-else
  51. :error="shareHadError"
  52. :is-loading="isShareLoading"
  53. @share="shareError"
  54. />
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import ShareForm from './ShareForm';
  60. import ShareLinks from './ShareLinks';
  61. export default {
  62. components: { ShareLinks, ShareForm },
  63. inject: ['report', 'shareEndpoint'],
  64. data() {
  65. return {
  66. shareHadError: false,
  67. sharedErrorUrls: null,
  68. menuVisible: false,
  69. isShareLoading: false,
  70. };
  71. },
  72. watch: {
  73. menuVisible(menuVisible) {
  74. if (menuVisible) {
  75. window.addEventListener('click', this.toggleMenu);
  76. } else {
  77. window.removeEventListener('click', this.toggleMenu);
  78. }
  79. },
  80. },
  81. methods: {
  82. toggleMenu() {
  83. this.menuVisible = !this.menuVisible;
  84. },
  85. async shareError(selectedTabs) {
  86. this.isShareLoading = true;
  87. try {
  88. const response = await fetch(this.shareEndpoint, {
  89. method: 'POST',
  90. headers: {
  91. 'Content-Type': 'application/json',
  92. Accept: 'application/json',
  93. },
  94. body: JSON.stringify({
  95. report: JSON.stringify(this.report),
  96. tabs: selectedTabs,
  97. lineSelection: window.location.hash,
  98. }),
  99. });
  100. const responseData = await response.json();
  101. if (response.ok) {
  102. this.sharedErrorUrls = responseData;
  103. } else {
  104. this.shareHadError = true;
  105. }
  106. } catch (error) {
  107. this.shareHadError = true;
  108. }
  109. this.isShareLoading = false;
  110. },
  111. },
  112. };
  113. </script>