_id.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="flex flex-col items-center justify-between">
  3. <div
  4. v-if="invalidLink"
  5. class="flex flex-col items-center justify-center flex-1"
  6. >
  7. <i class="material-icons pb-2 opacity-75">error_outline</i>
  8. <h1 class="heading text-center">
  9. {{ $t("error.invalid_link") }}
  10. </h1>
  11. <p class="mt-2 text-center">
  12. {{ $t("error.invalid_link_description") }}
  13. </p>
  14. </div>
  15. <div v-else class="flex flex-col items-center justify-center flex-1 p-4">
  16. <div
  17. v-if="shortcodeDetails.loading"
  18. class="flex flex-col items-center justify-center flex-1 p-4"
  19. >
  20. <SmartSpinner />
  21. </div>
  22. <div v-else>
  23. <div
  24. v-if="!shortcodeDetails.loading && E.isLeft(shortcodeDetails.data)"
  25. class="flex flex-col items-center p-4"
  26. >
  27. <i class="material-icons pb-2 opacity-75">error_outline</i>
  28. <h1 class="heading text-center">
  29. {{ $t("error.invalid_link") }}
  30. </h1>
  31. <p class="mt-2 text-center">
  32. {{ $t("error.invalid_link_description") }}
  33. </p>
  34. <p class="mt-4">
  35. <ButtonSecondary to="/" svg="home" filled :label="$t('app.home')" />
  36. <ButtonSecondary
  37. svg="refresh-cw"
  38. :label="$t('app.reload')"
  39. filled
  40. @click.native="reloadApplication"
  41. />
  42. </p>
  43. </div>
  44. <div
  45. v-if="!shortcodeDetails.loading && E.isRight(shortcodeDetails.data)"
  46. class="flex flex-col items-center justify-center flex-1 p-4"
  47. >
  48. <h1 class="heading">
  49. {{ $t("state.loading") }}
  50. </h1>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script lang="ts">
  57. import {
  58. defineComponent,
  59. useContext,
  60. useRoute,
  61. useRouter,
  62. watch,
  63. } from "@nuxtjs/composition-api"
  64. import * as E from "fp-ts/Either"
  65. import { useGQLQuery } from "~/helpers/backend/GQLClient"
  66. import {
  67. ResolveShortcodeDocument,
  68. ResolveShortcodeQuery,
  69. ResolveShortcodeQueryVariables,
  70. } from "~/helpers/backend/graphql"
  71. import { makeRESTRequest } from "~/helpers/types/HoppRESTRequest"
  72. import { setRESTRequest } from "~/newstore/RESTSession"
  73. export default defineComponent({
  74. setup() {
  75. const route = useRoute()
  76. const router = useRouter()
  77. const { localePath } = useContext() as any
  78. const shortcodeDetails = useGQLQuery<
  79. ResolveShortcodeQuery,
  80. ResolveShortcodeQueryVariables,
  81. ""
  82. >({
  83. query: ResolveShortcodeDocument,
  84. variables: {
  85. code: route.value.params.id as string,
  86. },
  87. })
  88. watch(
  89. () => shortcodeDetails.data,
  90. () => {
  91. if (shortcodeDetails.loading) return
  92. const data = shortcodeDetails.data
  93. if (E.isRight(data)) {
  94. const request = JSON.parse(data.right.shortcode?.request as string)
  95. setRESTRequest(makeRESTRequest(request))
  96. router.push({ path: localePath("/") })
  97. }
  98. }
  99. )
  100. const reloadApplication = () => {
  101. window.location.reload()
  102. }
  103. return {
  104. E,
  105. shortcodeDetails,
  106. reloadApplication,
  107. }
  108. },
  109. data() {
  110. return {
  111. invalidLink: false,
  112. shortcodeID: "",
  113. }
  114. },
  115. mounted() {
  116. if (typeof this.$route.params.id === "string") {
  117. this.shortcodeID = this.$route.params.id
  118. }
  119. this.invalidLink = !this.shortcodeID
  120. },
  121. })
  122. </script>